[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Re: Using Smalltalk as a scripting language

From: Roland Plüss
Subject: Re: [Help-smalltalk] Re: Using Smalltalk as a scripting language
Date: Sat, 31 Oct 2009 00:18:55 +0100
User-agent: Thunderbird (X11/20090926)

>> Got stumped :( . I forgot that the class I try to wrap right now is a
>> singleton. With other words in that case I need to assign a c-pointer
>> somehow to the class itself not the instance of it. But the class object
>> is created by smalltalk so I can't mess with it.
> No.  Even if it is a singleton, *never* place singleton methods on the
> class side.  Add a #uniqueInstance class method cCall and use
> gst_register_oop to ensure that the singleton instance is not garbage
> collected.
>> So basically I need to mess with the STSomething object. Can I do the
>> same hack you mentioned simply for STSomething like this?
>> Object subclass: STSomething [
>>      STSomething class [
>>          <shape: #byte>
>>          new [<cCall: 'CSomething_new' returning: #void args:
>> #(#self)>  ]
>>      ]
>> ]
> I answered above, but probably you want "returning: #smalltalk args:
> #(#selfSmalltalk)" in general.
Okay, this looks a bit more tricky then. I tried now the following but
without any luck so far.

Object subclass: DEEngine [
    DEEngine class [
        | uniqueInstance |
        uniqueInstance [ ^uniqueInstance ]
    quit [ <cCall: 'stClassEngine.ccQuit' returning: #void args: #(#self)> ]

The idea I had is to assign the uniqueInstance instance variable of the
class side from within the c code upon creation time. Doing so the
uniqueInstance would work without having to cCall ( which is a problem
since I would not have an engine pointer at that time ). I did hence the

struct csEngineClass{
    OOP uniqueInstance;

// in the creation function
OOP oopClass = gst_class_name_to_oop( "DEEngine" );
csEngineClass *csdata = ( csEngineClass* )OOP_TO_OBJ( oopClass );
csdata->uniqueInstance = pST->CreateNewObject( oopClass );

With CreateNewObject simply creating a new instance of the class. I can
printf csdata->uniqueInstance and it has a proper OOP. When I do though
"DEEngine uniqueInstance printNl" in my script I get nil. Something I
didn't understand on the way you manipulate ST data from C?

Yours sincerely
Plüss Roland

Leader and Head Programmer
- Game: Epsylon ( , )
- Game Engine: Drag(en)gine ( , )
- Normal Map Generator: DENormGen ( )

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]