第10月第6天 lua 闭包
1.
static int mytest(lua_State *L) { //获取上值 int upv = (int)lua_tonumber(L, lua_upvalueindex(1)); printf("%d\n", upv); upv += 5; lua_pushinteger(L, upv); lua_replace(L, lua_upvalueindex(1)); //获取一般参数 printf("%d\n", (int)lua_tonumber(L,1)); return 0; } int main(void) { lua_State *L = luaL_newstate(); luaL_openlibs(L); //设置Cclosure函数的上值 lua_pushinteger(L,10); lua_pushinteger(L,11); lua_pushcclosure(L,mytest,2);lua_setglobal(L,"upvalue_test");
http://www.cnblogs.com/biyeqingfeng/p/4990101.html

浙公网安备 33010602011771号