schoenborno - 2013-12-31
  • Description has changed:

Diff:

--- old
+++ new
@@ -1,4 +1,4 @@
-Lua-icxx was designed that way, but missing the link to make it easy to do. Goal is to support `Foo* foo = lua.getGlobal("foo")` and `lua.setGlobal("foo", foo)` where "foo" in Lua is assumed to be of C++ class `Foo` exported to Lua as Lua "class" Foo, and foo in C++ is assumed to be of class `Foo`. 
+Lua-icxx was designed that so that it can be used in conjunction with SWIG, but it does not support getting and putting SWIG-exported instances. Goal is to support `Foo* foo = lua.getGlobal("foo")` and `lua.setGlobal("foo", foo)` where "foo" in Lua is assumed to be of C++ class `Foo` exported to Lua as Lua "class" Foo, and foo in C++ is assumed to be of class `Foo`. 

 For getting an object out of Lua (first case), would get "foo" from the Lua interpreter, then get the object's type name string (this is in the object, as per "26.7.2 Userdata and Metatables"). Then, find the `swig_type_info` using `SWIGTypeQuery` with that name. Finally, call `SWIG_ConvertPtr` to get a `void*` to the `Foo`, and `reinterpret_cast<Foo*>`. See http://lua-users.org/lists/lua-l/2011-04/msg00595.html, as well as "26.5.2 SWIG's Lua-C API" on swig.org, and http://www.swig.org/Doc2.0/SWIGDocumentation.html#Modules_external_run_time.