root/trunk/lua/lauxlib.d

Revision 324, 4.5 kB (checked in by Trass3r, 3 years ago)

+ D2 compatibility!
+ precompiled lua 5.1.4
+ Exceptions support file and line arguments
* changed file encoding to UTF-8
* several bugfixes

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