src/lxplib.c

changeset 31
ebb63b55bcc1
parent 26
a8caec6c5429
child 32
73adc42f35ce
equal deleted inserted replaced
30:b20d4fce3095 31:ebb63b55bcc1
18 #include "lxplib.h" 18 #include "lxplib.h"
19 19
20 #if (LUA_VERSION_NUM == 501) 20 #if (LUA_VERSION_NUM == 501)
21 #define lua_getuservalue(L, i) lua_getfenv(L, i) 21 #define lua_getuservalue(L, i) lua_getfenv(L, i)
22 #define lua_setuservalue(L, i) lua_setfenv(L, i) 22 #define lua_setuservalue(L, i) lua_setfenv(L, i)
23 #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
23 #endif 24 #endif
24 25
25 #if !defined(lua_pushliteral) 26 #if !defined(lua_pushliteral)
26 #define lua_pushliteral(L, s) \ 27 #define lua_pushliteral(L, s) \
27 lua_pushstring(L, "" s, (sizeof(s)/sizeof(char))-1) 28 lua_pushstring(L, "" s, (sizeof(s)/sizeof(char))-1)
586 lua_pushliteral (L, "_VERSION"); 587 lua_pushliteral (L, "_VERSION");
587 lua_pushliteral (L, "LuaExpat 1.3.0"); 588 lua_pushliteral (L, "LuaExpat 1.3.0");
588 lua_settable (L, -3); 589 lua_settable (L, -3);
589 } 590 }
590 591
591
592 #if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501
593 /*
594 ** Adapted from Lua 5.2.0
595 */
596 static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
597 luaL_checkstack(L, nup, "too many upvalues");
598 for (; l->name != NULL; l++) { /* fill the table with given functions */
599 int i;
600 for (i = 0; i < nup; i++) /* copy upvalues to the top */
601 lua_pushvalue(L, -nup);
602 lua_pushstring(L, l->name);
603 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
604 lua_settable(L, -(nup + 3));
605 }
606 lua_pop(L, nup); /* remove upvalues */
607 }
608 #endif
609
610
611 int luaopen_lxp (lua_State *L) { 592 int luaopen_lxp (lua_State *L) {
612 luaL_newmetatable(L, ParserType); 593 luaL_newmetatable(L, ParserType);
613 594
614 lua_pushliteral(L, "__index"); 595 lua_pushliteral(L, "__index");
615 lua_pushvalue(L, -2); 596 lua_pushvalue(L, -2);

mercurial