> -----Original Message-----
> From: firstname.lastname@example.org [mailto:email@example.com] On
> Behalf Of Austin Einter
> Sent: dinsdag 24 juni 2014 11:50
> To: Lua mailing list
> Subject: Re: Simple Function Call From C language
> Hi Thijs SchreijerYou can only acccess a lua state from a single thread. So assuming you stay single threaded, then for each invocation you can simply clear the stack, and do your thing. Nobody will interfere with that.
> Basically I am using lua related functions such as
> 1. luaL_checkinteger(L, -1);
> 2. lua_pushinteger(L,4);
> in my C code.
> Once I call pushInteger api, do I need to call corresponding popInteger (or
> similar) api so that stack in Lua or in C will be in tact. For me there will
> be 1000s of processes and any process can call any Lua specific apis
> randomly. So bit worried if I am messing up a bit with stack.
This is a sandboxing question. Will users enter code, might it be malicious? Then you need tight controls, for example, some of the functions in the debug library you would better remove then.
> One more question is, suppose a C program is running for 1 hour. Frequently
> Lua scripts will be executed from C code.
> Is it a good idea to do luaL_openlibs once at C code init time and lua_close
> at C code exit time.
> Or whenever I want to execute a script, do luaL_openlibs , then execute Lua
> api, and then do lua_close.
> If I have 10 scripts to execute, do 10 times luaL_openlibs and lua_close.
> Which approach will be better.
Your first approach would be my favourite, but let each script run in its own environment that can be cleaned up by the GC after it finishes. Performance wise I think this would be best.