lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Ok, I see now calling LUA each frame isn't a good idea. But how can I do
the "shell-thing" I asked in my first posting?

> And which is the best way to transfer my C++ object data structure to a
LUA script, change it and then return it? Should I package all values in
a table and later read it back from the table to the object? Or is there
a more "generic" way?


Andreas, here is a partial reply.

1. Search the Wiki for "Simple" and "Binding" for some simple tools/samples
for "transferring" a C++ object into Lua.

2. As for simple single line console commands, just use lua_register to add
the commands as functions.  Check the manual for lua_load (and
lua_loadbuffer IIRC), follow from that the basics for loading/running
scripts.

3. You mentioned "commands with 2 keywords" (and maybe more).  For this you
will need to learn more of the API (mainly the stack operations) so that you
can retrieve parameters to your commands.  Also, things will go easier if
you can change your command syntax to fit Lua function call syntax.  If not
then you would have to play some "interpretation" games in your Chunkreader
function (see lua_load) in order to format things in a way that will go
nicely through Lua.  For instance a line entry such as....

fire rocket northeast

could be "translated" to...

fire{"rocket", "northeast",}


----
On the whole though this really does not get you much if you have to do all
of that parsing/reformatting, and you can't cope with allowing the user to
make their own variables/functions.