Leopold Toetsch wrote:

Klaas-Jan Stol wrote:

mmm, I looked at classes/none.pmc, this is a copy/paste:
===============
#include <assert.h>

static PMC * Py_None;

pmclass None singleton {


Ah, yep - None is a singleton too - sorry for my confusion.

So it should be rather easy to subclass None, implement get/set_pointer and use a distinct file-static PMC* storage for your singleton.

leo

ah great. it works! :-). Apparently, inheriting from a singleton class doesn't make the child class a singleton, you have to add the "singleton" keyword in the class definition header.

one more question though:

1a: when are set_pointer and get_pointer actually called?
1b: in set_pointer (I copied it from None.pmc) an assertion is done. Why is this? (this is also part of question 1a: set_pointer is called once, apparently?)

void set_pointer(void* ptr) {
     assert(!Lua_Nil);
   Lua_Nil = (PMC*) ptr;
}

Anyway:

   P0 = new "LuaNil"
   print P0

prints "nil". Great! :-)

thanks.
klaas-jan

Reply via email to