| 1 |
module lua.lauxlib; |
|---|
| 2 |
|
|---|
| 3 |
private import lua.lua; |
|---|
| 4 |
private import lua.luaconf; |
|---|
| 5 |
|
|---|
| 6 |
extern (C): |
|---|
| 7 |
|
|---|
| 8 |
int luaL_getn(lua_State* L, int i) { return lua_objlen(L, i); } |
|---|
| 9 |
void luaL_setn(lua_State* L, int i, int j) { } |
|---|
| 10 |
|
|---|
| 11 |
alias luaL_openlib luaI_openlib; |
|---|
| 12 |
|
|---|
| 13 |
struct luaL_Reg |
|---|
| 14 |
{ |
|---|
| 15 |
char *name; |
|---|
| 16 |
lua_CFunction func; |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
void luaL_openlib(lua_State *L, char *libname, luaL_Reg *l, int nup); |
|---|
| 20 |
void luaL_register(lua_State *L, char *libname, luaL_Reg *l); |
|---|
| 21 |
int luaL_getmetafield(lua_State *L, int obj, char *e); |
|---|
| 22 |
int luaL_callmeta(lua_State *L, int obj, char *e); |
|---|
| 23 |
int luaL_typerror(lua_State *L, int narg, char *tname); |
|---|
| 24 |
int luaL_argerror(lua_State *L, int numarg, char *extramsg); |
|---|
| 25 |
char * luaL_checklstring(lua_State *L, int numArg, size_t *l); |
|---|
| 26 |
char * luaL_optlstring(lua_State *L, int numArg, char *def, size_t *l); |
|---|
| 27 |
lua_Number luaL_checknumber(lua_State *L, int numArg); |
|---|
| 28 |
lua_Number luaL_optnumber(lua_State *L, int nArg, lua_Number def); |
|---|
| 29 |
|
|---|
| 30 |
lua_Integer luaL_checkinteger(lua_State *L, int numArg); |
|---|
| 31 |
lua_Integer luaL_optinteger(lua_State *L, int nArg, lua_Integer def); |
|---|
| 32 |
|
|---|
| 33 |
void luaL_checkstack(lua_State *L, int sz, char *msg); |
|---|
| 34 |
void luaL_checktype(lua_State *L, int narg, int t); |
|---|
| 35 |
void luaL_checkany(lua_State *L, int narg); |
|---|
| 36 |
|
|---|
| 37 |
int luaL_newmetatable(lua_State *L, char *tname); |
|---|
| 38 |
void * luaL_checkudata(lua_State *L, int ud, char *tname); |
|---|
| 39 |
|
|---|
| 40 |
void luaL_where(lua_State *L, int lvl); |
|---|
| 41 |
int luaL_error(lua_State *L, char *fmt,...); |
|---|
| 42 |
|
|---|
| 43 |
int luaL_checkoption(lua_State *L, int narg, char *def, char **lst); |
|---|
| 44 |
|
|---|
| 45 |
int luaL_ref(lua_State *L, int t); |
|---|
| 46 |
void luaL_unref(lua_State *L, int t, int _ref); |
|---|
| 47 |
|
|---|
| 48 |
int luaL_loadfile(lua_State *L, char *filename); |
|---|
| 49 |
int luaL_loadbuffer(lua_State *L, char *buff, size_t sz, char *name); |
|---|
| 50 |
int luaL_loadstring(lua_State *L, char *s); |
|---|
| 51 |
|
|---|
| 52 |
lua_State * luaL_newstate(); |
|---|
| 53 |
|
|---|
| 54 |
char * luaL_gsub(lua_State *L, char *s, char *p, char *r); |
|---|
| 55 |
|
|---|
| 56 |
char * luaL_findtable(lua_State *L, int idx, char *fname, int szhint); |
|---|
| 57 |
|
|---|
| 58 |
// some useful macros |
|---|
| 59 |
|
|---|
| 60 |
void luaL_argcheck(lua_State* L, int cond, int numarg, char* extramsg) { if (!cond) luaL_argerror(L, numarg, extramsg); } |
|---|
| 61 |
char* luaL_checkstring(lua_State* L, int n) { return luaL_checklstring(L, n, null); } |
|---|
| 62 |
char* luaL_optstring(lua_State* L, int n, char* d) { return luaL_optlstring(L, n, d, null); } |
|---|
| 63 |
int luaL_checkint(lua_State* L, int n) { return luaL_checkinteger(L, n); } |
|---|
| 64 |
int luaL_optint (lua_State* L, int n, int d) { return luaL_optinteger(L, n, d); } |
|---|
| 65 |
long luaL_checklong(lua_State* L, int n) { return luaL_checkinteger(L, n); } |
|---|
| 66 |
int luaL_optlong(lua_State* L, int n, int d) { return luaL_optinteger(L, n, d); } |
|---|
| 67 |
|
|---|
| 68 |
char* luaL_typename(lua_State* L, int i) { return lua_typename(L, lua_type(L, i)); } |
|---|
| 69 |
|
|---|
| 70 |
int luaL_dofile(lua_State* L, char* fn) { return luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0); } |
|---|
| 71 |
|
|---|
| 72 |
int luaL_dostring(lua_State*L, char* s) { return luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0); } |
|---|
| 73 |
|
|---|
| 74 |
void luaL_getmetatable(lua_State* L, char* s) { lua_getfield(L, LUA_REGISTRYINDEX, s); } |
|---|
| 75 |
|
|---|
| 76 |
bool luaL_opt(lua_State* L, int function(lua_State*, int) f, int n, int d) { return luaL_opt(L, f, n, d); } |
|---|
| 77 |
|
|---|
| 78 |
// Generic Buffer manipulation |
|---|
| 79 |
struct luaL_Buffer |
|---|
| 80 |
{ |
|---|
| 81 |
char *p; |
|---|
| 82 |
int lvl; |
|---|
| 83 |
lua_State *L; |
|---|
| 84 |
char [LUAL_BUFFERSIZE]buffer; |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
void luaL_addchar(luaL_Buffer* B, char c) |
|---|
| 88 |
{ |
|---|
| 89 |
if (B.p < B.buffer.ptr + LUAL_BUFFERSIZE || (luaL_prepbuffer(B))) |
|---|
| 90 |
{ |
|---|
| 91 |
*B.p = c; |
|---|
| 92 |
B.p++; |
|---|
| 93 |
} |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
void luaL_putchar(luaL_Buffer* B, char c) { luaL_addchar(B, c); } |
|---|
| 97 |
|
|---|
| 98 |
void luaL_addsize(luaL_Buffer* B, int n) { B.p += n; } |
|---|
| 99 |
|
|---|
| 100 |
void luaL_buffinit(lua_State *L, luaL_Buffer *B); |
|---|
| 101 |
char * luaL_prepbuffer(luaL_Buffer *B); |
|---|
| 102 |
void luaL_addlstring(luaL_Buffer *B, char *s, size_t l); |
|---|
| 103 |
void luaL_addstring(luaL_Buffer *B, char *s); |
|---|
| 104 |
void luaL_addvalue(luaL_Buffer *B); |
|---|
| 105 |
void luaL_pushresult(luaL_Buffer *B); |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
// compatibility with ref system |
|---|
| 109 |
|
|---|
| 110 |
const LUA_NOREF = -2; |
|---|
| 111 |
const LUA_REFNIL = -1; |
|---|
| 112 |
|
|---|
| 113 |
void lua_ref(lua_State* L, int lock) { lock ? luaL_ref(L, LUA_REGISTRYINDEX) : lua_pushstring(L, "unlocked reference are obsolete"); lua_error(L); } |
|---|
| 114 |
void lua_unref(lua_State* L, int _ref) { luaL_unref(L, LUA_REGISTRYINDEX, _ref); } |
|---|
| 115 |
void lua_getref(lua_State* L, int _ref) { lua_rawgeti(L, LUA_REGISTRYINDEX, _ref); } |
|---|
| 116 |
|
|---|
| 117 |
alias luaL_Reg luaL_reg; |
|---|
| 118 |
|
|---|
| 119 |
// some additional aliases |
|---|
| 120 |
alias luaL_checkstring luaL_check_string; |
|---|
| 121 |
alias luaL_optstring luaL_opt_string; |
|---|
| 122 |
alias luaL_checkint luaL_check_int; |
|---|
| 123 |
alias luaL_checkint luaL_check_int; |
|---|
| 124 |
alias luaL_checklong luaL_check_long; |
|---|
| 125 |
alias luaL_optint luaL_opt_int; |
|---|
| 126 |
alias luaL_optint luaL_opt_int; |
|---|
| 127 |
alias luaL_optlong luaL_opt_long; |
|---|