summaryrefslogtreecommitdiff
path: root/src/compat52.h
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-08-26 22:00:08 +1000
committerdaurnimator <quae@daurnimator.com>2017-08-30 23:34:48 +1000
commit71c54169bb96543a50f90767d351702f63fa0220 (patch)
tree426b26a2a73747e457c1947d143b6dc55d4fe0e0 /src/compat52.h
parentb8e3766294b6bf11d70a8a202e633b2569675e77 (diff)
downloadluaossl-71c54169bb96543a50f90767d351702f63fa0220.tar.gz
luaossl-71c54169bb96543a50f90767d351702f63fa0220.tar.bz2
luaossl-71c54169bb96543a50f90767d351702f63fa0220.zip
Move over to using lua-compat-5.3
Diffstat (limited to 'src/compat52.h')
-rw-r--r--src/compat52.h178
1 files changed, 0 insertions, 178 deletions
diff --git a/src/compat52.h b/src/compat52.h
deleted file mode 100644
index 9b0a48e..0000000
--- a/src/compat52.h
+++ /dev/null
@@ -1,178 +0,0 @@
1/* ==========================================================================
2 * compat52.h - Routines for Lua 5.2 compatibility
3 * --------------------------------------------------------------------------
4 * Copyright (c) 2012 William Ahern
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to permit
11 * persons to whom the Software is furnished to do so, subject to the
12 * following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
20 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * ==========================================================================
25 */
26
27
28#if LUA_VERSION_NUM < 503
29
30#define lua_getfield(L, i, f) (lua_getfield(L, (i), (f)), lua_type(L, -1))
31
32static int lua_isinteger(lua_State *L, int index) {
33 if (lua_type(L, index) == LUA_TNUMBER) {
34 lua_Number n = lua_tonumber(L, index);
35 lua_Integer i = lua_tointeger(L, index);
36 if (i == n)
37 return 1;
38 }
39 return 0;
40}
41
42#endif
43
44#if LUA_VERSION_NUM < 502
45
46#define LUA_OK 0
47
48
49static void luaL_setmetatable(lua_State *L, const char *tname) {
50 luaL_getmetatable(L, tname);
51 lua_setmetatable(L, -2);
52} /* luaL_setmetatable() */
53
54
55static int lua_absindex(lua_State *L, int idx) {
56 return (idx > 0 || idx <= LUA_REGISTRYINDEX)? idx : lua_gettop(L) + idx + 1;
57} /* lua_absindex() */
58
59
60static void *luaL_testudata(lua_State *L, int arg, const char *tname) {
61 void *p = lua_touserdata(L, arg);
62 int eq;
63
64 if (!p || !lua_getmetatable(L, arg))
65 return 0;
66
67 luaL_getmetatable(L, tname);
68 eq = lua_rawequal(L, -2, -1);
69 lua_pop(L, 2);
70
71 return (eq)? p : 0;
72} /* luaL_testudate() */
73
74
75static void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) {
76 int i, t = lua_absindex(L, -1 - nup);
77
78 for (; l->name; l++) {
79 for (i = 0; i < nup; i++)
80 lua_pushvalue(L, -nup);
81 lua_pushcclosure(L, l->func, nup);
82 lua_setfield(L, t, l->name);
83 }
84
85 lua_pop(L, nup);
86} /* luaL_setfuncs() */
87
88
89#define luaL_newlibtable(L, l) \
90 lua_createtable(L, 0, (sizeof (l) / sizeof *(l)) - 1)
91
92#define luaL_newlib(L, l) \
93 (luaL_newlibtable((L), (l)), luaL_setfuncs((L), (l), 0))
94
95
96static void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb) {
97 lua_pushcfunction(L, openf);
98 lua_pushstring(L, modname);
99 lua_call(L, 1, 1);
100
101 lua_getglobal(L, "package");
102 lua_getfield(L, -1, "loaded");
103 lua_pushvalue(L, -3);
104 lua_setfield(L, -2, modname);
105
106 lua_pop(L, 2);
107
108 if (glb) {
109 lua_pushvalue(L, -1);
110 lua_setglobal(L, modname);
111 }
112} /* luaL_requiref() */
113
114
115#define lua_resume(L, from, nargs) lua_resume((L), (nargs))
116
117
118static void lua_rawgetp(lua_State *L, int index, const void *p) {
119 index = lua_absindex(L, index);
120 lua_pushlightuserdata(L, (void *)p);
121 lua_rawget(L, index);
122} /* lua_rawgetp() */
123
124static void lua_rawsetp(lua_State *L, int index, const void *p) {
125 index = lua_absindex(L, index);
126 lua_pushlightuserdata(L, (void *)p);
127 lua_pushvalue(L, -2);
128 lua_rawset(L, index);
129 lua_pop(L, 1);
130} /* lua_rawsetp() */
131
132
133#ifndef LUA_UNSIGNED
134#define LUA_UNSIGNED unsigned
135#endif
136
137typedef LUA_UNSIGNED lua_Unsigned;
138
139
140static void lua_pushunsigned(lua_State *L, lua_Unsigned n) {
141 lua_pushnumber(L, (lua_Number)n);
142} /* lua_pushunsigned() */
143
144static lua_Unsigned luaL_checkunsigned(lua_State *L, int arg) {
145 return (lua_Unsigned)luaL_checknumber(L, arg);
146} /* luaL_checkunsigned() */
147
148
149static lua_Unsigned luaL_optunsigned(lua_State *L, int arg, lua_Unsigned def) {
150 return (lua_Unsigned)luaL_optnumber(L, arg, (lua_Number)def);
151} /* luaL_optunsigned() */
152
153
154#ifndef LUA_FILEHANDLE /* Not defined by earlier LuaJIT releases */
155#define LUA_FILEHANDLE "FILE*"
156#endif
157
158/*
159 * Lua 5.1 userdata is a simple FILE *, while LuaJIT is a struct with the
160 * first member a FILE *, similar to Lua 5.2.
161 */
162typedef struct luaL_Stream {
163 FILE *f;
164} luaL_Stream;
165
166
167#define lua_rawlen(...) lua_objlen(__VA_ARGS__)
168
169
170#define lua_pushstring(...) lua52_pushstring(__VA_ARGS__)
171
172static const char *lua52_pushstring(lua_State *L, const char *s) {
173 (lua_pushstring)(L, s);
174 return lua_tostring(L, -1);
175} /* lua52_pushstring() */
176
177
178#endif /* LUA_VERSION_NUM < 502 */