1 
2 //          Copyright 2019 - 2021 Michael D. Parker
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          http://www.boost.org/LICENSE_1_0.txt)
6 
7 module bindbc.lua.v51.binddynamic;
8 
9 version(BindBC_Static) version = BindLua_Static;
10 version(BindLua_Static) {}
11 else version = BindLua_Dynamic;
12 
13 version(LUA_51) {
14     version(BindLua_Dynamic) version = LUA_51_DYNAMIC;
15 }
16 
17 version(LUA_51_DYNAMIC):
18 
19 import core.stdc.stdarg : va_list;
20 import bindbc.loader;
21 import bindbc.lua.config;
22 import bindbc.lua.v51.types;
23 
24 extern(C) @nogc nothrow {
25     // lauxlib.h
26     alias pluaI_openlib = void function(lua_State* L,const(char)* libname, const(luaL_Reg)* l, int nup);
27     alias pluaL_register = void function(lua_State* L, const(char)* libname, const(luaL_Reg)* l);
28     alias pluaL_getmetafield = int function(lua_State* L, int obj, const(char)* e);
29     alias pluaL_callmeta = int function(lua_State* L,  int obj, const(char)* e);
30     alias pluaL_typerror = int function(lua_State* L, int narg, const(char)* tname);
31     alias pluaL_argerror = int function(lua_State* L, int numarg, const(char)* extramsg);
32     alias pluaL_checklstring = const(char)* function(lua_State* L, int numarg, size_t* l);
33     alias pluaL_optlstring = const(char)* function(lua_State* L, int numArg, const(char)* def, size_t* l);
34     alias pluaL_checknumber = lua_Number function(lua_State* L, int numArg);
35     alias pluaL_optnumber = lua_Number function(lua_State* L, int nArg, lua_Number def);
36     alias pluaL_checkinteger = lua_Integer function(lua_State* L, int numArg);
37     alias pluaL_optinteger = lua_Integer function(lua_State* L, int nArg, lua_Integer def);
38     alias pluaL_checkstack = void function(lua_State* L, int sz, const(char)* msg);
39     alias pluaL_checktype = void function(lua_State* L, int narg, int t);
40     alias pluaL_checkany = void function(lua_State* L, int narg);
41     alias pluaL_newmetatable = int function(lua_State* L, const(char)* tname);
42     alias pluaL_checkudata = void* function(lua_State* L, int ud, const(char)* tname);
43     alias pluaL_where = void function(lua_State* L, int lvl);
44     alias pluaL_error = int function(lua_State* L, const(char)* fmt, ...);
45     alias pluaL_checkoption = int function(lua_State* L, int narg, const(char)* def, const(char)** lst);
46     alias pluaL_ref = int function(lua_State* L, int t);
47     alias pluaL_unref = void function(lua_State* L, int t, int ref_);
48     alias pluaL_loadfile = int function(lua_State* L, const(char)* filename);
49     alias pluaL_loadbuffer = int function(lua_State* L, const(char)* buff, size_t sz, const(char)* name);
50     alias pluaL_loadstring = int function(lua_State* L, const(char)* s);
51     alias pluaL_newstate = lua_State* function();
52     alias pluaL_gsub = const(char)* function(lua_State* L, const(char)* s, const(char)* p, const(char)* r);
53     alias pluaL_findtable = const(char)* function(lua_State* L, int idx, const(char)* fname, int szhint);
54     alias pluaL_buffinit = void function(lua_State* L, luaL_Buffer* B);
55     alias pluaL_prepbuffer = char* function(luaL_Buffer* B);
56     alias pluaL_addlstring = void function(luaL_Buffer* B, const(char)* s, size_t l);
57     alias pluaL_addstring = void function(luaL_Buffer* B,  const(char)* s);
58     alias pluaL_addvalue = void function(luaL_Buffer* B);
59     alias pluaL_pushresult = void function(luaL_Buffer* B);
60 
61     // lua.h
62     alias plua_newstate = lua_State* function(lua_Alloc f,  void *ud);
63     alias plua_close = void function(lua_State* L);
64     alias plua_newthread = lua_State* function(lua_State* L);
65     alias plua_atpanic = lua_CFunction function(lua_State* L, lua_CFunction panicf);
66     alias plua_gettop = int function(lua_State* L);
67     alias plua_settop = void function(lua_State* L, int idx);
68     alias plua_pushvalue = void function(lua_State* L, int idx);
69     alias plua_remove = void function(lua_State* L, int idx);
70     alias plua_insert = void function(lua_State* L, int idx);
71     alias plua_replace = void function(lua_State* L, int idx);
72     alias plua_checkstack = int function(lua_State* L, int idx);
73     alias plua_xmove = void function(lua_State* L, lua_State*, int idx);
74     alias plua_isnumber = int function(lua_State* L, int idx);
75     alias plua_isstring = int function(lua_State* L, int idx);
76     alias plua_iscfunction = int function(lua_State* L, int idx);
77     alias plua_isuserdata = int function(lua_State* L, int idx);
78     alias plua_type = int function(lua_State* L, int idx);
79     alias plua_typename = const(char)* function(lua_State* L, int tp);
80     alias plua_equal = int function(lua_State* L, int idx1, int idx2);
81     alias plua_rawequal = int function(lua_State* L, int idx1, int idx2);
82     alias plua_lessthan = int function(lua_State* L, int idx1, int idx2);
83     alias plua_tonumber = lua_Number function(lua_State* L, int idx);
84     alias plua_tointeger = lua_Integer function(lua_State* L, int idx);
85     alias plua_toboolean = int function(lua_State* L, int idx);
86     alias plua_tolstring = const(char)* function(lua_State* L, int idx, size_t* len);
87     alias plua_objlen = size_t function(lua_State* L, int idx);
88     alias plua_tocfunction = lua_CFunction function(lua_State* L, int idx);
89     alias plua_touserdata = void* function(lua_State* L, int idx);
90     alias plua_tothread = lua_State* function(lua_State* L, int idx);
91     alias plua_topointer = const(void)* function(lua_State* L, int idx);
92     alias plua_pushnil = void function(lua_State* L);
93     alias plua_pushnumber = void function(lua_State* L, lua_Number n);
94     alias plua_pushinteger = void function(lua_State* L, lua_Integer n);
95     alias plua_pushlstring = void function(lua_State* L, const(char)* s, size_t l);
96     alias plua_pushstring = void function(lua_State* L, const(char)* s);
97     alias plua_pushvfstring = const(char)* function(lua_State* L, const(char)* fmt, va_list argp);
98     alias plua_pushfstring = const(char)* function(lua_State* L, const(char)* fmt, ...);
99     alias plua_pushcclosure = void function(lua_State* L, lua_CFunction fn, int n);
100     alias plua_pushboolean = void function(lua_State* L, int b);
101     alias plua_pushlightuserdata = void function(lua_State* L, void* p);
102     alias plua_pushthread = int function(lua_State* L);
103     alias plua_gettable = void function(lua_State* L, int idx);
104     alias plua_getfield = void function(lua_State* L, int idx, const(char)* k);
105     alias plua_rawget = void function(lua_State* L, int idx);
106     alias plua_rawgeti = void function(lua_State* L, int idx, int n);
107     alias plua_createtable = void function(lua_State* L, int narr, int nrec);
108     alias plua_newuserdata = void* function(lua_State* L, size_t sz);
109     alias plua_getmetatable = int function(lua_State* L, int objindex);
110     alias plua_getfenv = void function(lua_State* L, int idx);
111     alias plua_settable = void function(lua_State* L, int idx);
112     alias plua_setfield = void function(lua_State* L, int idx, const(char)* k);
113     alias plua_rawset = void function(lua_State* L, int idx);
114     alias plua_rawseti = void function(lua_State* L, int idx, int n);
115     alias plua_setmetatable = int function(lua_State* L, int objindex);
116     alias plua_setfenv = int function(lua_State* L, int idx);
117     alias plua_call = void function(lua_State* L, int nargs, int nresults);
118     alias plua_pcall = int function(lua_State* L, int nargs, int nresults, int errFunc);
119     alias plua_cpcall = int function(lua_State* L, lua_CFunction func, void* ud);
120     alias plua_load = int function(lua_State* L, lua_Reader reader, void* dt, const(char)* chunkname);
121     alias plua_dump = int function(lua_State* L, lua_Writer writer, void* data);
122     alias plua_yield = int function(lua_State* L, int nresults);
123     alias plua_resume = int function(lua_State* L, int nargs);
124     alias plua_status = int function(lua_State* L);
125     alias plua_gc = int function(lua_State* L, int what, int data);
126     alias plua_error = int function(lua_State* L);
127     alias plua_next = int function(lua_State* L, int idx);
128     alias plua_concat = void function(lua_State* L, int n);
129     alias plua_getallocf = lua_Alloc function(lua_State* L, void** ud);
130     alias plua_setallocf = void function(lua_State* L, lua_Alloc f, void* ud);
131     alias plua_setlevel = void function(lua_State* from,  lua_State* to);
132     alias plua_getstack = int function(lua_State* L, int level, lua_Debug* ar);
133     alias plua_getinfo = int function(lua_State* L, const(char)* what, lua_Debug* ar);
134     alias plua_getlocal = const(char)* function(lua_State* L, const(lua_Debug)* ar, int n);
135     alias plua_setlocal = const(char)* function(lua_State* L, const(lua_Debug)* ar, int n);
136     alias plua_getupvalue = const(char)* function(lua_State* L, int funcindex, int n);
137     alias plua_setupvalue = const(char)* function(lua_State* L, int funcindex, int n);
138     alias plua_sethook = int function(lua_State* L, lua_Hook func, int mask, int count);
139     alias plua_gethook = lua_Hook function(lua_State* L);
140     alias plua_gethookmask = int function(lua_State* L);
141     alias plua_gethookcount = int function(lua_State* L);
142 
143     // lualib.h
144     alias pluaopen_base = int function(lua_State* L);
145     alias pluaopen_table = int function(lua_State* L);
146     alias pluaopen_io = int function(lua_State* L);
147     alias pluaopen_os = int function(lua_State* L);
148     alias pluaopen_string = int function(lua_State* L);
149     alias pluaopen_math = int function(lua_State* L);
150     alias pluaopen_debug = int function(lua_State* L);
151     alias pluaopen_package = int function(lua_State* L);
152     alias pluaL_openlibs = void function(lua_State* L);
153 }
154 
155 __gshared {
156     // lauxlib.h
157     pluaI_openlib luaI_openlib;
158     pluaL_register luaL_register;
159     pluaL_getmetafield luaL_getmetafield;
160     pluaL_callmeta luaL_callmeta;
161     pluaL_typerror luaL_typerror;
162     pluaL_argerror luaL_argerror;
163     pluaL_checklstring luaL_checklstring;
164     pluaL_optlstring luaL_optlstring;
165     pluaL_checknumber luaL_checknumber;
166     pluaL_optnumber luaL_optnumber;
167     pluaL_checkinteger luaL_checkinteger;
168     pluaL_optinteger luaL_optinteger;
169     pluaL_checkstack luaL_checkstack;
170     pluaL_checktype luaL_checktype;
171     pluaL_checkany luaL_checkany;
172     pluaL_newmetatable luaL_newmetatable;
173     pluaL_checkudata luaL_checkudata;
174     pluaL_where luaL_where;
175     pluaL_error luaL_error;
176     pluaL_checkoption luaL_checkoption;
177     pluaL_ref luaL_ref;
178     pluaL_unref luaL_unref;
179     pluaL_loadfile luaL_loadfile;
180     pluaL_loadbuffer luaL_loadbuffer;
181     pluaL_loadstring luaL_loadstring;
182     pluaL_newstate luaL_newstate;
183     pluaL_gsub luaL_gsub;
184     pluaL_findtable luaL_findtable;
185     pluaL_buffinit luaL_buffinit;
186     pluaL_prepbuffer luaL_prepbuffer;
187     pluaL_addlstring luaL_addlstring;
188     pluaL_addstring luaL_addstring;
189     pluaL_addvalue luaL_addvalue;
190     pluaL_pushresult luaL_pushresult;
191 
192     // lua.h
193     plua_newstate lua_newstate;
194     plua_close lua_close;
195     plua_newthread lua_newthread;
196     plua_atpanic lua_atpanic;
197     plua_gettop lua_gettop;
198     plua_settop lua_settop;
199     plua_pushvalue lua_pushvalue;
200     plua_remove lua_remove;
201     plua_insert lua_insert;
202     plua_replace lua_replace;
203     plua_checkstack lua_checkstack;
204     plua_xmove lua_xmove;
205     plua_isnumber lua_isnumber;
206     plua_isstring lua_isstring;
207     plua_iscfunction lua_iscfunction;
208     plua_isuserdata lua_isuserdata;
209     plua_type lua_type;
210     plua_typename lua_typename;
211     plua_equal lua_equal;
212     plua_rawequal lua_rawequal;
213     plua_lessthan lua_lessthan;
214     plua_tonumber lua_tonumber;
215     plua_tointeger lua_tointeger;
216     plua_toboolean lua_toboolean;
217     plua_tolstring lua_tolstring;
218     plua_objlen lua_objlen;
219     plua_tocfunction lua_tocfunction;
220     plua_touserdata lua_touserdata;
221     plua_tothread lua_tothread;
222     plua_topointer lua_topointer;
223     plua_pushnil lua_pushnil;
224     plua_pushnumber lua_pushnumber;
225     plua_pushinteger lua_pushinteger;
226     plua_pushlstring lua_pushlstring;
227     plua_pushstring lua_pushstring;
228     plua_pushvfstring lua_pushvfstring;
229     plua_pushfstring lua_pushfstring;
230     plua_pushcclosure lua_pushcclosure;
231     plua_pushboolean lua_pushboolean;
232     plua_pushlightuserdata lua_pushlightuserdata;
233     plua_pushthread lua_pushthread;
234     plua_gettable lua_gettable;
235     plua_getfield lua_getfield;
236     plua_rawget lua_rawget;
237     plua_rawgeti lua_rawgeti;
238     plua_createtable lua_createtable;
239     plua_newuserdata lua_newuserdata;
240     plua_getmetatable lua_getmetatable;
241     plua_getfenv lua_getfenv;
242     plua_settable lua_settable;
243     plua_setfield lua_setfield;
244     plua_rawset lua_rawset;
245     plua_rawseti lua_rawseti;
246     plua_setmetatable lua_setmetatable;
247     plua_setfenv lua_setfenv;
248     plua_call lua_call;
249     plua_pcall lua_pcall;
250     plua_cpcall lua_cpcall;
251     plua_load lua_load;
252     plua_dump lua_dump;
253     plua_yield lua_yield;
254     plua_resume lua_resume;
255     plua_status lua_status;
256     plua_gc lua_gc;
257     plua_error lua_error;
258     plua_next lua_next;
259     plua_concat lua_concat;
260     plua_getallocf lua_getallocf;
261     plua_setallocf lua_setallocf;
262     plua_setlevel lua_setlevel;
263     plua_getstack lua_getstack;
264     plua_getinfo lua_getinfo;
265     plua_getlocal lua_getlocal;
266     plua_setlocal lua_setlocal;
267     plua_getupvalue lua_getupvalue;
268     plua_setupvalue lua_setupvalue;
269     plua_sethook lua_sethook;
270     plua_gethook lua_gethook;
271     plua_gethookmask lua_gethookmask;
272     plua_gethookcount lua_gethookcount;
273 
274     // lualib.h
275     pluaopen_base luaopen_base;
276     pluaopen_table luaopen_table;
277     pluaopen_io luaopen_io;
278     pluaopen_os luaopen_os;
279     pluaopen_string luaopen_string;
280     pluaopen_math luaopen_math;
281     pluaopen_debug luaopen_debug;
282     pluaopen_package luaopen_package;
283     pluaL_openlibs luaL_openlibs;
284 }
285 
286 private {
287     SharedLib lib;
288     LuaSupport loadedVersion;
289 }
290 
291 @nogc nothrow:
292 
293 void unloadLua()
294 {
295     if(lib != invalidHandle) {
296         lib.unload;
297     }
298 }
299 
300 LuaSupport loadedLuaVersion() @safe { return loadedVersion; }
301 bool isLuaLoaded() @safe { return lib != invalidHandle; }
302 
303 LuaSupport loadLua()
304 {
305     version(Windows) {
306         const(char)[][3] libNames = ["lua5.1.dll", "lua51.dll", "lua5.1.5.dll"];
307     }
308     else version(OSX) {
309         const(char)[][1] libNames = "liblua.5.1.dylib";
310     }
311     else version(Posix) {
312         const(char)[][3] libNames = ["liblua.so.5.1", "liblua5.1.so", "liblua-5.1.so"];
313     }
314     else static assert(0, "bindbc-lua support for Lua 5.1 is not implemented on this platform.");
315 
316     LuaSupport ret;
317     foreach(name; libNames) {
318         ret = loadLua(name.ptr);
319         if(ret != LuaSupport.noLibrary) break;
320     }
321     return ret;
322 }
323 
324 LuaSupport loadLua(const(char)* libName)
325 {
326     lib = load(libName);
327     if(lib == invalidHandle) {
328         return LuaSupport.noLibrary;
329     }
330 
331     auto errCount = errorCount();
332     loadedVersion = LuaSupport.badLibrary;
333 
334     // lauxlib.h
335     lib.bindSymbol(cast(void**)&luaI_openlib, "luaI_openlib");
336     lib.bindSymbol(cast(void**)&luaL_register, "luaL_register");
337     lib.bindSymbol(cast(void**)&luaL_getmetafield,"luaL_getmetafield");
338     lib.bindSymbol(cast(void**)&luaL_callmeta, "luaL_callmeta");
339     lib.bindSymbol(cast(void**)&luaL_typerror, "luaL_typerror");
340     lib.bindSymbol(cast(void**)&luaL_checklstring, "luaL_checklstring");
341     lib.bindSymbol(cast(void**)&luaL_argerror, "luaL_argerror");
342     lib.bindSymbol(cast(void**)&luaL_optlstring, "luaL_optlstring");
343     lib.bindSymbol(cast(void**)&luaL_checknumber, "luaL_checknumber");
344     lib.bindSymbol(cast(void**)&luaL_optnumber, "luaL_optnumber");
345     lib.bindSymbol(cast(void**)&luaL_checkinteger, "luaL_checkinteger");
346     lib.bindSymbol(cast(void**)&luaL_optinteger, "luaL_optinteger");
347     lib.bindSymbol(cast(void**)&luaL_checkstack, "luaL_checkstack");
348     lib.bindSymbol(cast(void**)&luaL_checktype, "luaL_checktype");
349     lib.bindSymbol(cast(void**)&luaL_checkany, "luaL_checkany");
350     lib.bindSymbol(cast(void**)&luaL_newmetatable, "luaL_newmetatable");
351     lib.bindSymbol(cast(void**)&luaL_checkudata, "luaL_checkudata");
352     lib.bindSymbol(cast(void**)&luaL_where, "luaL_where");
353     lib.bindSymbol(cast(void**)&luaL_error, "luaL_error");
354     lib.bindSymbol(cast(void**)&luaL_checkoption, "luaL_checkoption");
355     lib.bindSymbol(cast(void**)&luaL_ref, "luaL_ref");
356     lib.bindSymbol(cast(void**)&luaL_unref, "luaL_unref");
357     lib.bindSymbol(cast(void**)&luaL_loadfile, "luaL_loadfile");
358     lib.bindSymbol(cast(void**)&luaL_loadbuffer, "luaL_loadbuffer");
359     lib.bindSymbol(cast(void**)&luaL_loadstring, "luaL_loadstring");
360     lib.bindSymbol(cast(void**)&luaL_newstate, "luaL_newstate");
361     lib.bindSymbol(cast(void**)&luaL_gsub, "luaL_gsub");
362     lib.bindSymbol(cast(void**)&luaL_findtable, "luaL_findtable");
363 
364     lib.bindSymbol(cast(void**)&luaL_buffinit, "luaL_buffinit");
365     lib.bindSymbol(cast(void**)&luaL_prepbuffer, "luaL_prepbuffer");
366     lib.bindSymbol(cast(void**)&luaL_addlstring, "luaL_addlstring");
367     lib.bindSymbol(cast(void**)&luaL_addstring, "luaL_addstring");
368     lib.bindSymbol(cast(void**)&luaL_addvalue, "luaL_addvalue");
369     lib.bindSymbol(cast(void**)&luaL_pushresult, "luaL_pushresult");
370 
371     // lua.h
372     lib.bindSymbol(cast(void**)&lua_newstate, "lua_newstate");
373     lib.bindSymbol(cast(void**)&lua_close, "lua_close");
374     lib.bindSymbol(cast(void**)&lua_newthread, "lua_newthread");
375     lib.bindSymbol(cast(void**)&lua_atpanic, "lua_atpanic");
376     lib.bindSymbol(cast(void**)&lua_gettop, "lua_gettop");
377     lib.bindSymbol(cast(void**)&lua_settop, "lua_settop");
378     lib.bindSymbol(cast(void**)&lua_pushvalue, "lua_pushvalue");
379     lib.bindSymbol(cast(void**)&lua_remove, "lua_remove");
380     lib.bindSymbol(cast(void**)&lua_insert, "lua_insert");
381     lib.bindSymbol(cast(void**)&lua_replace, "lua_replace");
382     lib.bindSymbol(cast(void**)&lua_checkstack, "lua_checkstack");
383     lib.bindSymbol(cast(void**)&lua_xmove, "lua_xmove");
384     lib.bindSymbol(cast(void**)&lua_isnumber, "lua_isnumber");
385     lib.bindSymbol(cast(void**)&lua_isstring, "lua_isstring");
386     lib.bindSymbol(cast(void**)&lua_iscfunction, "lua_iscfunction");
387     lib.bindSymbol(cast(void**)&lua_isuserdata, "lua_isuserdata");
388     lib.bindSymbol(cast(void**)&lua_type, "lua_type");
389     lib.bindSymbol(cast(void**)&lua_typename, "lua_typename");
390     lib.bindSymbol(cast(void**)&lua_equal, "lua_equal");
391     lib.bindSymbol(cast(void**)&lua_rawequal, "lua_rawequal");
392     lib.bindSymbol(cast(void**)&lua_lessthan, "lua_lessthan");
393     lib.bindSymbol(cast(void**)&lua_tonumber, "lua_tonumber");
394     lib.bindSymbol(cast(void**)&lua_tointeger, "lua_tointeger");
395     lib.bindSymbol(cast(void**)&lua_toboolean, "lua_toboolean");
396     lib.bindSymbol(cast(void**)&lua_tolstring, "lua_tolstring");
397     lib.bindSymbol(cast(void**)&lua_objlen, "lua_objlen");
398     lib.bindSymbol(cast(void**)&lua_tocfunction, "lua_tocfunction");
399     lib.bindSymbol(cast(void**)&lua_touserdata, "lua_touserdata");
400     lib.bindSymbol(cast(void**)&lua_tothread, "lua_tothread");
401     lib.bindSymbol(cast(void**)&lua_topointer, "lua_topointer");
402     lib.bindSymbol(cast(void**)&lua_pushnil, "lua_pushnil");
403     lib.bindSymbol(cast(void**)&lua_pushnumber, "lua_pushnumber");
404     lib.bindSymbol(cast(void**)&lua_pushinteger, "lua_pushinteger");
405     lib.bindSymbol(cast(void**)&lua_pushlstring, "lua_pushlstring");
406     lib.bindSymbol(cast(void**)&lua_pushstring, "lua_pushstring");
407     lib.bindSymbol(cast(void**)&lua_pushvfstring, "lua_pushvfstring");
408     lib.bindSymbol(cast(void**)&lua_pushfstring, "lua_pushfstring");
409     lib.bindSymbol(cast(void**)&lua_pushcclosure, "lua_pushcclosure");
410     lib.bindSymbol(cast(void**)&lua_pushboolean, "lua_pushboolean");
411     lib.bindSymbol(cast(void**)&lua_pushlightuserdata, "lua_pushlightuserdata");
412     lib.bindSymbol(cast(void**)&lua_pushthread, "lua_pushthread");
413     lib.bindSymbol(cast(void**)&lua_gettable, "lua_gettable");
414     lib.bindSymbol(cast(void**)&lua_getfield, "lua_getfield");
415     lib.bindSymbol(cast(void**)&lua_rawget, "lua_rawget");
416     lib.bindSymbol(cast(void**)&lua_rawgeti, "lua_rawgeti");
417     lib.bindSymbol(cast(void**)&lua_createtable, "lua_createtable");
418     lib.bindSymbol(cast(void**)&lua_newuserdata, "lua_newuserdata");
419     lib.bindSymbol(cast(void**)&lua_getmetatable, "lua_getmetatable");
420     lib.bindSymbol(cast(void**)&lua_getfenv, "lua_getfenv");
421     lib.bindSymbol(cast(void**)&lua_settable, "lua_settable");
422     lib.bindSymbol(cast(void**)&lua_setfield, "lua_setfield");
423     lib.bindSymbol(cast(void**)&lua_rawset, "lua_rawset");
424     lib.bindSymbol(cast(void**)&lua_rawseti, "lua_rawseti");
425     lib.bindSymbol(cast(void**)&lua_setmetatable, "lua_setmetatable");
426     lib.bindSymbol(cast(void**)&lua_setfenv, "lua_setfenv");
427     lib.bindSymbol(cast(void**)&lua_call, "lua_call");
428     lib.bindSymbol(cast(void**)&lua_pcall, "lua_pcall");
429     lib.bindSymbol(cast(void**)&lua_cpcall, "lua_cpcall");
430     lib.bindSymbol(cast(void**)&lua_load, "lua_load");
431     lib.bindSymbol(cast(void**)&lua_dump, "lua_dump");
432     lib.bindSymbol(cast(void**)&lua_yield, "lua_yield");
433     lib.bindSymbol(cast(void**)&lua_resume, "lua_resume");
434     lib.bindSymbol(cast(void**)&lua_status, "lua_status");
435     lib.bindSymbol(cast(void**)&lua_gc, "lua_gc");
436     lib.bindSymbol(cast(void**)&lua_error, "lua_error");
437     lib.bindSymbol(cast(void**)&lua_next, "lua_next");
438     lib.bindSymbol(cast(void**)&lua_concat, "lua_concat");
439     lib.bindSymbol(cast(void**)&lua_getallocf, "lua_getallocf");
440     lib.bindSymbol(cast(void**)&lua_setallocf, "lua_setallocf");
441     lib.bindSymbol(cast(void**)&lua_setlevel, "lua_setlevel");
442     lib.bindSymbol(cast(void**)&lua_getstack, "lua_getstack");
443     lib.bindSymbol(cast(void**)&lua_getinfo, "lua_getinfo");
444     lib.bindSymbol(cast(void**)&lua_getlocal, "lua_getlocal");
445     lib.bindSymbol(cast(void**)&lua_setlocal, "lua_setlocal");
446     lib.bindSymbol(cast(void**)&lua_getupvalue, "lua_getupvalue");
447     lib.bindSymbol(cast(void**)&lua_setupvalue, "lua_setupvalue");
448     lib.bindSymbol(cast(void**)&lua_sethook, "lua_sethook");
449     lib.bindSymbol(cast(void**)&lua_gethook, "lua_gethook");
450     lib.bindSymbol(cast(void**)&lua_gethookmask, "lua_gethookmask");
451     lib.bindSymbol(cast(void**)&lua_gethookcount, "lua_gethookcount");
452 
453     // lualib.h
454     lib.bindSymbol(cast(void**)&luaopen_base, "luaopen_base");
455     lib.bindSymbol(cast(void**)&luaopen_table, "luaopen_table");
456     lib.bindSymbol(cast(void**)&luaopen_io, "luaopen_io");
457     lib.bindSymbol(cast(void**)&luaopen_os, "luaopen_os");
458     lib.bindSymbol(cast(void**)&luaopen_string, "luaopen_string");
459     lib.bindSymbol(cast(void**)&luaopen_math, "luaopen_math");
460     lib.bindSymbol(cast(void**)&luaopen_debug, "luaopen_debug");
461     lib.bindSymbol(cast(void**)&luaopen_package, "luaopen_package");
462     lib.bindSymbol(cast(void**)&luaL_openlibs, "luaL_openlibs");
463 
464     return LuaSupport.lua51;
465 }