[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: keeping reference of a table defined in C
- From: jseb <gmane2010@...>
- Date: Sun, 14 Aug 2011 14:02:04 +0200
I've made a function in a C module, for storing things in a local table.
This local table is returned to Lua script at the end of the C function.
I do like this:
// And then, in my inner loop:
lua_pushstring (L, classname); // key
lua_pushlightuserdata (L, (void*)object); // value
lua_rawset (L, -3); // -3 : position of table on the stack
It works very well.
The table is filled with my C objects, and i can retrieve them for
For example, the table contains records like this:
win userdata: 0x2251bf0
The problem is that: I must keep table at the top of the stack, and
cannot do stack manipulation before storing all my records.
For the moment, it's not a problem, but i think of the future :)
So i've tried and gave a name to my table, just after created it:
I was thinking i could retrive and push later the table, using:
lua_getglobal(L, "classname_table"); //table now at the top of stack
lua_pushstring (L, key );
lua_pushlightuserdata (L, ptr);
lua_rawset (L, -3);
But doesn't store anything.
Another question: since i've added
for naming my local C table, the returned table contains pointers to all
my module functions (only the one which can be called by Lua).
Now, the table contains only function i did't add:
runmainloop function: 0x2251a00
fluidimport function: 0x22519a0
widgetshow function: 0x22519d0
If i simply remove «lua_setglobal», those records disappear.
Thank you for reading all this.