lua-users home
lua-l archive

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


On 23 June 2014 22:54, Austin Einter <austin.einter@gmail.com> wrote:
 
Dear All
I am quite new to Lua environment.

We have very simple requirement. Before we start using Lua , we need to check if it is the right script language for our requirement.

I have a bunch of code as below

int count = 5
count = count * 2
return count

The above syntax is what I have thought of, I can change syntax if required

My whole project is in C. Now I need to evaluate above block and get the value.

Can we use Lua to determine the value of above block and return the value to C code.

I do not want to have script.lua and execute (same I can do with shell etc) by dofile load.

I have above string, I want to feed this string to Lua (or equivalent of above string that Lua understands) and can Lua evaluate count value and return to C code.

Can somebody guide me if Lua is right choice.
 
Also , at any point of time in same machine I might have 1000s of programs running and each program might be loading Lua Libs etc, will there be any performance constraints..

Thanks
Austin

The simplest way to execute a string as a chunk of Lua code from C is probably luaL_dostring:
http://www.lua.org/manual/5.2/manual.html#luaL_dostring

If you need more control, you can load the chunk with luaL_loadstring, luaL_loadbuffer, lua_load, etc. before you execute it.

Any values returned from the chunk are left on the stack, as described in lua_call:
http://www.lua.org/manual/5.2/manual.html#lua_call

As for performance, I can't really help you there.

Regards,
Choonster