Exposing class in Lua without exposing classes?
Pondering...
I want to expose some class objects to LUA without exposing the constructor/destructors and most likely some internal support fuctions.
Something along the lines of exposing say an APP object to initialize the screen and whatnot, but I don''t want LUA to be able to create the APP object itself. That is for the engine.
Is it possible to do this function by function in a LUA table? I have done whole classes before, and made nice wrappers for an embedded interpreter in an engine, but I started thinking that the script language should only have access to certain things down the line.
Previously I would just chuck the whole class exposed to LUA and just be smart in scripting. Seeing as it was me doing the scripting, this was a no brainer. But now what happens when I pull over people to write scripts. Some jamoke may actually try to init another APP or another Texturemanager class just cause they think they know what is going on.
Any one have expereience with this? Docs are pretty tight on LUA and class exposure.
Thanks in advance.
"Five passengers set sail that day, for a three hour tour, a three hour tour...."
(I am assuming you are using ToLUA)
There are several ways to do this, but I guess the best method would be to expose a function getApp() to LUA, which returns the only instance of the app. Then to prevent people from creating their own app classes, just remove the C++ code ToLUA generates for '':new()''.
So then in your LUA code you can do:
theApp = getApp();
theApp.doThingsToYourApp();
or
getApp().doThingsToYourApp();
Hope this helps.
There are several ways to do this, but I guess the best method would be to expose a function getApp() to LUA, which returns the only instance of the app. Then to prevent people from creating their own app classes, just remove the C++ code ToLUA generates for '':new()''.
So then in your LUA code you can do:
theApp = getApp();
theApp.doThingsToYourApp();
or
getApp().doThingsToYourApp();
Hope this helps.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement