简体   繁体   中英

Lua script to C++ code

I am writing C functions for Lua. I have many calls like lua_gettable, lua_touserdata, etc

My C function may receive complex structures like table with tables as fields.

It is hard for me to program stacked machine.

Is there way to write Lua script that would be converted to C code.

Or some other tools that may help me to code such C functions for lua scripts.

Thanks.

PS

Here is example:-

local data = {}
data.x = {}
data.x.y = 1
myCfunc(data)

int myCfunc(lua_State * L){
 lua_pushstring(L, "x");
 lua_gettable(L, 2);
 lua_pushstring(L, "y");
 lua_gettable(L, -2);
 double y = lua_tonumber(L, -1);
 lua_pop(L, 2);
}

instead of

function myCfunc(data)
 y = data.x.y
end

My real code is much more complex and I am looking for some automated code generation that will help me.

试试LuaToCee

也许对卢阿可以提供帮助。

From C#, something I've done is written code to convert LUA datastructures in JSON format. Then I can load the data via any JSON library, with all their bells and whistles. Its kind of a round-about solution but you only have to write the JSON Encoding code once.

SWIG Simplified Wrapper和Interface Generator http://www.swig.org/它通常用于C to Lua,但是通过定义一些全局变量,你可以将它用作Lua到C

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM