Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracking Lua tables in C

Tags:

c++

c

lua

swig

I have C++ objects and I have Lua objects/tables. (Also have SWIG C++ bindings.)

What I need to be able to do is associate the two objects so that if I do say

CObject* o1 = getObject();
o1->Update();

it will do the equivalent Lua:

myluatable1.Update();

So far I can imagine that CObject::Update would have the following code:

void CObject::Update(){
    // Acquire table.

    // ???

    // Do the following operations on the table.
    lua_getfield(L, -1, "Update");
    lua_pcall(L, 0, 0, 0);
}

How would I store/set the Lua table to be used, and what would go in the // ??? above to make the Update call work?

like image 232
Tom J Nowell Avatar asked Dec 02 '22 06:12

Tom J Nowell


1 Answers

I cant believe nobody noticed this!

http://www.lua.org/pil/27.3.2.html

A section of the Lua API for storing references to lua objects and tables and returning references for the purposes of being stored in C structures!!

like image 195
Tom J Nowell Avatar answered Dec 14 '22 23:12

Tom J Nowell