[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: SWIG/Lua/C++ object instance
- From: Joey Mukherjee <joey@...>
- Date: Thu, 3 May 2007 14:24:36 -0500
I create an instance of my class variable in C++ and want to use Lua
to use some of the routines in my C++ class so I used SWIG to
generate the bindings for Lua and I think I have that right.
However, I can not figure out how to make Lua use my C++ variable
instance instead of creating a new one. I was looking at the Wiki
and I am very close to the CppObjectBinding method, except I am using
SWIG.
I have a :
lua_pushlightuserdata (global_Lua_state, this);
lua_setglobal (global_Lua_state, "this");
to put the "this" pointer on the stack. I want to interface that
with Lua:
print ("In the Lua script")
b = plot.Plot(this) -- wrong! How do I make b = this, but be of a
plot.Plot () type.
print (this)
print (b)
print (b:DumpV (0))
print (this:DumpV(0))
Two addresses are printed out, but they are different (which I
expect). I want to do this:DumpV (0), but I get a:
In the Lua script
userdata: bc4dd8
userdata: b53330
dump.lua:7: attempt to index global 'this' (a userdata value)
I feel I am missing something simple, but I just can't get the next
step. I feel like if I go to the direct way of binding like in the
wiki CppObjectBinding, I can get this to work, but then I have to do
all the bindings myself so I would like to stick with SWIG.
Thanks for any ideas!
Joey