您的位置:首页 > 编程语言 > Lua

第10月第6天 lua 闭包

2017-07-06 09:53 274 查看
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);
[code]
lua_setglobal(L,
"upvalue_test"
);

http://www.cnblogs.com/biyeqingfeng/p/4990101.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: