diff options
| -rw-r--r-- | compat52.h | 70 |
1 files changed, 70 insertions, 0 deletions
| @@ -1,3 +1,6 @@ | |||
| 1 | #if LUA_VERSION_NUM < 502 | ||
| 2 | |||
| 3 | #define LUA_OK 0 | ||
| 1 | 4 | ||
| 2 | 5 | ||
| 3 | static void luaL_setmetatable(lua_State *L, const char *tname) { | 6 | static void luaL_setmetatable(lua_State *L, const char *tname) { |
| @@ -47,4 +50,71 @@ static void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { | |||
| 47 | (luaL_newlibtable((L), (l)), luaL_setfuncs((L), (l), 0)) | 50 | (luaL_newlibtable((L), (l)), luaL_setfuncs((L), (l), 0)) |
| 48 | 51 | ||
| 49 | 52 | ||
| 53 | static void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb) { | ||
| 54 | lua_pushcfunction(L, openf); | ||
| 55 | lua_pushstring(L, modname); | ||
| 56 | lua_call(L, 1, 1); | ||
| 57 | |||
| 58 | lua_getglobal(L, "package"); | ||
| 59 | lua_getfield(L, -1, "loaded"); | ||
| 60 | lua_pushvalue(L, -3); | ||
| 61 | lua_setfield(L, -2, modname); | ||
| 62 | |||
| 63 | lua_pop(L, 2); | ||
| 64 | |||
| 65 | if (glb) { | ||
| 66 | lua_pushvalue(L, -1); | ||
| 67 | lua_setglobal(L, modname); | ||
| 68 | } | ||
| 69 | } /* luaL_requiref() */ | ||
| 70 | |||
| 71 | |||
| 72 | #define lua_resume(L, from, nargs) lua_resume((L), (nargs)) | ||
| 73 | |||
| 74 | |||
| 75 | static void lua_rawgetp(lua_State *L, int index, const void *p) { | ||
| 76 | index = lua_absindex(L, index); | ||
| 77 | lua_pushlightuserdata(L, (void *)p); | ||
| 78 | lua_rawget(L, index); | ||
| 79 | } /* lua_rawgetp() */ | ||
| 80 | |||
| 81 | static void lua_rawsetp(lua_State *L, int index, const void *p) { | ||
| 82 | index = lua_absindex(L, index); | ||
| 83 | lua_pushlightuserdata(L, (void *)p); | ||
| 84 | lua_pushvalue(L, -2); | ||
| 85 | lua_rawset(L, index); | ||
| 86 | lua_pop(L, 1); | ||
| 87 | } /* lua_rawsetp() */ | ||
| 88 | |||
| 89 | |||
| 90 | #ifndef LUA_UNSIGNED | ||
| 91 | #define LUA_UNSIGNED unsigned | ||
| 92 | #endif | ||
| 93 | |||
| 94 | typedef LUA_UNSIGNED lua_Unsigned; | ||
| 95 | |||
| 96 | |||
| 97 | static void lua_pushunsigned(lua_State *L, lua_Unsigned n) { | ||
| 98 | lua_pushnumber(L, (lua_Number)n); | ||
| 99 | } /* lua_pushunsigned() */ | ||
| 100 | |||
| 101 | static lua_Unsigned luaL_checkunsigned(lua_State *L, int arg) { | ||
| 102 | return (lua_Unsigned)luaL_checknumber(L, arg); | ||
| 103 | } /* luaL_checkunsigned() */ | ||
| 104 | |||
| 105 | |||
| 106 | static lua_Unsigned luaL_optunsigned(lua_State *L, int arg, lua_Unsigned def) { | ||
| 107 | return (lua_Unsigned)luaL_optnumber(L, arg, (lua_Number)def); | ||
| 108 | } /* luaL_optunsigned() */ | ||
| 109 | |||
| 110 | |||
| 111 | /* | ||
| 112 | * Lua 5.1 userdata is a simple FILE *, while LuaJIT is a struct with the | ||
| 113 | * first membe a FILE *, similar to Lua 5.2. | ||
| 114 | */ | ||
| 115 | typedef struct luaL_Stream { | ||
| 116 | FILE *f; | ||
| 117 | } luaL_Stream; | ||
| 118 | |||
| 50 | 119 | ||
| 120 | #endif /* LUA_VERSION_NUM < 502 */ | ||
