lua-users home
lua-l archive

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


2014-06-23 13:54 GMT+01:00 Austin Einter <austin.einter@gmail.com>:
> 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

This is not valid Lua. You need to replace "int" with "local" for it to work.

> 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.

You can first compile the string into a Lua function with
luaL_loadstring. Then you can call the function with lua_call and get
the return value on the Lua stack through the C API.