2009-05-21 19:01:41 +00:00
|
|
|
/*
|
2018-11-08 16:32:45 +00:00
|
|
|
** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
|
2009-05-21 19:01:41 +00:00
|
|
|
** Auxiliary functions for building Lua libraries
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef lauxlib_h
|
|
|
|
#define lauxlib_h
|
|
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "lua.h"
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#if defined(LUA_COMPAT_GETN)
|
|
|
|
LUALIB_API int (luaL_getn) (lua_State *L, int t);
|
|
|
|
LUALIB_API void (luaL_setn) (lua_State *L, int t, int n);
|
|
|
|
#else
|
|
|
|
#define luaL_getn(L,i) ((int)lua_objlen(L, i))
|
|
|
|
#define luaL_setn(L,i,j) ((void)0) /* no op! */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(LUA_COMPAT_OPENLIB)
|
|
|
|
#define luaI_openlib luaL_openlib
|
|
|
|
#endif
|
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
/* extra error code for `luaL_load' */
|
|
|
|
#define LUA_ERRFILE (LUA_ERRERR+1)
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct luaL_Reg {
|
|
|
|
const char *name;
|
|
|
|
lua_CFunction func;
|
|
|
|
} luaL_Reg;
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname,
|
|
|
|
const luaL_Reg *l, int nup);
|
|
|
|
LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
|
|
|
|
const luaL_Reg *l);
|
2009-05-21 19:01:41 +00:00
|
|
|
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
|
|
|
|
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
|
2014-04-02 18:46:06 +00:00
|
|
|
LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
|
2009-05-21 19:01:41 +00:00
|
|
|
LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
|
|
|
|
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
|
|
|
|
size_t *l);
|
|
|
|
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
|
|
|
|
const char *def, size_t *l);
|
|
|
|
LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
|
|
|
|
LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
|
|
|
|
|
|
|
|
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
|
|
|
|
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
|
|
|
|
lua_Integer def);
|
2014-04-02 18:46:06 +00:00
|
|
|
|
2018-11-08 16:32:45 +00:00
|
|
|
LUALIB_API int (luaL_checkboolean) (lua_State *L, int nArg);
|
2014-04-02 18:46:06 +00:00
|
|
|
LUALIB_API int (luaL_optboolean) (lua_State *L, int nArg,
|
|
|
|
int def);
|
2009-05-25 11:12:27 +00:00
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
|
|
|
|
LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
|
|
|
|
LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
|
|
|
|
|
|
|
|
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
|
|
|
|
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
|
|
|
|
|
|
|
|
LUALIB_API void (luaL_where) (lua_State *L, int lvl);
|
|
|
|
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
|
|
|
|
|
|
|
|
LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
|
|
|
|
const char *const lst[]);
|
|
|
|
|
|
|
|
LUALIB_API int (luaL_ref) (lua_State *L, int t);
|
|
|
|
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
|
|
|
|
LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
|
|
|
|
const char *name);
|
2009-05-21 19:01:41 +00:00
|
|
|
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
|
|
|
|
|
|
|
|
LUALIB_API lua_State *(luaL_newstate) (void);
|
|
|
|
|
|
|
|
|
|
|
|
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
|
|
|
|
const char *r);
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
|
|
|
|
const char *fname, int szhint);
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** ===============================================================
|
|
|
|
** some useful macros
|
|
|
|
** ===============================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define luaL_argcheck(L, cond,numarg,extramsg) \
|
|
|
|
((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
|
|
|
|
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
|
|
|
|
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
|
|
|
|
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
|
|
|
|
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
|
|
|
|
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
|
|
|
|
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
|
|
|
|
|
|
|
|
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
|
|
|
|
|
|
|
|
#define luaL_dofile(L, fn) \
|
|
|
|
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
|
|
|
|
|
|
|
|
#define luaL_dostring(L, s) \
|
|
|
|
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
|
|
|
|
|
|
|
|
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
|
|
|
|
|
|
|
|
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
|
|
|
|
|
|
|
|
/*
|
|
|
|
** {======================================================
|
|
|
|
** Generic Buffer manipulation
|
|
|
|
** =======================================================
|
|
|
|
*/
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
|
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
typedef struct luaL_Buffer {
|
2014-04-02 18:46:06 +00:00
|
|
|
char *p; /* current position in buffer */
|
|
|
|
int lvl; /* number of strings in the stack (level) */
|
2009-05-21 19:01:41 +00:00
|
|
|
lua_State *L;
|
2014-04-02 18:46:06 +00:00
|
|
|
char buffer[LUAL_BUFFERSIZE];
|
2009-05-21 19:01:41 +00:00
|
|
|
} luaL_Buffer;
|
|
|
|
|
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>
2014-03-19 18:31:31 +00:00
|
|
|
#define luaL_addchar(B,c) \
|
2014-04-02 18:46:06 +00:00
|
|
|
((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
|
|
|
|
(*(B)->p++ = (char)(c)))
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
/* compatibility only */
|
|
|
|
#define luaL_putchar(B,c) luaL_addchar(B,c)
|
|
|
|
|
|
|
|
#define luaL_addsize(B,n) ((B)->p += (n))
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
|
2014-04-02 18:46:06 +00:00
|
|
|
LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);
|
2009-05-21 19:01:41 +00:00
|
|
|
LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
|
|
|
|
LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
|
|
|
|
LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
|
|
|
|
LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
|
|
|
|
|
|
|
|
|
|
|
|
/* }====================================================== */
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
/* compatibility with ref system */
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
/* pre-defined references */
|
|
|
|
#define LUA_NOREF (-2)
|
|
|
|
#define LUA_REFNIL (-1)
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
|
|
|
|
(lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
|
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>
2014-03-19 18:31:31 +00:00
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define luaL_reg luaL_Reg
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|