root/trunk/lua/lua.d

Revision 265, 9.5 kB (checked in by xammy, 1 month ago)

lua 5.1.3 bindings with wrapper classes and mixins

Line 
1 module lua.lua;
2
3 private import lua.luaconf, lua.lauxlib;
4
5 extern (C):
6
7 const char[] LUA_VERSION = "Lua 5.1";
8 const char[] LUA_RELEASE = "Lua 5.1.3";
9 const LUA_VERSION_NUM = 501;
10 const char[] LUA_COPYRIGHT = "Copyright (C) 1994-2008 Lua.org, PUC-Rio";
11 const char[] LUA_AUTHORS = "R. Ierusalimschy, L. H. de Figueiredo & W. Celes";
12
13
14 // mark for precompiled code (`<esc>Lua')
15 const char[] LUA_SIGNATURE = "\033Lua";
16
17 // option for multiple returns in `lua_pcall' and `lua_call'
18 const LUA_MULTRET = -1;
19
20
21 // pseudo-indices
22 const LUA_REGISTRYINDEX = -10000;
23 const LUA_ENVIRONINDEX = -10001;
24 const LUA_GLOBALSINDEX = -10002;
25
26 int lua_upvalueindex (int i) { return LUA_GLOBALSINDEX-i; }
27
28
29 // thread status; 0 is OK
30 const LUA_YIELD = 1;
31 const LUA_ERRRUN = 2;
32 const LUA_ERRSYNTAX = 3;
33 const LUA_ERRMEM = 4;
34 const LUA_ERRERR = 5;
35 const LUA_ERRFILE = LUA_ERRERR+1;
36
37 // don't specify lua_State in detail
38 alias void* lua_State;
39
40 typedef int  function(lua_State *L)lua_CFunction;
41
42
43 // functions that read/write blocks when loading/dumping Lua chunks
44 alias char * function(lua_State *L, void *ud, size_t *sz)lua_Reader;
45 alias int function(lua_State *L, void *p, size_t sz, void *ud)lua_Writer;
46
47 // prototype for memory-allocation functions
48 alias void * function(void *ud, void *ptr, size_t osize, size_t nsize)lua_Alloc;
49
50 // basic types
51 const LUA_TNONE = -1;
52 const LUA_TNIL = 0;
53 const LUA_TBOOLEAN = 1;
54 const LUA_TLIGHTUSERDATA = 2;
55 const LUA_TNUMBER = 3;
56 const LUA_TSTRING = 4;
57 const LUA_TTABLE = 5;
58 const LUA_TFUNCTION = 6;
59 const LUA_TUSERDATA = 7;
60 const LUA_TTHREAD = 8;
61
62 const LUA_MINSTACK = 20;
63
64 // type of numbers in Lua */
65 alias double lua_Number;
66 alias ptrdiff_t lua_Integer;
67
68 // state manipulation
69 lua_State * lua_newstate(lua_Alloc f, void *ud);
70 void  lua_close(lua_State *L);
71 lua_State * lua_newthread(lua_State *L);
72 lua_CFunction  lua_atpanic(lua_State *L, lua_CFunction panicf);
73
74
75 // basic stack manipulation
76 int  lua_gettop(lua_State *L);
77 void  lua_settop(lua_State *L, int idx);
78 void  lua_pushvalue(lua_State *L, int idx);
79 void  lua_remove(lua_State *L, int idx);
80 void  lua_insert(lua_State *L, int idx);
81 void  lua_replace(lua_State *L, int idx);
82 int  lua_checkstack(lua_State *L, int sz);
83
84 void  lua_xmove(lua_State *from, lua_State *to, int n);
85
86
87 // access functions (stack -> C)
88 int  lua_isnumber(lua_State *L, int idx);
89 int  lua_isstring(lua_State *L, int idx);
90 int  lua_iscfunction(lua_State *L, int idx);
91 int  lua_isuserdata(lua_State *L, int idx);
92 int  lua_type(lua_State *L, int idx);
93 char * lua_typename(lua_State *L, int tp);
94 int  lua_equal(lua_State *L, int idx1, int idx2);
95 int  lua_rawequal(lua_State *L, int idx1, int idx2);
96 int  lua_lessthan(lua_State *L, int idx1, int idx2);
97
98 lua_Number  lua_tonumber(lua_State *L, int idx);
99 lua_Integer  lua_tointeger(lua_State *L, int idx);
100 int  lua_toboolean(lua_State *L, int idx);
101 char * lua_tolstring(lua_State *L, int idx, size_t *len);
102 size_t  lua_objlen(lua_State *L, int idx);
103 lua_CFunction  lua_tocfunction(lua_State *L, int idx);
104 void * lua_touserdata(lua_State *L, int idx);
105 lua_State * lua_tothread(lua_State *L, int idx);
106 void * lua_topointer(lua_State *L, int idx);
107
108
109 // push functions (C -> stack)
110 void  lua_pushnil(lua_State *L);
111 void  lua_pushnumber(lua_State *L, lua_Number n);
112 void  lua_pushinteger(lua_State *L, lua_Integer n);
113 void  lua_pushlstring(lua_State *L, char *s, size_t l);
114 void  lua_pushstring(lua_State *L, char *s);
115 char * lua_pushvfstring(lua_State *L, char *fmt, ...);
116 char * lua_pushfstring(lua_State *L, char *fmt,...);
117 void  lua_pushcclosure(lua_State *L, lua_CFunction fn, int n);
118 void  lua_pushboolean(lua_State *L, int b);
119 void  lua_pushlightuserdata(lua_State *L, void *p);
120 int  lua_pushthread(lua_State *L);
121
122 // get functions (Lua -> stack)
123 void  lua_gettable(lua_State *L, int idx);
124 void  lua_getfield(lua_State *L, int idx, char *k);
125 void  lua_rawget(lua_State *L, int idx);
126 void  lua_rawgeti(lua_State *L, int idx, int n);
127 void  lua_createtable(lua_State *L, int narr, int nrec);
128 void * lua_newuserdata(lua_State *L, size_t sz);
129 int  lua_getmetatable(lua_State *L, int objindex);
130 void  lua_getfenv(lua_State *L, int idx);
131
132 // set functions (stack -> Lua)
133 void  lua_settable(lua_State *L, int idx);
134 void  lua_setfield(lua_State *L, int idx, char *k);
135 void  lua_rawset(lua_State *L, int idx);
136 void  lua_rawseti(lua_State *L, int idx, int n);
137 int  lua_setmetatable(lua_State *L, int objindex);
138 int  lua_setfenv(lua_State *L, int idx);
139
140 // `load' and `call' functions (load and run Lua code)
141 void  lua_call(lua_State *L, int nargs, int nresults);
142 int  lua_pcall(lua_State *L, int nargs, int nresults, int errfunc);
143 int  lua_cpcall(lua_State *L, lua_CFunction func, void *ud);
144 int  lua_load(lua_State *L, lua_Reader reader, void *dt, char *chunkname);
145 int  lua_dump(lua_State *L, lua_Writer writer, void *data);
146
147
148 // coroutine functions
149 int  lua_yield(lua_State *L, int nresults);
150 int  lua_resume(lua_State *L, int narg);
151 int  lua_status(lua_State *L);
152
153 // garbage-collection function and options
154 const LUA_GCSTOP = 0;
155 const LUA_GCRESTART = 1;
156 const LUA_GCCOLLECT = 2;
157 const LUA_GCCOUNT = 3;
158 const LUA_GCCOUNTB = 4;
159 const LUA_GCSTEP = 5;
160 const LUA_GCSETPAUSE = 6;
161 const LUA_GCSETSTEPMUL = 7;
162
163 int  lua_gc(lua_State *L, int what, int data);
164
165
166 // miscellaneous functions
167 int  lua_error(lua_State *L);
168 int  lua_next(lua_State *L, int idx);
169 void  lua_concat(lua_State *L, int n);
170 lua_Alloc  lua_getallocf(lua_State *L, void **ud);
171 void  lua_setallocf(lua_State *L, lua_Alloc f, void *ud);
172
173 // some useful macros
174 void lua_pop(lua_State* L, int n) { lua_settop(L, -(n)-1); }
175 void lua_newtable(lua_State* L) { lua_createtable(L, 0, 0); }
176 void lua_register(lua_State* L, char* n, lua_CFunction f) { lua_pushcfunction(L, f); lua_setglobal(L, n); }
177 void lua_pushcfunction(lua_State* L, lua_CFunction f) { lua_pushcclosure(L, f, 0); }
178 int lua_strlen(lua_State* L, int i) { return lua_objlen(L, i); }
179 bool lua_isfunction(lua_State* L, int n) { return lua_type(L, n) == LUA_TFUNCTION; }
180 bool lua_istable(lua_State* L, int n) { return lua_type(L, n) == LUA_TTABLE; }
181 bool lua_islightuserdata(lua_State* L, int n) { return lua_type(L, n) == LUA_TLIGHTUSERDATA; }
182 bool lua_isnil(lua_State* L, int n) { return lua_type(L, n) == LUA_TNIL; }
183 bool lua_isboolean(lua_State* L, int n) { return lua_type(L, n) == LUA_TBOOLEAN; }
184 bool lua_isthread(lua_State* L, int n) { return lua_type(L, n) == LUA_TTHREAD; }
185 bool lua_isnone(lua_State* L, int n) { return lua_type(L, n) == LUA_TNONE; }
186 bool lua_isnoneornil(lua_State* L, int n) { return lua_type(L, n) <= 0; }
187 void lua_pushliteral(lua_State* L, char[] s) { lua_pushlstring(L, (s ~ \0).ptr, s.length);  }
188 void lua_setglobal(lua_State* L, char* s) { lua_setfield(L, LUA_GLOBALSINDEX, s); }
189 void lua_getglobal(lua_State* L, char* s) { lua_getfield(L, LUA_GLOBALSINDEX, s); }
190 char* lua_tostring(lua_State* L, int i) { return lua_tolstring(L, i, null); }
191
192 // compatibility macros and functions
193 lua_State* lua_open() { return luaL_newstate(); }
194 void lua_getregistry(lua_State* L) { lua_pushvalue(L, LUA_REGISTRYINDEX); }
195 int lua_getgccount(lua_State* L) { return lua_gc(L, LUA_GCCOUNT, 0); }
196 alias lua_Reader lua_Chunkreader;
197 alias lua_Writer lua_Chunkwriter;
198
199 // hack
200 void lua_setlevel (lua_State *from, lua_State *to);
201
202
203 // Debug API
204
205 // Event codes
206 const LUA_HOOKCALL = 0;
207 const LUA_HOOKRET = 1;
208 const LUA_HOOKLINE = 2;
209 const LUA_HOOKCOUNT = 3;
210 const LUA_HOOKTAILRET = 4;
211
212 // Event masks
213 const LUA_MASKCALL = 1 << LUA_HOOKCALL;
214 const LUA_MASKRET = 1 << LUA_HOOKRET;
215 const LUA_MASKLINE = 1 << LUA_HOOKLINE;
216 const LUA_MASKCOUNT = 1 << LUA_HOOKCOUNT;
217
218 alias void  function(lua_State *L, lua_Debug *ar)lua_Hook;
219
220 int  lua_getstack(lua_State *L, int level, lua_Debug *ar);
221 int  lua_getinfo(lua_State *L, char *what, lua_Debug *ar);
222 char * lua_getlocal(lua_State *L, lua_Debug *ar, int n);
223 char * lua_setlocal(lua_State *L, lua_Debug *ar, int n);
224 char * lua_getupvalue(lua_State *L, int funcindex, int n);
225 char * lua_setupvalue(lua_State *L, int funcindex, int n);
226 int  lua_sethook(lua_State *L, lua_Hook func, int mask, int count);
227 lua_Hook  lua_gethook(lua_State *L);
228 int  lua_gethookmask(lua_State *L);
229 int  lua_gethookcount(lua_State *L);
230
231 struct lua_Debug
232 {
233     int event;
234     char *name;
235     char *namewhat;
236     char *what;
237     char *source;
238     int currentline;
239     int nups;
240     int linedefined;
241     int lastlinedefined;
242     char [LUA_IDSIZE]short_src;
243     int i_ci;
244 }
245
246 /******************************************************************************
247 * Copyright (C) 1994-2008 Lua.org, PUC-Rio.  All rights reserved.
248 *
249 * Permission is hereby granted, free of charge, to any person obtaining
250 * a copy of this software and associated documentation files (the
251 * "Software"), to deal in the Software without restriction, including
252 * without limitation the rights to use, copy, modify, merge, publish,
253 * distribute, sublicense, and/or sell copies of the Software, and to
254 * permit persons to whom the Software is furnished to do so, subject to
255 * the following conditions:
256 *
257 * The above copyright notice and this permission notice shall be
258 * included in all copies or substantial portions of the Software.
259 *
260 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
261 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
262 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
263 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
264 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
265 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
266 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
267 ******************************************************************************/
Note: See TracBrowser for help on using the browser.