如何在 c 中调用 lua 运算符?

how to call lua operator in c?

以下示例显示了 c 程序如何执行与 Lua 代码等效的操作:

a = f(t)

在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"

那么,以下Lua代码的等效C代码是什么?

a = t + 1

由于我们没有关于 t 的信息,我们应该在 c 代码中调用底层的 + 运算符,但是如何?

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