X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=tools%2Fcpkg2c.mll;h=82be124f77b2d8fcd87475c23cb016b95cb48120;hb=7f591b58f859555c0eb573477f9ff179bfc46751;hp=b5ef25a27af267ad8e91d71703ea70189e8cfbaa;hpb=5f0d69cc13a116be64a243c07bad259af7d90397;p=apps%2Fmadmutt.git diff --git a/tools/cpkg2c.mll b/tools/cpkg2c.mll index b5ef25a..82be124 100644 --- a/tools/cpkg2c.mll +++ b/tools/cpkg2c.mll @@ -511,7 +511,6 @@ and ext_member m f = parse printf "static int luaM_%s_index(lua_State *L)\n{\n" pkg.name; printf " const char *idx = luaL_checkstring(L, 2);\n\n"; printf " switch (mlua_which_token(idx, -1)) {\n"; - printf " default:\n"; List.iter (function (m, _, _) -> printf " case LTK_%s:\n" (upper m.mname); let push, f, l = (snd m.typ).push in @@ -519,7 +518,8 @@ and ext_member m f = parse printf " %s;\n" (tplize push (sprintf "%s.%s" pkg.name m.mname)); printf " return 1;\n" ) pkg.members; - printf " lua_rawget(L, lua_upvalueindex(2));\n"; + printf " default:\n"; + printf " lua_rawget(L, lua_upvalueindex(1));\n"; printf " return 1;\n"; printf " }\n}\n\n"; @@ -561,6 +561,7 @@ and ext_member m f = parse printf " return 1;\n" ) pkg.members; printf " default:\n"; + printf " lua_rawset(L, lua_upvalueindex(1));\n"; printf " return 1;\n"; printf " }\n}\n"; @@ -576,7 +577,7 @@ and ext_member m f = parse int luaopen_%s(lua_State *L) { - int mt, methods; + int mt, members, methods; %s_init(); @@ -584,18 +585,20 @@ int luaopen_%s(lua_State *L) luaL_openlib(L, \"%s\", luaM_%s_methods, 0); methods = lua_gettop(L); + lua_newtable(L); /* for new members */ + members = lua_gettop(L); + /* create metatable for %s, add it to the registry */ luaL_newmetatable(L, \"%s\"); mt = lua_gettop(L); lua_pushliteral(L, \"__index\"); - lua_pushvalue(L, mt); /* upvalue 1 */ - lua_pushvalue(L, methods); /* upvalue 2 */ - lua_pushcclosure(L, &luaM_%s_index, 2); + lua_pushvalue(L, members); /* upvalue 1 */ + lua_pushcclosure(L, &luaM_%s_index, 1); lua_rawset(L, mt); /* set mt.__index */ lua_pushliteral(L, \"__newindex\"); - lua_newtable(L); /* for new members */ + lua_pushvalue(L, members); /* upvalue 1 */ lua_pushcclosure(L, &luaM_%s_newindex, 1); lua_rawset(L, mt); /* set mt.__newindex */ @@ -605,7 +608,7 @@ int luaopen_%s(lua_State *L) lua_setmetatable(L, methods); - lua_pop(L, 2); /* drop mt + methods */ + lua_pop(L, 3); return 1; }