Exposing object instance to Lua
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!
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)
@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.
Please let me know if you find something simpler/better. SWIG is the easiest way for newbies (like me) I've found.
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?
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement