1179896Sdelphij/* 2179896Sdelphij** $Id: lauxlib.h,v 1.120.1.1 2013/04/12 18:48:47 roberto Exp $ 3179896Sdelphij** Auxiliary functions for building Lua libraries 4179896Sdelphij** See Copyright Notice in lua.h 5179896Sdelphij*/ 6179896Sdelphij 7179896Sdelphij 8179896Sdelphij#ifndef lauxlib_h 9179896Sdelphij#define lauxlib_h 10179896Sdelphij 11179896Sdelphij 12179896Sdelphij#include <sys/zfs_context.h> 13179896Sdelphij 14179896Sdelphij#include "lua.h" 15179896Sdelphij 16179896Sdelphij 17179896Sdelphij 18179896Sdelphij/* extra error code for `luaL_load' */ 19179896Sdelphij#define LUA_ERRFILE (LUA_ERRERR+1) 20179896Sdelphij 21179896Sdelphij 22179896Sdelphijtypedef struct luaL_Reg { 23179896Sdelphij const char *name; 24179896Sdelphij lua_CFunction func; 25179896Sdelphij} luaL_Reg; 26179896Sdelphij 27179896Sdelphij 28179896SdelphijLUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver); 29179896Sdelphij#define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM) 30179896Sdelphij 31179896SdelphijLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 32179896SdelphijLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 33179896SdelphijLUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); 34179896SdelphijLUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); 35179896SdelphijLUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, 36179896Sdelphij size_t *l); 37179896SdelphijLUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, 38179896Sdelphij const char *def, size_t *l); 39179896SdelphijLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); 40179896SdelphijLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); 41179896Sdelphij 42179896SdelphijLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); 43179896SdelphijLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, 44179896Sdelphij lua_Integer def); 45179896SdelphijLUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int numArg); 46179896SdelphijLUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int numArg, 47179896Sdelphij lua_Unsigned def); 48179896Sdelphij 49179896SdelphijLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 50179896SdelphijLUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); 51179896SdelphijLUALIB_API void (luaL_checkany) (lua_State *L, int narg); 52179896Sdelphij 53179896SdelphijLUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); 54179896SdelphijLUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); 55179896SdelphijLUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); 56179896SdelphijLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); 57179896Sdelphij 58179896SdelphijLUALIB_API void (luaL_where) (lua_State *L, int lvl); 59179896SdelphijLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); 60185421Sbz 61185421SbzLUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, 62179896Sdelphij const char *const lst[]); 63179896Sdelphij 64179896Sdelphij/* pre-defined references */ 65179896Sdelphij#define LUA_NOREF (-2) 66179896Sdelphij#define LUA_REFNIL (-1) 67179896Sdelphij 68179896SdelphijLUALIB_API int (luaL_ref) (lua_State *L, int t); 69179896SdelphijLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); 70179896Sdelphij 71179896SdelphijLUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, 72179896Sdelphij const char *name, const char *mode); 73179896SdelphijLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); 74179896Sdelphij 75227908SmariusLUALIB_API int (luaL_len) (lua_State *L, int idx); 76179896Sdelphij 77179896SdelphijLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, 78179896Sdelphij const char *r); 79206563Syongari 80179896SdelphijLUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); 81179896Sdelphij 82179896SdelphijLUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname); 83179896Sdelphij 84179896SdelphijLUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1, 85179896Sdelphij const char *msg, int level); 86179896Sdelphij 87179896SdelphijLUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, 88179896Sdelphij lua_CFunction openf, int glb); 89179896Sdelphij 90179896Sdelphij/* 91179896Sdelphij** =============================================================== 92179896Sdelphij** some useful macros 93179896Sdelphij** =============================================================== 94221407Smarius*/ 95221407Smarius 96221407Smarius 97221407Smarius#define luaL_newlibtable(L,l) \ 98221407Smarius lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) 99221407Smarius 100179896Sdelphij#define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) 101179896Sdelphij 102179896Sdelphij#define luaL_argcheck(L, cond,numarg,extramsg) \ 103179896Sdelphij ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) 104179896Sdelphij#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 105179896Sdelphij#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 106179896Sdelphij#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) 107179896Sdelphij#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) 108179896Sdelphij#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) 109179896Sdelphij#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) 110179896Sdelphij 111179896Sdelphij#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) 112179896Sdelphij 113179896Sdelphij#define luaL_dofile(L, fn) \ 114179896Sdelphij (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 115179896Sdelphij 116179896Sdelphij#define luaL_dostring(L, s) \ 117179896Sdelphij (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 118179896Sdelphij 119179896Sdelphij#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) 120179896Sdelphij 121179896Sdelphij#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) 122179896Sdelphij 123179896Sdelphij#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) 124179896Sdelphij 125179896Sdelphij 126179896Sdelphij/* 127179896Sdelphij** {====================================================== 128179896Sdelphij** Generic Buffer manipulation 129179896Sdelphij** ======================================================= 130179896Sdelphij*/ 131179896Sdelphij 132179896Sdelphijtypedef struct luaL_Buffer { 133179896Sdelphij char *b; /* buffer address */ 134179896Sdelphij size_t size; /* buffer size */ 135179896Sdelphij size_t n; /* number of characters in buffer */ 136179896Sdelphij lua_State *L; 137179896Sdelphij char initb[LUAL_BUFFERSIZE]; /* initial buffer */ 138179896Sdelphij} luaL_Buffer; 139179896Sdelphij 140179896Sdelphij 141179896Sdelphij#define luaL_addchar(B,c) \ 142179896Sdelphij ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \ 143179896Sdelphij ((B)->b[(B)->n++] = (c))) 144179896Sdelphij 145179896Sdelphij#define luaL_addsize(B,s) ((B)->n += (s)) 146179896Sdelphij 147179896SdelphijLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); 148179896SdelphijLUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz); 149179896SdelphijLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); 150179896SdelphijLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); 151179896SdelphijLUALIB_API void (luaL_addvalue) (luaL_Buffer *B); 152221407SmariusLUALIB_API void (luaL_pushresult) (luaL_Buffer *B); 153221407SmariusLUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz); 154179896SdelphijLUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); 155221407Smarius 156179896Sdelphij#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE) 157221407Smarius 158179896Sdelphij/* }====================================================== */ 159179896Sdelphij 160179896Sdelphij 161179896Sdelphij/* compatibility with old module system */ 162179896Sdelphij#if defined(LUA_COMPAT_MODULE) 163179896Sdelphij 164179896SdelphijLUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname, 165213364Smarius int sizehint); 166179896SdelphijLUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, 167179896Sdelphij const luaL_Reg *l, int nup); 168179896Sdelphij 169213364Smarius#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0)) 170179896Sdelphij 171179896Sdelphij#endif 172179896Sdelphij 173179896Sdelphij 174179896Sdelphij#endif 175179896Sdelphij 176179896Sdelphij 177179896Sdelphij