简体   繁体   中英

how to call lua operator in c?

The following example shows how the c program can do the equivalent to the Lua code:

a = f(t)

Here it is in C:

lua_getglobal(L, "f");    // function to be called
lua_getglobal(L, "t");    // 1 argument
lua_call(L, 1, 1);        // call "f" with 1 argument and 1 result
lua_setglobal(L, "a");    // set "a"

So, what is the equivalent C code of the following Lua code?

a = t + 1

Since we have no information about t , we should call the underlying + operator in c code, but HOW?

lua_getglobal(L, "t");
lua_pushinteger(L, 1);
lua_arith(L, LUA_OPADD);
lua_setglobal(L, "a");

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