diff options
author | Richard Quirk <richard.quirk@gmail.com> | 2014-03-19 19:31:31 +0100 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2014-04-02 20:31:54 +0200 |
commit | 36378988ad4059982742f05f5eb50580b456840a (patch) | |
tree | ee70be810d894566c5e351f21a1ebb79be742a85 /apps/plugins/lua/lauxlib.h | |
parent | 020f16a1c7d5bc9a302671cef03f56ac735e20c5 (diff) | |
download | rockbox-36378988ad4059982742f05f5eb50580b456840a.tar.gz rockbox-36378988ad4059982742f05f5eb50580b456840a.zip |
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
Diffstat (limited to 'apps/plugins/lua/lauxlib.h')
-rw-r--r-- | apps/plugins/lua/lauxlib.h | 130 |
1 files changed, 82 insertions, 48 deletions
diff --git a/apps/plugins/lua/lauxlib.h b/apps/plugins/lua/lauxlib.h index a36de351fe..0fb023b8e7 100644 --- a/apps/plugins/lua/lauxlib.h +++ b/apps/plugins/lua/lauxlib.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id$ | 2 | ** $Id: lauxlib.h,v 1.120.1.1 2013/04/12 18:48:47 roberto Exp $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -15,18 +15,6 @@ | |||
15 | #include "lua.h" | 15 | #include "lua.h" |
16 | 16 | ||
17 | 17 | ||
18 | #if defined(LUA_COMPAT_GETN) | ||
19 | LUALIB_API int (luaL_getn) (lua_State *L, int t); | ||
20 | LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); | ||
21 | #else | ||
22 | #define luaL_getn(L,i) ((int)lua_objlen(L, i)) | ||
23 | #define luaL_setn(L,i,j) ((void)0) /* no op! */ | ||
24 | #endif | ||
25 | |||
26 | #if defined(LUA_COMPAT_OPENLIB) | ||
27 | #define luaI_openlib luaL_openlib | ||
28 | #endif | ||
29 | |||
30 | 18 | ||
31 | /* extra error code for `luaL_load' */ | 19 | /* extra error code for `luaL_load' */ |
32 | #define LUA_ERRFILE (LUA_ERRERR+1) | 20 | #define LUA_ERRFILE (LUA_ERRERR+1) |
@@ -38,14 +26,12 @@ typedef struct luaL_Reg { | |||
38 | } luaL_Reg; | 26 | } luaL_Reg; |
39 | 27 | ||
40 | 28 | ||
29 | LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver); | ||
30 | #define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM) | ||
41 | 31 | ||
42 | LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, | ||
43 | const luaL_Reg *l, int nup); | ||
44 | LUALIB_API void (luaL_register) (lua_State *L, const char *libname, | ||
45 | const luaL_Reg *l); | ||
46 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); | 32 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); |
47 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); | 33 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); |
48 | LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); | 34 | LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); |
49 | LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); | 35 | LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); |
50 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, | 36 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, |
51 | size_t *l); | 37 | size_t *l); |
@@ -57,16 +43,17 @@ LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); | |||
57 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); | 43 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); |
58 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, | 44 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, |
59 | lua_Integer def); | 45 | lua_Integer def); |
60 | 46 | LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int numArg); | |
61 | LUALIB_API int (luaL_checkboolean) (lua_State *L, int numArg); | 47 | LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int numArg, |
62 | LUALIB_API int (luaL_optboolean) (lua_State *L, int nArg, | 48 | lua_Unsigned def); |
63 | int def); | ||
64 | 49 | ||
65 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); | 50 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); |
66 | LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); | 51 | LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); |
67 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); | 52 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); |
68 | 53 | ||
69 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); | 54 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); |
55 | LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); | ||
56 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); | ||
70 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); | 57 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); |
71 | 58 | ||
72 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); | 59 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); |
@@ -75,25 +62,41 @@ LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); | |||
75 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, | 62 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, |
76 | const char *const lst[]); | 63 | const char *const lst[]); |
77 | 64 | ||
65 | LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname); | ||
66 | LUALIB_API int (luaL_execresult) (lua_State *L, int stat); | ||
67 | |||
68 | /* pre-defined references */ | ||
69 | #define LUA_NOREF (-2) | ||
70 | #define LUA_REFNIL (-1) | ||
71 | |||
78 | LUALIB_API int (luaL_ref) (lua_State *L, int t); | 72 | LUALIB_API int (luaL_ref) (lua_State *L, int t); |
79 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); | 73 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); |
80 | 74 | ||
81 | LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); | 75 | LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, |
82 | LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, | 76 | const char *mode); |
83 | const char *name); | 77 | |
78 | #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) | ||
79 | |||
80 | LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, | ||
81 | const char *name, const char *mode); | ||
84 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); | 82 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); |
85 | 83 | ||
86 | LUALIB_API lua_State *(luaL_newstate) (void); | 84 | LUALIB_API lua_State *(luaL_newstate) (void); |
87 | 85 | ||
86 | LUALIB_API int (luaL_len) (lua_State *L, int idx); | ||
88 | 87 | ||
89 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, | 88 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, |
90 | const char *r); | 89 | const char *r); |
91 | 90 | ||
92 | LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, | 91 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); |
93 | const char *fname, int szhint); | ||
94 | 92 | ||
93 | LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname); | ||
95 | 94 | ||
95 | LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1, | ||
96 | const char *msg, int level); | ||
96 | 97 | ||
98 | LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, | ||
99 | lua_CFunction openf, int glb); | ||
97 | 100 | ||
98 | /* | 101 | /* |
99 | ** =============================================================== | 102 | ** =============================================================== |
@@ -101,6 +104,12 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, | |||
101 | ** =============================================================== | 104 | ** =============================================================== |
102 | */ | 105 | */ |
103 | 106 | ||
107 | |||
108 | #define luaL_newlibtable(L,l) \ | ||
109 | lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) | ||
110 | |||
111 | #define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) | ||
112 | |||
104 | #define luaL_argcheck(L, cond,numarg,extramsg) \ | 113 | #define luaL_argcheck(L, cond,numarg,extramsg) \ |
105 | ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) | 114 | ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) |
106 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) | 115 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) |
@@ -122,56 +131,81 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, | |||
122 | 131 | ||
123 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) | 132 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) |
124 | 133 | ||
134 | #define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) | ||
135 | |||
136 | |||
125 | /* | 137 | /* |
126 | ** {====================================================== | 138 | ** {====================================================== |
127 | ** Generic Buffer manipulation | 139 | ** Generic Buffer manipulation |
128 | ** ======================================================= | 140 | ** ======================================================= |
129 | */ | 141 | */ |
130 | 142 | ||
131 | |||
132 | |||
133 | typedef struct luaL_Buffer { | 143 | typedef struct luaL_Buffer { |
134 | char *p; /* current position in buffer */ | 144 | char *b; /* buffer address */ |
135 | int lvl; /* number of strings in the stack (level) */ | 145 | size_t size; /* buffer size */ |
146 | size_t n; /* number of characters in buffer */ | ||
136 | lua_State *L; | 147 | lua_State *L; |
137 | char buffer[LUAL_BUFFERSIZE]; | 148 | char initb[LUAL_BUFFERSIZE]; /* initial buffer */ |
138 | } luaL_Buffer; | 149 | } luaL_Buffer; |
139 | 150 | ||
140 | #define luaL_addchar(B,c) \ | ||
141 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ | ||
142 | (*(B)->p++ = (char)(c))) | ||
143 | 151 | ||
144 | /* compatibility only */ | 152 | #define luaL_addchar(B,c) \ |
145 | #define luaL_putchar(B,c) luaL_addchar(B,c) | 153 | ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \ |
154 | ((B)->b[(B)->n++] = (c))) | ||
146 | 155 | ||
147 | #define luaL_addsize(B,n) ((B)->p += (n)) | 156 | #define luaL_addsize(B,s) ((B)->n += (s)) |
148 | 157 | ||
149 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); | 158 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); |
150 | LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); | 159 | LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz); |
151 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); | 160 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); |
152 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); | 161 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); |
153 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); | 162 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); |
154 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); | 163 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); |
164 | LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz); | ||
165 | LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); | ||
155 | 166 | ||
167 | #define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE) | ||
156 | 168 | ||
157 | /* }====================================================== */ | 169 | /* }====================================================== */ |
158 | 170 | ||
159 | 171 | ||
160 | /* compatibility with ref system */ | ||
161 | 172 | ||
162 | /* pre-defined references */ | 173 | /* |
163 | #define LUA_NOREF (-2) | 174 | ** {====================================================== |
164 | #define LUA_REFNIL (-1) | 175 | ** File handles for IO library |
176 | ** ======================================================= | ||
177 | */ | ||
178 | |||
179 | /* | ||
180 | ** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and | ||
181 | ** initial structure 'luaL_Stream' (it may contain other fields | ||
182 | ** after that initial structure). | ||
183 | */ | ||
184 | |||
185 | #define LUA_FILEHANDLE "FILE*" | ||
186 | |||
187 | |||
188 | typedef struct luaL_Stream { | ||
189 | FILE *f; /* stream (NULL for incompletely created streams) */ | ||
190 | lua_CFunction closef; /* to close stream (NULL for closed streams) */ | ||
191 | } luaL_Stream; | ||
192 | |||
193 | /* }====================================================== */ | ||
194 | |||
165 | 195 | ||
166 | #define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ | ||
167 | (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) | ||
168 | 196 | ||
169 | #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) | 197 | /* compatibility with old module system */ |
198 | #if defined(LUA_COMPAT_MODULE) | ||
170 | 199 | ||
171 | #define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) | 200 | LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname, |
201 | int sizehint); | ||
202 | LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, | ||
203 | const luaL_Reg *l, int nup); | ||
172 | 204 | ||
205 | #define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0)) | ||
206 | |||
207 | #endif | ||
173 | 208 | ||
174 | #define luaL_reg luaL_Reg | ||
175 | 209 | ||
176 | #endif | 210 | #endif |
177 | 211 | ||