|
I earlier asked about calling a Lua function from C/C++. I appreciate the feedback. However, 1) I was already familiar with the INCOMPLETE example associated with the below link: http://www.lua.org/manual/5.1/manual.html#lua_call 2) I was also aware that luaL_loadstring() does not execute the Lua chunk. 3) As for the example in Patrick Rapin's documentation, it is NOT an example of calling a Lua function. It's an example of calling a varargs _expression_ (for which the Lua text was helpful). I realized what must be wrong with my program. I discovered that my program works fine with a Lua script consisting of a varargs _expression_. However, it does not work if the script consists of a Lua function. I realized that a Lua function is different. A Lua script might contain several functions. Surely, the individual functions must be "registered" so that they may later be pushed onto the stack via calls to lua_getfield(). When I call lua_setfield() after loading a chunk consisting of a varargs _expression_, a table entry is made associated with the chunk (i.e., the chunk is "registered"). But, if I load a chunk containing one or more Lua functions, how do I cause the individual functions to be "registered"? I've found no examples of this. Thanks! If you have any trouble sounding condescending, find a Unix user to show you how it's done. -- Scott Adams Dilbert newsletter 3.0, 1994 |