[英]how to call lua operator in c?
The following example shows how the c program can do the equivalent to the Lua code: 以下示例显示了c程序如何执行与Lua代码等效的操作:
a = f(t)
Here it is in C: 它在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? 那么,以下Lua代码的等效C代码是什么?
a = t + 1
Since we have no information about t
, we should call the underlying +
operator in c code, but HOW? 由于我们没有关于
t
信息,我们应该在c代码中调用底层的+
运算符,但是如何呢?
lua_getglobal(L, "t");
lua_pushinteger(L, 1);
lua_arith(L, LUA_OPADD);
lua_setglobal(L, "a");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.