Exposing object instance to Lua

Started by
24 comments, last by AverageJoeSSU 12 years, 9 months ago
Hello all, I'm thinking of using tolua++ to bind some of my internal engine functionality to lua (so that scripts can do things like set up triggers and stuff with ease), but it seems the tolua++ documentation is fairly mediocre. Specifically, what I want to do is expose an object instance of my trigger handler class (TriggerHandler triggers;) so that I could do things like triggers.newtrigger()) from within a lua script. Does tolua++ provide a mechanism to do this? It seems fairly straight forward to expose the TriggerHandler class itself, but the documentation doesn't say anything about object instances. Thanks!
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
Advertisement
Pass them in as lightuserdata, maybe..?
I know SWIG is capable of binding C++ variables (in this case, object instances) with lua objects (If I understand correctly, the lua variable functions as a proxy for the C++ one, allowing normal usage). Not sure if tolua++ can do that sort of thing. I don't want to simply pass in the object by value, but rather expose it to direct manipulation in lua (more accurately, direct interface through its member functions)
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
I've made a journal entry briefly describing SWIG if u feel like reading it.
[size="2"]I like the Walrus best.
@Owl: Your journal post is actually what got me looking into SWIG/toLua++/etc in the first place :). Unfortunately SWIG doesn't seem to work quite the way I'd prefer (I'd rather like something that will generate code which can simply be #included, opened in the lua state, and available without having to compile anything separately or whatever. The documentation for all these things seems a little weird so its possible I'm missing something.
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
Please let me know if you find something simpler/better. SWIG is the easiest way for newbies (like me) I've found.
[size="2"]I like the Walrus best.
It certainly seemed fairly simple... is there a way to use the code it generates without having to separately compile it and link it in?
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
To be able to use the code it generates first you have to generate it with swig (letting it generate the cpp from the interface file) and in order to use the resulting code in your program you have to include the cpp file into your project.

Now if you mean to be able to use the code it generates by your own, I'm pretty sure you can, but you'd have to understand it first.
[size="2"]I like the Walrus best.
If all I have to do is #include the code SWIG generates, that sounds pretty good to me :)
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
It's simpler than that, you don't have to #include the cpp, you just add it to your project like any other of the cpp you write yourself. That will allow you to use anything you declare in the interface file (classes, types, etc) from your Lua scripts. Remember that every time you change c++ code you are exposing to Lua you must re-generate the cpp.
[size="2"]I like the Walrus best.

This topic is closed to new replies.

Advertisement