├── .gitignore ├── .npmignore ├── LICENSE.md ├── README.md ├── binding.gyp ├── examples ├── lua_require │ ├── file.lua │ ├── index.js │ └── lua │ │ └── another.lua └── simple │ ├── index.js │ └── test.lua ├── index.js ├── maclualib ├── include │ ├── lauxlib.h │ ├── lua.h │ ├── lua.hpp │ ├── luaconf.h │ └── lualib.h └── lib │ └── liblua.a ├── package.json ├── src ├── luastate.cc ├── luastate.h ├── nodelua.cc ├── utils.cc └── utils.h └── win64luajit ├── lauxlib.h ├── lua.h ├── lua.hpp ├── lua51.dll ├── lua51.lib ├── luaconf.h ├── luajit.h └── lualib.h /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | node_modules/ 3 | npm-debug.log 4 | yarn-error.log 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | build 2 | /node_modules 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | ## License & Copyrights 3 | 4 | #### The ISC Licence (ISC) Copyright (c) 2017, Medaeus245 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Node-lua binding 2 | 3 | ## Installation 4 | 5 | `npm install node-lua` 6 | 7 | ## About 8 | 9 | 10 | Using Lua5.1 C interface: https://www.lua.org/manual/5.1/manual.html with luajit compiler 11 | 12 | **Based on:** 13 | - nodelua ( https://github.com/brettlangdon/NodeLua ) 14 | - node-luajit ( https://github.com/whtiehack/node-luajit ) 15 | 16 | 17 | **Features:** 18 | - Low-Level API 19 | - For now Sync only 20 | 21 | 22 | **Compilation:** 23 | - On Windows and Mac : Luajit library already included in the package 24 | - On Linux: Compilation with following parameters: 25 | - Include directory: (find /usr/include /usr/local/include $NODELUA_INCLUDE -name lua.h | sed s/lua.h//) 26 | - Library directory: "/usr/local/lib" 27 | - Library: "/usr/local/lib/libluajit-5.1.so" 28 | 29 | NOTE (Linux only): Don't forget to set your LD_LIBRARY_PATH to /usr/local/lib so that node-lua can find luajit. 30 | 31 | **Tested on:** 32 | - Windows (Node v6.10.2) 33 | - Linux (Node v4.2.6 & v.7.10.0) 34 | 35 | 36 | ## Examples 37 | 38 | - [Simple](https://github.com/medaeus245/node-lua/blob/master/examples/simple/index.js) 39 | - [Using lua require function](https://github.com/medaeus245/node-lua/blob/master/examples/lua_require/index.js) 40 | 41 | 42 | 43 | ## API 44 | 45 | 46 | ```javascript 47 | 48 | const nodelua = require('node-lua'); 49 | 50 | var lua = new nodelua.LuaState(); 51 | 52 | 53 | /** 54 | * [Add a path to the lua package.path variable. Set a root path for lua require (see example)] 55 | * @param {String} path 56 | */ 57 | lua.AddPackagePath(__dirname); 58 | 59 | 60 | /** 61 | * [Loads and runs the given file] 62 | * @type {String} file 63 | * @throws {Exception} 64 | */ 65 | lua.DoFile(__dirname + "/test.lua"); 66 | 67 | 68 | /** 69 | * [Loads and runs the given string] 70 | * @type {String} str 71 | * @throws {Exception} 72 | */ 73 | lua.DoString("print('Hello world!')"); 74 | 75 | 76 | /** 77 | * [Sets the function f as the new value of global name] 78 | * @param {String} name [name of the global in lua] 79 | * @param {Function} f [function to set] 80 | */ 81 | lua.RegisterFunction('add', function() { 82 | var a = lua.ToValue(1); 83 | var b = lua.ToValue(2); 84 | lua.Pop(2); 85 | lua.Push(a + b); 86 | return 1; 87 | }); 88 | 89 | 90 | /** 91 | * [Pops a value from the stack and sets it as the new value of global name] 92 | * @type {String} name 93 | */ 94 | lua.SetGlobal("myVar"); 95 | 96 | 97 | /** 98 | * [Pushes onto the stack the value of the global name] 99 | * @type {String} name 100 | */ 101 | lua.GetGlobal('myVar'); 102 | 103 | 104 | /** 105 | * [Does the equivalent to t[k] = v, where t is the value at the given valid index and v is the value at the top of the stack. This function pops the value from the stack.] 106 | * @type {Number} index 107 | * @type {String} key 108 | */ 109 | lua.SetField(index, "t"); 110 | 111 | 112 | /** 113 | * [Pushes onto the stack the value t[key], where t is the value at the given valid index.] 114 | * @type {Number} index 115 | * @type {String} key 116 | */ 117 | lua.GetField(index, "t"); 118 | 119 | 120 | /** 121 | * [Get value at the given acceptable index] 122 | * @type {Number} index 123 | * @return value 124 | */ 125 | var value = lua.ToValue(-1); 126 | 127 | 128 | /** 129 | * [Calls a function. Gets the function and arguments from the stack. Pushes the results onto the stack. See https://www.lua.org/manual/5.1/manual.html#pdf-pcall for more information] 130 | * @type {Number} args 131 | * @type {Number} results 132 | * @throws {Exception} 133 | */ 134 | lua.Call(args, results); 135 | 136 | 137 | /** 138 | * [Yields a coroutine.] 139 | * @type {Number} args 140 | */ 141 | lua.Yield(args); 142 | 143 | 144 | /** 145 | * [Starts and resumes a coroutine in a given thread.] 146 | * @type {Number} args 147 | */ 148 | lua.Resume(args); 149 | 150 | 151 | /** 152 | * [Pushes a value n onto the stack] 153 | * @type n 154 | */ 155 | lua.Push(5); 156 | 157 | 158 | /** 159 | * [Pops n elements from the stack. Default value is 1] 160 | * @type {Number} n 161 | */ 162 | lua.Pop(); 163 | lua.Pop(n); 164 | 165 | 166 | /** 167 | * [Returns the index of the top element in the stack. Because indices start at 1, this result is equal to the number of elements in the stack (and so 0 means an empty stack)] 168 | * @return {Number} 169 | */ 170 | var size = lua.GetTop(); 171 | 172 | 173 | /** 174 | * [Accepts any acceptable index, or 0, and sets the stack top to this index. If the new top is larger than the old one, then the new elements are filled with nil. If index is 0, then all stack elements are removed] 175 | * @type {Number} index 176 | */ 177 | lua.SetTop(index); 178 | 179 | 180 | /** 181 | * [Moves the top element into the given position (and pops it), without shifting any element (therefore replacing the value at the given position)] 182 | * @type {Number} index 183 | */ 184 | lua.Replace(index); 185 | 186 | 187 | ``` 188 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "nodelua", 5 | "variables": { 6 | "lua_include": "", 7 | "lib_dirs": "" 8 | }, 9 | "conditions": [ 10 | [ 11 | "OS=='win'", 12 | { 13 | "include_dirs": [ 14 | "./win64luajit" 15 | ], 16 | "library_dirs": [ 17 | "./win64luajit" 18 | ], 19 | "libraries": [ 20 | "lua51.lib" 21 | ], 22 | "actions": [ 23 | { 24 | 'action_name': 'move_lua', 25 | 'inputs': [ 26 | '<(module_root_dir)/win64luajit/lua51.dll' 27 | ], 28 | 'outputs': [ 29 | '<(module_root_dir)/build/Release/lua51.dll' 30 | ], 31 | 'action': [ 32 | 'cp', 33 | '<(module_root_dir)/win64luajit/lua51.dll', 34 | '<(module_root_dir)/build/Release/lua51.dll' 35 | ] 36 | } 37 | ], 38 | } 39 | ], 40 | [ 41 | 'OS=="mac"', 42 | { 43 | "include_dirs": [ 44 | "./maclualib/include" 45 | ], 46 | "libraries": [ 47 | "../maclualib/lib/liblua.a" 48 | ], 49 | "actions": [], 50 | "cflags": [ 51 | "-std=c++11", 52 | "-stdlib=libc++" 53 | ], 54 | "xcode_settings": { 55 | "CLANG_CXX_LANGUAGE_STANDARD": "c++0x", 56 | "CLANG_CXX_LIBRARY": "libc++" 57 | } 58 | } 59 | ], 60 | [ 61 | 'OS=="linux"', 62 | { 63 | "include_dirs": [ 64 | " 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | 18 | #if defined(LUA_COMPAT_GETN) 19 | LUALIB_API int (luaL_getn) (lua_State *L, int t); 20 | LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); 21 | #else 22 | #define luaL_getn(L,i) ((int)lua_objlen(L, i)) 23 | #define luaL_setn(L,i,j) ((void)0) /* no op! */ 24 | #endif 25 | 26 | #if defined(LUA_COMPAT_OPENLIB) 27 | #define luaI_openlib luaL_openlib 28 | #endif 29 | 30 | 31 | /* extra error code for `luaL_load' */ 32 | #define LUA_ERRFILE (LUA_ERRERR+1) 33 | 34 | 35 | typedef struct luaL_Reg { 36 | const char *name; 37 | lua_CFunction func; 38 | } luaL_Reg; 39 | 40 | 41 | 42 | LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, 43 | const luaL_Reg *l, int nup); 44 | LUALIB_API void (luaL_register) (lua_State *L, const char *libname, 45 | const luaL_Reg *l); 46 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 47 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 48 | LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); 49 | LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); 50 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, 51 | size_t *l); 52 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, 53 | const char *def, size_t *l); 54 | LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); 55 | LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); 56 | 57 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); 58 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, 59 | lua_Integer def); 60 | 61 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 62 | LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); 63 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); 64 | 65 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); 66 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); 67 | 68 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); 69 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); 70 | 71 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, 72 | const char *const lst[]); 73 | 74 | LUALIB_API int (luaL_ref) (lua_State *L, int t); 75 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); 76 | 77 | LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); 78 | LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, 79 | const char *name); 80 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); 81 | 82 | LUALIB_API lua_State *(luaL_newstate) (void); 83 | 84 | 85 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, 86 | const char *r); 87 | 88 | LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, 89 | const char *fname, int szhint); 90 | 91 | 92 | 93 | 94 | /* 95 | ** =============================================================== 96 | ** some useful macros 97 | ** =============================================================== 98 | */ 99 | 100 | #define luaL_argcheck(L, cond,numarg,extramsg) \ 101 | ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) 102 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 103 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 104 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) 105 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) 106 | #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) 107 | #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) 108 | 109 | #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) 110 | 111 | #define luaL_dofile(L, fn) \ 112 | (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 113 | 114 | #define luaL_dostring(L, s) \ 115 | (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 116 | 117 | #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) 118 | 119 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) 120 | 121 | /* 122 | ** {====================================================== 123 | ** Generic Buffer manipulation 124 | ** ======================================================= 125 | */ 126 | 127 | 128 | 129 | typedef struct luaL_Buffer { 130 | char *p; /* current position in buffer */ 131 | int lvl; /* number of strings in the stack (level) */ 132 | lua_State *L; 133 | char buffer[LUAL_BUFFERSIZE]; 134 | } luaL_Buffer; 135 | 136 | #define luaL_addchar(B,c) \ 137 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ 138 | (*(B)->p++ = (char)(c))) 139 | 140 | /* compatibility only */ 141 | #define luaL_putchar(B,c) luaL_addchar(B,c) 142 | 143 | #define luaL_addsize(B,n) ((B)->p += (n)) 144 | 145 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); 146 | LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); 147 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); 148 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); 149 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); 150 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); 151 | 152 | 153 | /* }====================================================== */ 154 | 155 | 156 | /* compatibility with ref system */ 157 | 158 | /* pre-defined references */ 159 | #define LUA_NOREF (-2) 160 | #define LUA_REFNIL (-1) 161 | 162 | #define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ 163 | (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) 164 | 165 | #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) 166 | 167 | #define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) 168 | 169 | 170 | #define luaL_reg luaL_Reg 171 | 172 | #endif 173 | 174 | 175 | -------------------------------------------------------------------------------- /maclualib/include/lua.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lua.h,v 1.218.1.7 2012/01/13 20:36:20 roberto Exp $ 3 | ** Lua - An Extensible Extension Language 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 5 | ** See Copyright Notice at the end of this file 6 | */ 7 | 8 | 9 | #ifndef lua_h 10 | #define lua_h 11 | 12 | #include 13 | #include 14 | 15 | 16 | #include "luaconf.h" 17 | 18 | 19 | #define LUA_VERSION "Lua 5.1" 20 | #define LUA_RELEASE "Lua 5.1.5" 21 | #define LUA_VERSION_NUM 501 22 | #define LUA_COPYRIGHT "Copyright (C) 1994-2012 Lua.org, PUC-Rio" 23 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" 24 | 25 | 26 | /* mark for precompiled code (`Lua') */ 27 | #define LUA_SIGNATURE "\033Lua" 28 | 29 | /* option for multiple returns in `lua_pcall' and `lua_call' */ 30 | #define LUA_MULTRET (-1) 31 | 32 | 33 | /* 34 | ** pseudo-indices 35 | */ 36 | #define LUA_REGISTRYINDEX (-10000) 37 | #define LUA_ENVIRONINDEX (-10001) 38 | #define LUA_GLOBALSINDEX (-10002) 39 | #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) 40 | 41 | 42 | /* thread status; 0 is OK */ 43 | #define LUA_YIELD 1 44 | #define LUA_ERRRUN 2 45 | #define LUA_ERRSYNTAX 3 46 | #define LUA_ERRMEM 4 47 | #define LUA_ERRERR 5 48 | 49 | 50 | typedef struct lua_State lua_State; 51 | 52 | typedef int (*lua_CFunction) (lua_State *L); 53 | 54 | 55 | /* 56 | ** functions that read/write blocks when loading/dumping Lua chunks 57 | */ 58 | typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); 59 | 60 | typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); 61 | 62 | 63 | /* 64 | ** prototype for memory-allocation functions 65 | */ 66 | typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); 67 | 68 | 69 | /* 70 | ** basic types 71 | */ 72 | #define LUA_TNONE (-1) 73 | 74 | #define LUA_TNIL 0 75 | #define LUA_TBOOLEAN 1 76 | #define LUA_TLIGHTUSERDATA 2 77 | #define LUA_TNUMBER 3 78 | #define LUA_TSTRING 4 79 | #define LUA_TTABLE 5 80 | #define LUA_TFUNCTION 6 81 | #define LUA_TUSERDATA 7 82 | #define LUA_TTHREAD 8 83 | 84 | 85 | 86 | /* minimum Lua stack available to a C function */ 87 | #define LUA_MINSTACK 20 88 | 89 | 90 | /* 91 | ** generic extra include file 92 | */ 93 | #if defined(LUA_USER_H) 94 | #include LUA_USER_H 95 | #endif 96 | 97 | 98 | /* type of numbers in Lua */ 99 | typedef LUA_NUMBER lua_Number; 100 | 101 | 102 | /* type for integer functions */ 103 | typedef LUA_INTEGER lua_Integer; 104 | 105 | 106 | 107 | /* 108 | ** state manipulation 109 | */ 110 | LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); 111 | LUA_API void (lua_close) (lua_State *L); 112 | LUA_API lua_State *(lua_newthread) (lua_State *L); 113 | 114 | LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); 115 | 116 | 117 | /* 118 | ** basic stack manipulation 119 | */ 120 | LUA_API int (lua_gettop) (lua_State *L); 121 | LUA_API void (lua_settop) (lua_State *L, int idx); 122 | LUA_API void (lua_pushvalue) (lua_State *L, int idx); 123 | LUA_API void (lua_remove) (lua_State *L, int idx); 124 | LUA_API void (lua_insert) (lua_State *L, int idx); 125 | LUA_API void (lua_replace) (lua_State *L, int idx); 126 | LUA_API int (lua_checkstack) (lua_State *L, int sz); 127 | 128 | LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); 129 | 130 | 131 | /* 132 | ** access functions (stack -> C) 133 | */ 134 | 135 | LUA_API int (lua_isnumber) (lua_State *L, int idx); 136 | LUA_API int (lua_isstring) (lua_State *L, int idx); 137 | LUA_API int (lua_iscfunction) (lua_State *L, int idx); 138 | LUA_API int (lua_isuserdata) (lua_State *L, int idx); 139 | LUA_API int (lua_type) (lua_State *L, int idx); 140 | LUA_API const char *(lua_typename) (lua_State *L, int tp); 141 | 142 | LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); 143 | LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); 144 | LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); 145 | 146 | LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); 147 | LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); 148 | LUA_API int (lua_toboolean) (lua_State *L, int idx); 149 | LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); 150 | LUA_API size_t (lua_objlen) (lua_State *L, int idx); 151 | LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); 152 | LUA_API void *(lua_touserdata) (lua_State *L, int idx); 153 | LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); 154 | LUA_API const void *(lua_topointer) (lua_State *L, int idx); 155 | 156 | 157 | /* 158 | ** push functions (C -> stack) 159 | */ 160 | LUA_API void (lua_pushnil) (lua_State *L); 161 | LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); 162 | LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); 163 | LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); 164 | LUA_API void (lua_pushstring) (lua_State *L, const char *s); 165 | LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, 166 | va_list argp); 167 | LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); 168 | LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); 169 | LUA_API void (lua_pushboolean) (lua_State *L, int b); 170 | LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); 171 | LUA_API int (lua_pushthread) (lua_State *L); 172 | 173 | 174 | /* 175 | ** get functions (Lua -> stack) 176 | */ 177 | LUA_API void (lua_gettable) (lua_State *L, int idx); 178 | LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); 179 | LUA_API void (lua_rawget) (lua_State *L, int idx); 180 | LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); 181 | LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); 182 | LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); 183 | LUA_API int (lua_getmetatable) (lua_State *L, int objindex); 184 | LUA_API void (lua_getfenv) (lua_State *L, int idx); 185 | 186 | 187 | /* 188 | ** set functions (stack -> Lua) 189 | */ 190 | LUA_API void (lua_settable) (lua_State *L, int idx); 191 | LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); 192 | LUA_API void (lua_rawset) (lua_State *L, int idx); 193 | LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); 194 | LUA_API int (lua_setmetatable) (lua_State *L, int objindex); 195 | LUA_API int (lua_setfenv) (lua_State *L, int idx); 196 | 197 | 198 | /* 199 | ** `load' and `call' functions (load and run Lua code) 200 | */ 201 | LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); 202 | LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); 203 | LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); 204 | LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, 205 | const char *chunkname); 206 | 207 | LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); 208 | 209 | 210 | /* 211 | ** coroutine functions 212 | */ 213 | LUA_API int (lua_yield) (lua_State *L, int nresults); 214 | LUA_API int (lua_resume) (lua_State *L, int narg); 215 | LUA_API int (lua_status) (lua_State *L); 216 | 217 | /* 218 | ** garbage-collection function and options 219 | */ 220 | 221 | #define LUA_GCSTOP 0 222 | #define LUA_GCRESTART 1 223 | #define LUA_GCCOLLECT 2 224 | #define LUA_GCCOUNT 3 225 | #define LUA_GCCOUNTB 4 226 | #define LUA_GCSTEP 5 227 | #define LUA_GCSETPAUSE 6 228 | #define LUA_GCSETSTEPMUL 7 229 | 230 | LUA_API int (lua_gc) (lua_State *L, int what, int data); 231 | 232 | 233 | /* 234 | ** miscellaneous functions 235 | */ 236 | 237 | LUA_API int (lua_error) (lua_State *L); 238 | 239 | LUA_API int (lua_next) (lua_State *L, int idx); 240 | 241 | LUA_API void (lua_concat) (lua_State *L, int n); 242 | 243 | LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); 244 | LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); 245 | 246 | 247 | 248 | /* 249 | ** =============================================================== 250 | ** some useful macros 251 | ** =============================================================== 252 | */ 253 | 254 | #define lua_pop(L,n) lua_settop(L, -(n)-1) 255 | 256 | #define lua_newtable(L) lua_createtable(L, 0, 0) 257 | 258 | #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) 259 | 260 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) 261 | 262 | #define lua_strlen(L,i) lua_objlen(L, (i)) 263 | 264 | #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) 265 | #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) 266 | #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) 267 | #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) 268 | #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) 269 | #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) 270 | #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) 271 | #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) 272 | 273 | #define lua_pushliteral(L, s) \ 274 | lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) 275 | 276 | #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) 277 | #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) 278 | 279 | #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) 280 | 281 | 282 | 283 | /* 284 | ** compatibility macros and functions 285 | */ 286 | 287 | #define lua_open() luaL_newstate() 288 | 289 | #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) 290 | 291 | #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) 292 | 293 | #define lua_Chunkreader lua_Reader 294 | #define lua_Chunkwriter lua_Writer 295 | 296 | 297 | /* hack */ 298 | LUA_API void lua_setlevel (lua_State *from, lua_State *to); 299 | 300 | 301 | /* 302 | ** {====================================================================== 303 | ** Debug API 304 | ** ======================================================================= 305 | */ 306 | 307 | 308 | /* 309 | ** Event codes 310 | */ 311 | #define LUA_HOOKCALL 0 312 | #define LUA_HOOKRET 1 313 | #define LUA_HOOKLINE 2 314 | #define LUA_HOOKCOUNT 3 315 | #define LUA_HOOKTAILRET 4 316 | 317 | 318 | /* 319 | ** Event masks 320 | */ 321 | #define LUA_MASKCALL (1 << LUA_HOOKCALL) 322 | #define LUA_MASKRET (1 << LUA_HOOKRET) 323 | #define LUA_MASKLINE (1 << LUA_HOOKLINE) 324 | #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) 325 | 326 | typedef struct lua_Debug lua_Debug; /* activation record */ 327 | 328 | 329 | /* Functions to be called by the debuger in specific events */ 330 | typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); 331 | 332 | 333 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); 334 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); 335 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); 336 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); 337 | LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); 338 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); 339 | 340 | LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); 341 | LUA_API lua_Hook lua_gethook (lua_State *L); 342 | LUA_API int lua_gethookmask (lua_State *L); 343 | LUA_API int lua_gethookcount (lua_State *L); 344 | 345 | 346 | struct lua_Debug { 347 | int event; 348 | const char *name; /* (n) */ 349 | const char *namewhat; /* (n) `global', `local', `field', `method' */ 350 | const char *what; /* (S) `Lua', `C', `main', `tail' */ 351 | const char *source; /* (S) */ 352 | int currentline; /* (l) */ 353 | int nups; /* (u) number of upvalues */ 354 | int linedefined; /* (S) */ 355 | int lastlinedefined; /* (S) */ 356 | char short_src[LUA_IDSIZE]; /* (S) */ 357 | /* private part */ 358 | int i_ci; /* active function */ 359 | }; 360 | 361 | /* }====================================================================== */ 362 | 363 | 364 | /****************************************************************************** 365 | * Copyright (C) 1994-2012 Lua.org, PUC-Rio. All rights reserved. 366 | * 367 | * Permission is hereby granted, free of charge, to any person obtaining 368 | * a copy of this software and associated documentation files (the 369 | * "Software"), to deal in the Software without restriction, including 370 | * without limitation the rights to use, copy, modify, merge, publish, 371 | * distribute, sublicense, and/or sell copies of the Software, and to 372 | * permit persons to whom the Software is furnished to do so, subject to 373 | * the following conditions: 374 | * 375 | * The above copyright notice and this permission notice shall be 376 | * included in all copies or substantial portions of the Software. 377 | * 378 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 379 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 380 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 381 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 382 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 383 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 384 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 385 | ******************************************************************************/ 386 | 387 | 388 | #endif 389 | -------------------------------------------------------------------------------- /maclualib/include/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /maclualib/include/luaconf.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $ 3 | ** Configuration file for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lconfig_h 9 | #define lconfig_h 10 | 11 | #include 12 | #include 13 | 14 | 15 | /* 16 | ** ================================================================== 17 | ** Search for "@@" to find all configurable definitions. 18 | ** =================================================================== 19 | */ 20 | 21 | 22 | /* 23 | @@ LUA_ANSI controls the use of non-ansi features. 24 | ** CHANGE it (define it) if you want Lua to avoid the use of any 25 | ** non-ansi feature or library. 26 | */ 27 | #if defined(__STRICT_ANSI__) 28 | #define LUA_ANSI 29 | #endif 30 | 31 | 32 | #if !defined(LUA_ANSI) && defined(_WIN32) 33 | #define LUA_WIN 34 | #endif 35 | 36 | #if defined(LUA_USE_LINUX) 37 | #define LUA_USE_POSIX 38 | #define LUA_USE_DLOPEN /* needs an extra library: -ldl */ 39 | #define LUA_USE_READLINE /* needs some extra libraries */ 40 | #endif 41 | 42 | #if defined(LUA_USE_MACOSX) 43 | #define LUA_USE_POSIX 44 | #define LUA_DL_DYLD /* does not need extra library */ 45 | #endif 46 | 47 | 48 | 49 | /* 50 | @@ LUA_USE_POSIX includes all functionallity listed as X/Open System 51 | @* Interfaces Extension (XSI). 52 | ** CHANGE it (define it) if your system is XSI compatible. 53 | */ 54 | #if defined(LUA_USE_POSIX) 55 | #define LUA_USE_MKSTEMP 56 | #define LUA_USE_ISATTY 57 | #define LUA_USE_POPEN 58 | #define LUA_USE_ULONGJMP 59 | #endif 60 | 61 | 62 | /* 63 | @@ LUA_PATH and LUA_CPATH are the names of the environment variables that 64 | @* Lua check to set its paths. 65 | @@ LUA_INIT is the name of the environment variable that Lua 66 | @* checks for initialization code. 67 | ** CHANGE them if you want different names. 68 | */ 69 | #define LUA_PATH "LUA_PATH" 70 | #define LUA_CPATH "LUA_CPATH" 71 | #define LUA_INIT "LUA_INIT" 72 | 73 | 74 | /* 75 | @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for 76 | @* Lua libraries. 77 | @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for 78 | @* C libraries. 79 | ** CHANGE them if your machine has a non-conventional directory 80 | ** hierarchy or if you want to install your libraries in 81 | ** non-conventional directories. 82 | */ 83 | #if defined(_WIN32) 84 | /* 85 | ** In Windows, any exclamation mark ('!') in the path is replaced by the 86 | ** path of the directory of the executable file of the current process. 87 | */ 88 | #define LUA_LDIR "!\\lua\\" 89 | #define LUA_CDIR "!\\" 90 | #define LUA_PATH_DEFAULT \ 91 | ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ 92 | LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua" 93 | #define LUA_CPATH_DEFAULT \ 94 | ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" 95 | 96 | #else 97 | #define LUA_ROOT "/usr/local/" 98 | #define LUA_LDIR LUA_ROOT "share/lua/5.1/" 99 | #define LUA_CDIR LUA_ROOT "lib/lua/5.1/" 100 | #define LUA_PATH_DEFAULT \ 101 | "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ 102 | LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua" 103 | #define LUA_CPATH_DEFAULT \ 104 | "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so" 105 | #endif 106 | 107 | 108 | /* 109 | @@ LUA_DIRSEP is the directory separator (for submodules). 110 | ** CHANGE it if your machine does not use "/" as the directory separator 111 | ** and is not Windows. (On Windows Lua automatically uses "\".) 112 | */ 113 | #if defined(_WIN32) 114 | #define LUA_DIRSEP "\\" 115 | #else 116 | #define LUA_DIRSEP "/" 117 | #endif 118 | 119 | 120 | /* 121 | @@ LUA_PATHSEP is the character that separates templates in a path. 122 | @@ LUA_PATH_MARK is the string that marks the substitution points in a 123 | @* template. 124 | @@ LUA_EXECDIR in a Windows path is replaced by the executable's 125 | @* directory. 126 | @@ LUA_IGMARK is a mark to ignore all before it when bulding the 127 | @* luaopen_ function name. 128 | ** CHANGE them if for some reason your system cannot use those 129 | ** characters. (E.g., if one of those characters is a common character 130 | ** in file/directory names.) Probably you do not need to change them. 131 | */ 132 | #define LUA_PATHSEP ";" 133 | #define LUA_PATH_MARK "?" 134 | #define LUA_EXECDIR "!" 135 | #define LUA_IGMARK "-" 136 | 137 | 138 | /* 139 | @@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger. 140 | ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most 141 | ** machines, ptrdiff_t gives a good choice between int or long.) 142 | */ 143 | #define LUA_INTEGER ptrdiff_t 144 | 145 | 146 | /* 147 | @@ LUA_API is a mark for all core API functions. 148 | @@ LUALIB_API is a mark for all standard library functions. 149 | ** CHANGE them if you need to define those functions in some special way. 150 | ** For instance, if you want to create one Windows DLL with the core and 151 | ** the libraries, you may want to use the following definition (define 152 | ** LUA_BUILD_AS_DLL to get it). 153 | */ 154 | #if defined(LUA_BUILD_AS_DLL) 155 | 156 | #if defined(LUA_CORE) || defined(LUA_LIB) 157 | #define LUA_API __declspec(dllexport) 158 | #else 159 | #define LUA_API __declspec(dllimport) 160 | #endif 161 | 162 | #else 163 | 164 | #define LUA_API extern 165 | 166 | #endif 167 | 168 | /* more often than not the libs go together with the core */ 169 | #define LUALIB_API LUA_API 170 | 171 | 172 | /* 173 | @@ LUAI_FUNC is a mark for all extern functions that are not to be 174 | @* exported to outside modules. 175 | @@ LUAI_DATA is a mark for all extern (const) variables that are not to 176 | @* be exported to outside modules. 177 | ** CHANGE them if you need to mark them in some special way. Elf/gcc 178 | ** (versions 3.2 and later) mark them as "hidden" to optimize access 179 | ** when Lua is compiled as a shared library. 180 | */ 181 | #if defined(luaall_c) 182 | #define LUAI_FUNC static 183 | #define LUAI_DATA /* empty */ 184 | 185 | #elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ 186 | defined(__ELF__) 187 | #define LUAI_FUNC __attribute__((visibility("hidden"))) extern 188 | #define LUAI_DATA LUAI_FUNC 189 | 190 | #else 191 | #define LUAI_FUNC extern 192 | #define LUAI_DATA extern 193 | #endif 194 | 195 | 196 | 197 | /* 198 | @@ LUA_QL describes how error messages quote program elements. 199 | ** CHANGE it if you want a different appearance. 200 | */ 201 | #define LUA_QL(x) "'" x "'" 202 | #define LUA_QS LUA_QL("%s") 203 | 204 | 205 | /* 206 | @@ LUA_IDSIZE gives the maximum size for the description of the source 207 | @* of a function in debug information. 208 | ** CHANGE it if you want a different size. 209 | */ 210 | #define LUA_IDSIZE 60 211 | 212 | 213 | /* 214 | ** {================================================================== 215 | ** Stand-alone configuration 216 | ** =================================================================== 217 | */ 218 | 219 | #if defined(lua_c) || defined(luaall_c) 220 | 221 | /* 222 | @@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that 223 | @* is, whether we're running lua interactively). 224 | ** CHANGE it if you have a better definition for non-POSIX/non-Windows 225 | ** systems. 226 | */ 227 | #if defined(LUA_USE_ISATTY) 228 | #include 229 | #define lua_stdin_is_tty() isatty(0) 230 | #elif defined(LUA_WIN) 231 | #include 232 | #include 233 | #define lua_stdin_is_tty() _isatty(_fileno(stdin)) 234 | #else 235 | #define lua_stdin_is_tty() 1 /* assume stdin is a tty */ 236 | #endif 237 | 238 | 239 | /* 240 | @@ LUA_PROMPT is the default prompt used by stand-alone Lua. 241 | @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. 242 | ** CHANGE them if you want different prompts. (You can also change the 243 | ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) 244 | */ 245 | #define LUA_PROMPT "> " 246 | #define LUA_PROMPT2 ">> " 247 | 248 | 249 | /* 250 | @@ LUA_PROGNAME is the default name for the stand-alone Lua program. 251 | ** CHANGE it if your stand-alone interpreter has a different name and 252 | ** your system is not able to detect that name automatically. 253 | */ 254 | #define LUA_PROGNAME "lua" 255 | 256 | 257 | /* 258 | @@ LUA_MAXINPUT is the maximum length for an input line in the 259 | @* stand-alone interpreter. 260 | ** CHANGE it if you need longer lines. 261 | */ 262 | #define LUA_MAXINPUT 512 263 | 264 | 265 | /* 266 | @@ lua_readline defines how to show a prompt and then read a line from 267 | @* the standard input. 268 | @@ lua_saveline defines how to "save" a read line in a "history". 269 | @@ lua_freeline defines how to free a line read by lua_readline. 270 | ** CHANGE them if you want to improve this functionality (e.g., by using 271 | ** GNU readline and history facilities). 272 | */ 273 | #if defined(LUA_USE_READLINE) 274 | #include 275 | #include 276 | #include 277 | #define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) 278 | #define lua_saveline(L,idx) \ 279 | if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ 280 | add_history(lua_tostring(L, idx)); /* add it to history */ 281 | #define lua_freeline(L,b) ((void)L, free(b)) 282 | #else 283 | #define lua_readline(L,b,p) \ 284 | ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ 285 | fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ 286 | #define lua_saveline(L,idx) { (void)L; (void)idx; } 287 | #define lua_freeline(L,b) { (void)L; (void)b; } 288 | #endif 289 | 290 | #endif 291 | 292 | /* }================================================================== */ 293 | 294 | 295 | /* 296 | @@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles 297 | @* as a percentage. 298 | ** CHANGE it if you want the GC to run faster or slower (higher values 299 | ** mean larger pauses which mean slower collection.) You can also change 300 | ** this value dynamically. 301 | */ 302 | #define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */ 303 | 304 | 305 | /* 306 | @@ LUAI_GCMUL defines the default speed of garbage collection relative to 307 | @* memory allocation as a percentage. 308 | ** CHANGE it if you want to change the granularity of the garbage 309 | ** collection. (Higher values mean coarser collections. 0 represents 310 | ** infinity, where each step performs a full collection.) You can also 311 | ** change this value dynamically. 312 | */ 313 | #define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ 314 | 315 | 316 | 317 | /* 318 | @@ LUA_COMPAT_GETN controls compatibility with old getn behavior. 319 | ** CHANGE it (define it) if you want exact compatibility with the 320 | ** behavior of setn/getn in Lua 5.0. 321 | */ 322 | #undef LUA_COMPAT_GETN 323 | 324 | /* 325 | @@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib. 326 | ** CHANGE it to undefined as soon as you do not need a global 'loadlib' 327 | ** function (the function is still available as 'package.loadlib'). 328 | */ 329 | #undef LUA_COMPAT_LOADLIB 330 | 331 | /* 332 | @@ LUA_COMPAT_VARARG controls compatibility with old vararg feature. 333 | ** CHANGE it to undefined as soon as your programs use only '...' to 334 | ** access vararg parameters (instead of the old 'arg' table). 335 | */ 336 | #define LUA_COMPAT_VARARG 337 | 338 | /* 339 | @@ LUA_COMPAT_MOD controls compatibility with old math.mod function. 340 | ** CHANGE it to undefined as soon as your programs use 'math.fmod' or 341 | ** the new '%' operator instead of 'math.mod'. 342 | */ 343 | #define LUA_COMPAT_MOD 344 | 345 | /* 346 | @@ LUA_COMPAT_LSTR controls compatibility with old long string nesting 347 | @* facility. 348 | ** CHANGE it to 2 if you want the old behaviour, or undefine it to turn 349 | ** off the advisory error when nesting [[...]]. 350 | */ 351 | #define LUA_COMPAT_LSTR 1 352 | 353 | /* 354 | @@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name. 355 | ** CHANGE it to undefined as soon as you rename 'string.gfind' to 356 | ** 'string.gmatch'. 357 | */ 358 | #define LUA_COMPAT_GFIND 359 | 360 | /* 361 | @@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' 362 | @* behavior. 363 | ** CHANGE it to undefined as soon as you replace to 'luaL_register' 364 | ** your uses of 'luaL_openlib' 365 | */ 366 | #define LUA_COMPAT_OPENLIB 367 | 368 | 369 | 370 | /* 371 | @@ luai_apicheck is the assert macro used by the Lua-C API. 372 | ** CHANGE luai_apicheck if you want Lua to perform some checks in the 373 | ** parameters it gets from API calls. This may slow down the interpreter 374 | ** a bit, but may be quite useful when debugging C code that interfaces 375 | ** with Lua. A useful redefinition is to use assert.h. 376 | */ 377 | #if defined(LUA_USE_APICHECK) 378 | #include 379 | #define luai_apicheck(L,o) { (void)L; assert(o); } 380 | #else 381 | #define luai_apicheck(L,o) { (void)L; } 382 | #endif 383 | 384 | 385 | /* 386 | @@ LUAI_BITSINT defines the number of bits in an int. 387 | ** CHANGE here if Lua cannot automatically detect the number of bits of 388 | ** your machine. Probably you do not need to change this. 389 | */ 390 | /* avoid overflows in comparison */ 391 | #if INT_MAX-20 < 32760 392 | #define LUAI_BITSINT 16 393 | #elif INT_MAX > 2147483640L 394 | /* int has at least 32 bits */ 395 | #define LUAI_BITSINT 32 396 | #else 397 | #error "you must define LUA_BITSINT with number of bits in an integer" 398 | #endif 399 | 400 | 401 | /* 402 | @@ LUAI_UINT32 is an unsigned integer with at least 32 bits. 403 | @@ LUAI_INT32 is an signed integer with at least 32 bits. 404 | @@ LUAI_UMEM is an unsigned integer big enough to count the total 405 | @* memory used by Lua. 406 | @@ LUAI_MEM is a signed integer big enough to count the total memory 407 | @* used by Lua. 408 | ** CHANGE here if for some weird reason the default definitions are not 409 | ** good enough for your machine. (The definitions in the 'else' 410 | ** part always works, but may waste space on machines with 64-bit 411 | ** longs.) Probably you do not need to change this. 412 | */ 413 | #if LUAI_BITSINT >= 32 414 | #define LUAI_UINT32 unsigned int 415 | #define LUAI_INT32 int 416 | #define LUAI_MAXINT32 INT_MAX 417 | #define LUAI_UMEM size_t 418 | #define LUAI_MEM ptrdiff_t 419 | #else 420 | /* 16-bit ints */ 421 | #define LUAI_UINT32 unsigned long 422 | #define LUAI_INT32 long 423 | #define LUAI_MAXINT32 LONG_MAX 424 | #define LUAI_UMEM unsigned long 425 | #define LUAI_MEM long 426 | #endif 427 | 428 | 429 | /* 430 | @@ LUAI_MAXCALLS limits the number of nested calls. 431 | ** CHANGE it if you need really deep recursive calls. This limit is 432 | ** arbitrary; its only purpose is to stop infinite recursion before 433 | ** exhausting memory. 434 | */ 435 | #define LUAI_MAXCALLS 20000 436 | 437 | 438 | /* 439 | @@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function 440 | @* can use. 441 | ** CHANGE it if you need lots of (Lua) stack space for your C 442 | ** functions. This limit is arbitrary; its only purpose is to stop C 443 | ** functions to consume unlimited stack space. (must be smaller than 444 | ** -LUA_REGISTRYINDEX) 445 | */ 446 | #define LUAI_MAXCSTACK 8000 447 | 448 | 449 | 450 | /* 451 | ** {================================================================== 452 | ** CHANGE (to smaller values) the following definitions if your system 453 | ** has a small C stack. (Or you may want to change them to larger 454 | ** values if your system has a large C stack and these limits are 455 | ** too rigid for you.) Some of these constants control the size of 456 | ** stack-allocated arrays used by the compiler or the interpreter, while 457 | ** others limit the maximum number of recursive calls that the compiler 458 | ** or the interpreter can perform. Values too large may cause a C stack 459 | ** overflow for some forms of deep constructs. 460 | ** =================================================================== 461 | */ 462 | 463 | 464 | /* 465 | @@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and 466 | @* syntactical nested non-terminals in a program. 467 | */ 468 | #define LUAI_MAXCCALLS 200 469 | 470 | 471 | /* 472 | @@ LUAI_MAXVARS is the maximum number of local variables per function 473 | @* (must be smaller than 250). 474 | */ 475 | #define LUAI_MAXVARS 200 476 | 477 | 478 | /* 479 | @@ LUAI_MAXUPVALUES is the maximum number of upvalues per function 480 | @* (must be smaller than 250). 481 | */ 482 | #define LUAI_MAXUPVALUES 60 483 | 484 | 485 | /* 486 | @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. 487 | */ 488 | #define LUAL_BUFFERSIZE BUFSIZ 489 | 490 | /* }================================================================== */ 491 | 492 | 493 | 494 | 495 | /* 496 | ** {================================================================== 497 | @@ LUA_NUMBER is the type of numbers in Lua. 498 | ** CHANGE the following definitions only if you want to build Lua 499 | ** with a number type different from double. You may also need to 500 | ** change lua_number2int & lua_number2integer. 501 | ** =================================================================== 502 | */ 503 | 504 | #define LUA_NUMBER_DOUBLE 505 | #define LUA_NUMBER double 506 | 507 | /* 508 | @@ LUAI_UACNUMBER is the result of an 'usual argument conversion' 509 | @* over a number. 510 | */ 511 | #define LUAI_UACNUMBER double 512 | 513 | 514 | /* 515 | @@ LUA_NUMBER_SCAN is the format for reading numbers. 516 | @@ LUA_NUMBER_FMT is the format for writing numbers. 517 | @@ lua_number2str converts a number to a string. 518 | @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. 519 | @@ lua_str2number converts a string to a number. 520 | */ 521 | #define LUA_NUMBER_SCAN "%lf" 522 | #define LUA_NUMBER_FMT "%.14g" 523 | #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) 524 | #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ 525 | #define lua_str2number(s,p) strtod((s), (p)) 526 | 527 | 528 | /* 529 | @@ The luai_num* macros define the primitive operations over numbers. 530 | */ 531 | #if defined(LUA_CORE) 532 | #include 533 | #define luai_numadd(a,b) ((a)+(b)) 534 | #define luai_numsub(a,b) ((a)-(b)) 535 | #define luai_nummul(a,b) ((a)*(b)) 536 | #define luai_numdiv(a,b) ((a)/(b)) 537 | #define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) 538 | #define luai_numpow(a,b) (pow(a,b)) 539 | #define luai_numunm(a) (-(a)) 540 | #define luai_numeq(a,b) ((a)==(b)) 541 | #define luai_numlt(a,b) ((a)<(b)) 542 | #define luai_numle(a,b) ((a)<=(b)) 543 | #define luai_numisnan(a) (!luai_numeq((a), (a))) 544 | #endif 545 | 546 | 547 | /* 548 | @@ lua_number2int is a macro to convert lua_Number to int. 549 | @@ lua_number2integer is a macro to convert lua_Number to lua_Integer. 550 | ** CHANGE them if you know a faster way to convert a lua_Number to 551 | ** int (with any rounding method and without throwing errors) in your 552 | ** system. In Pentium machines, a naive typecast from double to int 553 | ** in C is extremely slow, so any alternative is worth trying. 554 | */ 555 | 556 | /* On a Pentium, resort to a trick */ 557 | #if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \ 558 | (defined(__i386) || defined (_M_IX86) || defined(__i386__)) 559 | 560 | /* On a Microsoft compiler, use assembler */ 561 | #if defined(_MSC_VER) 562 | 563 | #define lua_number2int(i,d) __asm fld d __asm fistp i 564 | #define lua_number2integer(i,n) lua_number2int(i, n) 565 | 566 | /* the next trick should work on any Pentium, but sometimes clashes 567 | with a DirectX idiosyncrasy */ 568 | #else 569 | 570 | union luai_Cast { double l_d; long l_l; }; 571 | #define lua_number2int(i,d) \ 572 | { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } 573 | #define lua_number2integer(i,n) lua_number2int(i, n) 574 | 575 | #endif 576 | 577 | 578 | /* this option always works, but may be slow */ 579 | #else 580 | #define lua_number2int(i,d) ((i)=(int)(d)) 581 | #define lua_number2integer(i,d) ((i)=(lua_Integer)(d)) 582 | 583 | #endif 584 | 585 | /* }================================================================== */ 586 | 587 | 588 | /* 589 | @@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment. 590 | ** CHANGE it if your system requires alignments larger than double. (For 591 | ** instance, if your system supports long doubles and they must be 592 | ** aligned in 16-byte boundaries, then you should add long double in the 593 | ** union.) Probably you do not need to change this. 594 | */ 595 | #define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } 596 | 597 | 598 | /* 599 | @@ LUAI_THROW/LUAI_TRY define how Lua does exception handling. 600 | ** CHANGE them if you prefer to use longjmp/setjmp even with C++ 601 | ** or if want/don't to use _longjmp/_setjmp instead of regular 602 | ** longjmp/setjmp. By default, Lua handles errors with exceptions when 603 | ** compiling as C++ code, with _longjmp/_setjmp when asked to use them, 604 | ** and with longjmp/setjmp otherwise. 605 | */ 606 | #if defined(__cplusplus) 607 | /* C++ exceptions */ 608 | #define LUAI_THROW(L,c) throw(c) 609 | #define LUAI_TRY(L,c,a) try { a } catch(...) \ 610 | { if ((c)->status == 0) (c)->status = -1; } 611 | #define luai_jmpbuf int /* dummy variable */ 612 | 613 | #elif defined(LUA_USE_ULONGJMP) 614 | /* in Unix, try _longjmp/_setjmp (more efficient) */ 615 | #define LUAI_THROW(L,c) _longjmp((c)->b, 1) 616 | #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } 617 | #define luai_jmpbuf jmp_buf 618 | 619 | #else 620 | /* default handling with long jumps */ 621 | #define LUAI_THROW(L,c) longjmp((c)->b, 1) 622 | #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } 623 | #define luai_jmpbuf jmp_buf 624 | 625 | #endif 626 | 627 | 628 | /* 629 | @@ LUA_MAXCAPTURES is the maximum number of captures that a pattern 630 | @* can do during pattern-matching. 631 | ** CHANGE it if you need more captures. This limit is arbitrary. 632 | */ 633 | #define LUA_MAXCAPTURES 32 634 | 635 | 636 | /* 637 | @@ lua_tmpnam is the function that the OS library uses to create a 638 | @* temporary name. 639 | @@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam. 640 | ** CHANGE them if you have an alternative to tmpnam (which is considered 641 | ** insecure) or if you want the original tmpnam anyway. By default, Lua 642 | ** uses tmpnam except when POSIX is available, where it uses mkstemp. 643 | */ 644 | #if defined(loslib_c) || defined(luaall_c) 645 | 646 | #if defined(LUA_USE_MKSTEMP) 647 | #include 648 | #define LUA_TMPNAMBUFSIZE 32 649 | #define lua_tmpnam(b,e) { \ 650 | strcpy(b, "/tmp/lua_XXXXXX"); \ 651 | e = mkstemp(b); \ 652 | if (e != -1) close(e); \ 653 | e = (e == -1); } 654 | 655 | #else 656 | #define LUA_TMPNAMBUFSIZE L_tmpnam 657 | #define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } 658 | #endif 659 | 660 | #endif 661 | 662 | 663 | /* 664 | @@ lua_popen spawns a new process connected to the current one through 665 | @* the file streams. 666 | ** CHANGE it if you have a way to implement it in your system. 667 | */ 668 | #if defined(LUA_USE_POPEN) 669 | 670 | #define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) 671 | #define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) 672 | 673 | #elif defined(LUA_WIN) 674 | 675 | #define lua_popen(L,c,m) ((void)L, _popen(c,m)) 676 | #define lua_pclose(L,file) ((void)L, (_pclose(file) != -1)) 677 | 678 | #else 679 | 680 | #define lua_popen(L,c,m) ((void)((void)c, m), \ 681 | luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) 682 | #define lua_pclose(L,file) ((void)((void)L, file), 0) 683 | 684 | #endif 685 | 686 | /* 687 | @@ LUA_DL_* define which dynamic-library system Lua should use. 688 | ** CHANGE here if Lua has problems choosing the appropriate 689 | ** dynamic-library system for your platform (either Windows' DLL, Mac's 690 | ** dyld, or Unix's dlopen). If your system is some kind of Unix, there 691 | ** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for 692 | ** it. To use dlopen you also need to adapt the src/Makefile (probably 693 | ** adding -ldl to the linker options), so Lua does not select it 694 | ** automatically. (When you change the makefile to add -ldl, you must 695 | ** also add -DLUA_USE_DLOPEN.) 696 | ** If you do not want any kind of dynamic library, undefine all these 697 | ** options. 698 | ** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD. 699 | */ 700 | #if defined(LUA_USE_DLOPEN) 701 | #define LUA_DL_DLOPEN 702 | #endif 703 | 704 | #if defined(LUA_WIN) 705 | #define LUA_DL_DLL 706 | #endif 707 | 708 | 709 | /* 710 | @@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State 711 | @* (the data goes just *before* the lua_State pointer). 712 | ** CHANGE (define) this if you really need that. This value must be 713 | ** a multiple of the maximum alignment required for your machine. 714 | */ 715 | #define LUAI_EXTRASPACE 0 716 | 717 | 718 | /* 719 | @@ luai_userstate* allow user-specific actions on threads. 720 | ** CHANGE them if you defined LUAI_EXTRASPACE and need to do something 721 | ** extra when a thread is created/deleted/resumed/yielded. 722 | */ 723 | #define luai_userstateopen(L) ((void)L) 724 | #define luai_userstateclose(L) ((void)L) 725 | #define luai_userstatethread(L,L1) ((void)L) 726 | #define luai_userstatefree(L) ((void)L) 727 | #define luai_userstateresume(L,n) ((void)L) 728 | #define luai_userstateyield(L,n) ((void)L) 729 | 730 | 731 | /* 732 | @@ LUA_INTFRMLEN is the length modifier for integer conversions 733 | @* in 'string.format'. 734 | @@ LUA_INTFRM_T is the integer type correspoding to the previous length 735 | @* modifier. 736 | ** CHANGE them if your system supports long long or does not support long. 737 | */ 738 | 739 | #if defined(LUA_USELONGLONG) 740 | 741 | #define LUA_INTFRMLEN "ll" 742 | #define LUA_INTFRM_T long long 743 | 744 | #else 745 | 746 | #define LUA_INTFRMLEN "l" 747 | #define LUA_INTFRM_T long 748 | 749 | #endif 750 | 751 | 752 | 753 | /* =================================================================== */ 754 | 755 | /* 756 | ** Local configuration. You can use this space to add your redefinitions 757 | ** without modifying the main part of the file. 758 | */ 759 | 760 | 761 | 762 | #endif 763 | 764 | -------------------------------------------------------------------------------- /maclualib/include/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* Key to file-handle type */ 15 | #define LUA_FILEHANDLE "FILE*" 16 | 17 | 18 | #define LUA_COLIBNAME "coroutine" 19 | LUALIB_API int (luaopen_base) (lua_State *L); 20 | 21 | #define LUA_TABLIBNAME "table" 22 | LUALIB_API int (luaopen_table) (lua_State *L); 23 | 24 | #define LUA_IOLIBNAME "io" 25 | LUALIB_API int (luaopen_io) (lua_State *L); 26 | 27 | #define LUA_OSLIBNAME "os" 28 | LUALIB_API int (luaopen_os) (lua_State *L); 29 | 30 | #define LUA_STRLIBNAME "string" 31 | LUALIB_API int (luaopen_string) (lua_State *L); 32 | 33 | #define LUA_MATHLIBNAME "math" 34 | LUALIB_API int (luaopen_math) (lua_State *L); 35 | 36 | #define LUA_DBLIBNAME "debug" 37 | LUALIB_API int (luaopen_debug) (lua_State *L); 38 | 39 | #define LUA_LOADLIBNAME "package" 40 | LUALIB_API int (luaopen_package) (lua_State *L); 41 | 42 | 43 | /* open all previous libraries */ 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); 45 | 46 | 47 | 48 | #ifndef lua_assert 49 | #define lua_assert(x) ((void)0) 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /maclualib/lib/liblua.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/medaeus245/node-lua/13b1b830210256fc6bd24502ec23e5b63b07afd6/maclualib/lib/liblua.a -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-lua", 3 | "version": "1.0.4", 4 | "description": "Lua Bindings For NodeJS", 5 | "author": "medaeus245", 6 | "main": "index.js", 7 | "keywords": [ 8 | "lua", 9 | "lua5.1", 10 | "node-lua", 11 | "node-lua-binding", 12 | "nodejs" 13 | ], 14 | "scripts": { 15 | "install": "node-gyp rebuild" 16 | }, 17 | "dependencies": { 18 | "nan": "^2.6.2" 19 | }, 20 | "homepage": "http://github.com/medaeus245/node-lua", 21 | "repository": { 22 | "type": "git", 23 | "url": "git@github.com:medaeus245/node-lua.git" 24 | }, 25 | "license": "ISC", 26 | "gypfile": true 27 | } 28 | -------------------------------------------------------------------------------- /src/luastate.cc: -------------------------------------------------------------------------------- 1 | #define BUILDING_NODELUA 2 | 3 | #include 4 | #include 5 | 6 | #include "luastate.h" 7 | #include 8 | #include 9 | 10 | using v8::Function; 11 | using v8::Local; 12 | using v8::Number; 13 | using v8::String; 14 | using v8::Value; 15 | using Nan::HandleScope; 16 | using Nan::New; 17 | using Nan::Null; 18 | using Nan::To; 19 | 20 | LuaState::LuaState() {} 21 | LuaState::~LuaState() {} 22 | 23 | Nan::Persistent LuaState::constructor; 24 | 25 | LuaState* LuaState::instance = 0; 26 | LuaState* LuaState::getCurrentInstance() { 27 | return LuaState::instance; 28 | } 29 | void LuaState::setCurrentInstance(LuaState* instance) { 30 | LuaState::instance = instance; 31 | } 32 | 33 | void LuaState::Init(v8::Local exports) { 34 | 35 | Nan::HandleScope scope; 36 | 37 | // Prepare constructor template 38 | v8::Local tpl = Nan::New(New); 39 | tpl->SetClassName(Nan::New("LuaState").ToLocalChecked()); 40 | tpl->InstanceTemplate()->SetInternalFieldCount(1); 41 | 42 | // Prototype 43 | 44 | Nan::SetPrototypeMethod(tpl, "LoadFile", DoFileSync); 45 | Nan::SetPrototypeMethod(tpl, "LoadString", DoStringSync); 46 | 47 | Nan::SetPrototypeMethod(tpl, "AddPackagePath", AddPackagePath); 48 | 49 | Nan::SetPrototypeMethod(tpl, "DoFile", DoFileSync); 50 | Nan::SetPrototypeMethod(tpl, "DoString", DoStringSync); 51 | 52 | Nan::SetPrototypeMethod(tpl, "Status", StatusSync); 53 | Nan::SetPrototypeMethod(tpl, "CollectGarbage", CollectGarbageSync); 54 | 55 | Nan::SetPrototypeMethod(tpl, "SetGlobal", SetGlobal); 56 | Nan::SetPrototypeMethod(tpl, "GetGlobal", GetGlobal); 57 | 58 | Nan::SetPrototypeMethod(tpl, "SetField", SetField); 59 | Nan::SetPrototypeMethod(tpl, "GetField", GetField); 60 | 61 | Nan::SetPrototypeMethod(tpl, "ToValue", ToValue); 62 | Nan::SetPrototypeMethod(tpl, "Call", Call); 63 | 64 | Nan::SetPrototypeMethod(tpl, "Yield", LuaYield); 65 | Nan::SetPrototypeMethod(tpl, "Resume", LuaResume); 66 | 67 | Nan::SetPrototypeMethod(tpl, "Close", Close); 68 | 69 | Nan::SetPrototypeMethod(tpl, "RegisterFunction", RegisterFunction); 70 | 71 | Nan::SetPrototypeMethod(tpl, "Push", Push); 72 | Nan::SetPrototypeMethod(tpl, "Pop", Pop); 73 | Nan::SetPrototypeMethod(tpl, "GetTop", GetTop); 74 | Nan::SetPrototypeMethod(tpl, "SetTop", SetTop); 75 | Nan::SetPrototypeMethod(tpl, "Replace", Replace); 76 | 77 | constructor.Reset(tpl->GetFunction()); 78 | exports->Set(Nan::New("LuaState").ToLocalChecked(), tpl->GetFunction()); 79 | } 80 | 81 | void LuaState::New(const Nan::FunctionCallbackInfo& info) { 82 | Nan::HandleScope scope; 83 | 84 | if(!info.IsConstructCall()) { 85 | Nan::ThrowTypeError("LuaState Requires The 'new' Operator To Create An Instance"); 86 | return; 87 | } 88 | 89 | LuaState* obj = new LuaState(); 90 | obj->lua_ = lua_open(); 91 | luaL_openlibs(obj->lua_); 92 | obj->Wrap(info.This()); 93 | 94 | info.GetReturnValue().Set(info.This()); 95 | } 96 | 97 | int LuaState::CallFunction(lua_State* L){ 98 | 99 | char *func_name = (char *)lua_tostring(L, lua_upvalueindex(1)); 100 | 101 | v8::Local ret_val = Nan::Undefined(); 102 | 103 | if (LuaState::getCurrentInstance()) { 104 | LuaState *self = LuaState::getCurrentInstance(); 105 | lua_State *mainL = self->lua_; 106 | self->lua_ = L; 107 | 108 | const unsigned argc = 0; 109 | Local* argv = new Local[0]; 110 | 111 | std::map >::iterator iter; 112 | for(iter = self->functions.begin(); iter != self->functions.end(); iter++) { 113 | if(strcmp(iter->first, func_name) == 0) { 114 | v8::Local func = Nan::New(iter->second); 115 | ret_val = Nan::MakeCallback(Nan::GetCurrentContext()->Global(), func, argc, argv); 116 | break; 117 | } 118 | } 119 | 120 | self->lua_ = mainL; 121 | } 122 | 123 | int args = 0; 124 | if (ret_val->IsNumber()) { 125 | args = Nan::To(ret_val).FromMaybe(0); 126 | } 127 | return args; 128 | } 129 | 130 | void LuaState::RegisterFunction(const Nan::FunctionCallbackInfo& info){ 131 | Nan::HandleScope scope; 132 | 133 | if(info.Length() < 1){ 134 | Nan::ThrowTypeError("LuaState.RegisterFunction Must Have 2 Arguments"); 135 | return; 136 | } 137 | 138 | if(!info[0]->IsString()){ 139 | Nan::ThrowTypeError("LuaState.RegisterFunction Argument 1 Must Be A String"); 140 | return; 141 | } 142 | 143 | if(!info[1]->IsFunction()){ 144 | Nan::ThrowTypeError("LuaState.RegisterFunction Argument 2 Must Be A Function"); 145 | return; 146 | } 147 | 148 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 149 | LuaState::setCurrentInstance(obj); 150 | lua_State* L = obj->lua_; 151 | 152 | char* func_name = get_str(info[0]); 153 | Nan::Persistent func(Local::Cast(info[1])); 154 | obj->functions[func_name].Reset(func); 155 | 156 | lua_pushstring(L, func_name); 157 | lua_pushcclosure(L, CallFunction, 1); 158 | lua_setglobal(L, func_name); 159 | 160 | LuaState::setCurrentInstance(0); 161 | info.GetReturnValue().Set(Nan::Undefined()); 162 | } 163 | 164 | void LuaState::AddPackagePath(const Nan::FunctionCallbackInfo& info){ 165 | Nan::HandleScope scope; 166 | 167 | if (info.Length() < 1) { 168 | Nan::ThrowTypeError("LuaState.DoFile Takes Only 1 Argument"); 169 | return; 170 | } 171 | 172 | if (!info[0]->IsString()) { 173 | Nan::ThrowTypeError("LuaState.DoFile Argument 1 Must Be A String"); 174 | return; 175 | } 176 | 177 | std::string path = std::string(get_str(info[0])); 178 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 179 | LuaState::setCurrentInstance(obj); 180 | lua_State *L = obj->lua_; 181 | 182 | std::replace(path.begin(), path.end(), '\\', '/'); 183 | if (path.back() == '/') { 184 | path.pop_back(); 185 | } 186 | std::string code = std::string("package.path = package.path .. '") + path + "/?.lua;';"; 187 | 188 | if(luaL_dostring(L, code.c_str())) { 189 | char buf[1024]; 190 | sprintf(buf, "LuaState.AddPackagePath: Could not add package path:\n%s\n", path.c_str()); 191 | Nan::ThrowError(Nan::New(buf).ToLocalChecked()); 192 | LuaState::setCurrentInstance(0); 193 | return; 194 | } 195 | info.GetReturnValue().Set(Nan::Undefined()); 196 | LuaState::setCurrentInstance(0); 197 | } 198 | 199 | 200 | void LuaState::LoadFileSync(const Nan::FunctionCallbackInfo& info){ 201 | Nan::HandleScope scope; 202 | 203 | if (info.Length() < 1) { 204 | Nan::ThrowTypeError("LuaState.DoFile Takes Only 1 Argument"); 205 | return; 206 | } 207 | 208 | if (!info[0]->IsString()) { 209 | Nan::ThrowTypeError("LuaState.DoFile Argument 1 Must Be A String"); 210 | return; 211 | } 212 | 213 | char* file_name = get_str(info[0]); 214 | 215 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 216 | LuaState::setCurrentInstance(obj); 217 | lua_State* L = obj->lua_; 218 | 219 | if (luaL_loadfile(L, file_name)) { 220 | char buf[1024]; 221 | sprintf(buf, "LuaState.LoadFile: Parsing Of File %s Has Failed:\n%s\n", file_name, lua_tostring(L, -1)); 222 | Nan::ThrowError(Nan::New(buf).ToLocalChecked()); 223 | LuaState::setCurrentInstance(0); 224 | return; 225 | } 226 | 227 | info.GetReturnValue().Set(Nan::Undefined()); 228 | LuaState::setCurrentInstance(0); 229 | } 230 | 231 | 232 | void LuaState::LoadStringSync(const Nan::FunctionCallbackInfo& info) { 233 | Nan::HandleScope scope; 234 | 235 | if(info.Length() < 1){ 236 | Nan::ThrowTypeError("LuaState.DoString Requires 1 Argument"); 237 | return; 238 | } 239 | 240 | char *lua_code = get_str(info[0]); 241 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 242 | LuaState::setCurrentInstance(obj); 243 | lua_State *L = obj->lua_; 244 | 245 | if(luaL_loadstring(L, lua_code)) { 246 | char buf[1024]; 247 | sprintf(buf, "LuaState.LoadString: Parsing Of Lua Code Has Failed:\n%s\n", lua_tostring(L, -1)); 248 | Nan::ThrowError(Nan::New(buf).ToLocalChecked()); 249 | LuaState::setCurrentInstance(0); 250 | return; 251 | } 252 | info.GetReturnValue().Set(Nan::Undefined()); 253 | LuaState::setCurrentInstance(0); 254 | } 255 | 256 | 257 | void LuaState::DoFileSync(const Nan::FunctionCallbackInfo& info){ 258 | Nan::HandleScope scope; 259 | 260 | if (info.Length() < 1) { 261 | Nan::ThrowTypeError("LuaState.DoFile Takes Only 1 Argument"); 262 | return; 263 | } 264 | 265 | if (!info[0]->IsString()) { 266 | Nan::ThrowTypeError("LuaState.DoFile Argument 1 Must Be A String"); 267 | return; 268 | } 269 | 270 | char* file_name = get_str(info[0]); 271 | 272 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 273 | LuaState::setCurrentInstance(obj); 274 | lua_State* L = obj->lua_; 275 | 276 | if (luaL_dofile(L, file_name)) { 277 | char buf[1024]; 278 | sprintf(buf, "LuaState.DoFile: Execution Of File %s Has Failed:\n%s\n", file_name, lua_tostring(L, -1)); 279 | Nan::ThrowError(Nan::New(buf).ToLocalChecked()); 280 | LuaState::setCurrentInstance(0); 281 | return; 282 | } 283 | 284 | info.GetReturnValue().Set(Nan::Undefined()); 285 | LuaState::setCurrentInstance(0); 286 | } 287 | 288 | void LuaState::DoStringSync(const Nan::FunctionCallbackInfo& info) { 289 | Nan::HandleScope scope; 290 | 291 | if(info.Length() < 1){ 292 | Nan::ThrowTypeError("LuaState.DoString Requires 1 Argument"); 293 | return; 294 | } 295 | 296 | char *lua_code = get_str(info[0]); 297 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 298 | LuaState::setCurrentInstance(obj); 299 | lua_State *L = obj->lua_; 300 | 301 | if(luaL_dostring(L, lua_code)) { 302 | char buf[1024]; 303 | sprintf(buf, "LuaState.DoString: Execution Of Lua Code Has Failed:\n%s\n", lua_tostring(L, -1)); 304 | Nan::ThrowError(Nan::New(buf).ToLocalChecked()); 305 | LuaState::setCurrentInstance(0); 306 | return; 307 | } 308 | info.GetReturnValue().Set(Nan::Undefined()); 309 | LuaState::setCurrentInstance(0); 310 | } 311 | 312 | void LuaState::SetGlobal(const Nan::FunctionCallbackInfo& info) { 313 | Nan::HandleScope scope; 314 | 315 | if (info.Length() < 1) { 316 | Nan::ThrowTypeError("LuaState.SetGlobal Requires 1 Arguments"); 317 | return; 318 | } 319 | 320 | if (!info[0]->IsString()) { 321 | Nan::ThrowTypeError("LuaState.SetGlobal Argument 1 Must Be A String"); 322 | return; 323 | } 324 | 325 | char *global_name = get_str(info[0]); 326 | 327 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 328 | 329 | lua_setglobal(obj->lua_, global_name); 330 | info.GetReturnValue().Set(Nan::Undefined()); 331 | } 332 | 333 | void LuaState::GetGlobal(const Nan::FunctionCallbackInfo& info) { 334 | Nan::HandleScope scope; 335 | 336 | if (info.Length() < 1) { 337 | Nan::ThrowTypeError("LuaState.GetGlobal Requires 1 Argument"); 338 | return; 339 | } 340 | 341 | if (!info[0]->IsString()) { 342 | Nan::ThrowTypeError("LuaState.GetGlobal Argument 1 Must Be A String"); 343 | return; 344 | } 345 | 346 | char *global_name = get_str(info[0]); 347 | 348 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 349 | lua_getglobal(obj->lua_, global_name); 350 | info.GetReturnValue().Set(Nan::Undefined()); 351 | } 352 | 353 | void LuaState::SetField(const Nan::FunctionCallbackInfo& info) { 354 | Nan::HandleScope scope; 355 | 356 | if (info.Length() < 3) { 357 | Nan::ThrowTypeError("LuaState.SetField Requires 3 Arguments"); 358 | return; 359 | } 360 | 361 | if (!info[0]->IsNumber()) { 362 | Nan::ThrowTypeError("LuaState.GetField Argument 1 Must Be A Number"); 363 | return; 364 | } 365 | 366 | if (!info[1]->IsString()) { 367 | Nan::ThrowTypeError("LuaState.GetField Argument 2 Must Be A String"); 368 | return; 369 | } 370 | 371 | int index = Nan::To(info[0]).FromMaybe(0); 372 | char *field_name = get_str(info[1]); 373 | 374 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 375 | 376 | push_value_to_lua(obj->lua_, info[1]); 377 | lua_setfield(obj->lua_, index, field_name); 378 | info.GetReturnValue().Set(Nan::Undefined()); 379 | } 380 | 381 | void LuaState::GetField(const Nan::FunctionCallbackInfo& info) { 382 | Nan::HandleScope scope; 383 | 384 | if (info.Length() < 2) { 385 | Nan::ThrowTypeError("LuaState.GetField Requires 2 Argument"); 386 | return; 387 | } 388 | 389 | if (!info[0]->IsNumber()) { 390 | Nan::ThrowTypeError("LuaState.GetField Argument 1 Must Be A Number"); 391 | return; 392 | } 393 | 394 | if (!info[1]->IsString()) { 395 | Nan::ThrowTypeError("LuaState.GetField Argument 2 Must Be A String"); 396 | return; 397 | } 398 | 399 | int index = Nan::To(info[0]).FromMaybe(0); 400 | char *field_name = get_str(info[1]); 401 | 402 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 403 | lua_getfield(obj->lua_, index, field_name); 404 | info.GetReturnValue().Set(Nan::Undefined()); 405 | } 406 | 407 | void LuaState::ToValue(const Nan::FunctionCallbackInfo& info) { 408 | Nan::HandleScope scope; 409 | 410 | if (info.Length() < 1) { 411 | Nan::ThrowTypeError("LuaState.ToValue Requires 1 Argument"); 412 | return; 413 | } 414 | 415 | if (!info[0]->IsNumber()) { 416 | Nan::ThrowTypeError("LuaState.ToValue Argument 1 Must Be A Number"); 417 | return; 418 | } 419 | 420 | int index = Nan::To(info[0]).FromMaybe(0); 421 | 422 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 423 | Local val = lua_to_value(obj->lua_, index); 424 | info.GetReturnValue().Set(val); 425 | } 426 | 427 | void LuaState::Call(const Nan::FunctionCallbackInfo& info) { 428 | Nan::HandleScope scope; 429 | 430 | if (info.Length() < 2) { 431 | Nan::ThrowTypeError("LuaState.Call Requires 2 Argument"); 432 | return; 433 | } 434 | 435 | if (!info[0]->IsNumber()) { 436 | Nan::ThrowTypeError("LuaState.Call Argument 1 Must Be A Number"); 437 | return; 438 | } 439 | 440 | if (!info[1]->IsNumber()) { 441 | Nan::ThrowTypeError("LuaState.Call Argument 2 Must Be A Number"); 442 | return; 443 | } 444 | 445 | 446 | int args = Nan::To(info[0]).FromMaybe(0); 447 | int results = Nan::To(info[1]).FromMaybe(0); 448 | 449 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 450 | LuaState::setCurrentInstance(obj); 451 | lua_State *L = obj->lua_; 452 | 453 | if(lua_pcall(L, args, results, 0)) { 454 | char buf[1024]; 455 | sprintf(buf, "LuaState.Call: Execution Of Lua Function Has Failed:\n%s\n", lua_tostring(L, -1)); 456 | Nan::ThrowError(Nan::New(buf).ToLocalChecked()); 457 | LuaState::setCurrentInstance(0); 458 | return; 459 | } 460 | LuaState::setCurrentInstance(0); 461 | info.GetReturnValue().Set(Nan::Undefined()); 462 | } 463 | 464 | void LuaState::LuaYield(const Nan::FunctionCallbackInfo& info) { 465 | Nan::HandleScope scope; 466 | 467 | if (info.Length() < 1) { 468 | Nan::ThrowTypeError("LuaState.Yield Requires 1 Argument"); 469 | return; 470 | } 471 | 472 | if (!info[0]->IsNumber()) { 473 | Nan::ThrowTypeError("LuaState.Yield Argument 1 Must Be A Number"); 474 | return; 475 | } 476 | 477 | int args = Nan::To(info[0]).FromMaybe(0); 478 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 479 | lua_yield(obj->lua_, args); 480 | info.GetReturnValue().Set(Nan::Undefined()); 481 | } 482 | 483 | void LuaState::LuaResume(const Nan::FunctionCallbackInfo& info) { 484 | Nan::HandleScope scope; 485 | 486 | if (info.Length() < 1) { 487 | Nan::ThrowTypeError("LuaState.Resume Requires 1 Argument"); 488 | return; 489 | } 490 | 491 | if (!info[0]->IsNumber()) { 492 | Nan::ThrowTypeError("LuaState.Resume Argument 1 Must Be A Number"); 493 | return; 494 | } 495 | 496 | int args = Nan::To(info[0]).FromMaybe(0); 497 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 498 | lua_resume(obj->lua_, args); 499 | info.GetReturnValue().Set(Nan::Undefined()); 500 | } 501 | 502 | 503 | void LuaState::Close(const Nan::FunctionCallbackInfo& info) { 504 | Nan::HandleScope scope; 505 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 506 | lua_close(obj->lua_); 507 | info.GetReturnValue().Set(Nan::Undefined()); 508 | } 509 | 510 | void LuaState::StatusSync(const Nan::FunctionCallbackInfo& info){ 511 | Nan::HandleScope scope; 512 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 513 | int status = lua_status(obj->lua_); 514 | info.GetReturnValue().Set(Nan::New(status)); 515 | } 516 | 517 | void LuaState::CollectGarbageSync(const Nan::FunctionCallbackInfo& info){ 518 | Nan::HandleScope scope; 519 | 520 | if(info.Length() < 1){ 521 | Nan::ThrowTypeError("LuaState.CollectGarbage Requires 1 Argument"); 522 | return; 523 | } 524 | 525 | if(!info[0]->IsNumber()){ 526 | Nan::ThrowTypeError("LuaState.CollectGarbage Argument 1 Must Be A Number, try nodelua.GC.[TYPE]"); 527 | return; 528 | } 529 | 530 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 531 | int type = Nan::To(info[0]).FromMaybe(0); 532 | int gc = lua_gc(obj->lua_, type, 0); 533 | info.GetReturnValue().Set(Nan::New(gc)); 534 | } 535 | 536 | void LuaState::Push(const Nan::FunctionCallbackInfo& info) { 537 | Nan::HandleScope scope; 538 | 539 | if (info.Length() < 1) { 540 | Nan::ThrowTypeError("LuaState.Push Requires 1 Argument"); 541 | return; 542 | } 543 | 544 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 545 | push_value_to_lua(obj->lua_, info[0]); 546 | info.GetReturnValue().Set(Nan::Undefined()); 547 | } 548 | 549 | void LuaState::Pop(const Nan::FunctionCallbackInfo& info) { 550 | Nan::HandleScope scope; 551 | 552 | int pop_n = 1; 553 | if (info.Length() > 0 && info[0]->IsNumber()) { 554 | pop_n = Nan::To(info[0]).FromMaybe(1); 555 | } 556 | 557 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 558 | lua_pop(obj->lua_, pop_n); 559 | info.GetReturnValue().Set(Nan::Undefined()); 560 | } 561 | 562 | void LuaState::GetTop(const Nan::FunctionCallbackInfo& info) { 563 | Nan::HandleScope scope; 564 | 565 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 566 | int n = lua_gettop(obj->lua_); 567 | info.GetReturnValue().Set(Nan::New(n)); 568 | } 569 | 570 | void LuaState::SetTop(const Nan::FunctionCallbackInfo& info) { 571 | Nan::HandleScope scope; 572 | 573 | int set_n = 0; 574 | if(info.Length() > 0 && info[0]->IsNumber()){ 575 | set_n = Nan::To(info[0]).FromMaybe(0); 576 | } 577 | 578 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 579 | lua_settop(obj->lua_, set_n); 580 | info.GetReturnValue().Set(Nan::Undefined()); 581 | } 582 | 583 | void LuaState::Replace(const Nan::FunctionCallbackInfo& info) { 584 | Nan::HandleScope scope; 585 | 586 | if (info.Length() < 1) { 587 | Nan::ThrowTypeError("LuaState.Replace Requires 1 Argument"); 588 | return; 589 | } 590 | 591 | if (!info[0]->IsNumber()) { 592 | Nan::ThrowTypeError("LuaState.Replace Argument 1 Must Be A Number"); 593 | return; 594 | } 595 | 596 | int index = Nan::To(info[0]).FromMaybe(0); 597 | LuaState* obj = ObjectWrap::Unwrap(info.This()); 598 | lua_replace(obj->lua_, index); 599 | info.GetReturnValue().Set(Nan::Undefined()); 600 | } 601 | -------------------------------------------------------------------------------- /src/luastate.h: -------------------------------------------------------------------------------- 1 | #ifndef LUASTATE_H 2 | #define LUASTATE_H 3 | 4 | #include 5 | #include 6 | 7 | #include "utils.h" 8 | #include 9 | #include 10 | 11 | extern "C" { 12 | #include 13 | #include 14 | #include 15 | } 16 | 17 | class LuaState : public Nan::ObjectWrap { 18 | private: 19 | static Nan::Persistent constructor; 20 | static LuaState* instance; 21 | 22 | std::map > functions; 23 | lua_State* lua_; 24 | 25 | public: 26 | static void Init(v8::Local exports); 27 | static int CallFunction(lua_State* L); 28 | 29 | static LuaState* getCurrentInstance(); 30 | static void setCurrentInstance(LuaState*); 31 | 32 | private: 33 | LuaState(); 34 | ~LuaState(); 35 | 36 | static void New(const Nan::FunctionCallbackInfo& info); 37 | static void Close(const Nan::FunctionCallbackInfo& info); 38 | 39 | static void CollectGarbageSync(const Nan::FunctionCallbackInfo& info); 40 | static void StatusSync(const Nan::FunctionCallbackInfo& info); 41 | 42 | static void AddPackagePath(const Nan::FunctionCallbackInfo& info); 43 | 44 | static void LoadFileSync(const Nan::FunctionCallbackInfo& info); 45 | static void LoadStringSync(const Nan::FunctionCallbackInfo& info); 46 | 47 | static void DoFileSync(const Nan::FunctionCallbackInfo& info); 48 | static void DoStringSync(const Nan::FunctionCallbackInfo& info); 49 | 50 | static void SetGlobal(const Nan::FunctionCallbackInfo& info); 51 | static void GetGlobal(const Nan::FunctionCallbackInfo& info); 52 | 53 | static void SetField(const Nan::FunctionCallbackInfo& info); 54 | static void GetField(const Nan::FunctionCallbackInfo& info); 55 | 56 | static void ToValue(const Nan::FunctionCallbackInfo& info); 57 | static void Call(const Nan::FunctionCallbackInfo& info); 58 | 59 | static void LuaYield(const Nan::FunctionCallbackInfo& info); 60 | static void LuaResume(const Nan::FunctionCallbackInfo& info); 61 | 62 | static void RegisterFunction(const Nan::FunctionCallbackInfo& info); 63 | 64 | static void Push(const Nan::FunctionCallbackInfo& info); 65 | static void Pop(const Nan::FunctionCallbackInfo& info); 66 | static void GetTop(const Nan::FunctionCallbackInfo& info); 67 | static void SetTop(const Nan::FunctionCallbackInfo& info); 68 | static void Replace(const Nan::FunctionCallbackInfo& info); 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/nodelua.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "luastate.h" 6 | #ifndef WIN32 7 | # include 8 | #else 9 | //TODO 10 | #endif 11 | 12 | extern "C" { 13 | #include 14 | } 15 | 16 | using namespace v8; 17 | 18 | void init_info_constants(v8::Local target){ 19 | Local constants = Nan::New(); 20 | constants->Set(Nan::New("VERSION").ToLocalChecked(),Nan::New(LUA_VERSION).ToLocalChecked()); 21 | constants->Set(Nan::New("VERSION_NUM").ToLocalChecked(), Nan::New(LUA_VERSION_NUM)); 22 | constants->Set(Nan::New("COPYRIGHT").ToLocalChecked(), Nan::New(LUA_COPYRIGHT).ToLocalChecked()); 23 | constants->Set(Nan::New("AUTHORS").ToLocalChecked(), Nan::New(LUA_AUTHORS).ToLocalChecked()); 24 | target->Set(Nan::New("INFO").ToLocalChecked(), constants); 25 | } 26 | 27 | void init_status_constants(Handle target){ 28 | Local constants = Nan::New(); 29 | constants->Set(Nan::New("YIELD").ToLocalChecked(), Nan::New(LUA_YIELD)); 30 | constants->Set(Nan::New("ERRRUN").ToLocalChecked(), Nan::New(LUA_ERRRUN)); 31 | constants->Set(Nan::New("ERRSYNTAX").ToLocalChecked(), Nan::New(LUA_ERRSYNTAX)); 32 | constants->Set(Nan::New("ERRMEM").ToLocalChecked(), Nan::New(LUA_ERRMEM)); 33 | constants->Set(Nan::New("ERRERR").ToLocalChecked(), Nan::New(LUA_ERRERR)); 34 | target->Set(Nan::New("STATUS").ToLocalChecked(), constants); 35 | } 36 | 37 | void init_gc_constants(Handle target){ 38 | Local constants = Nan::New(); 39 | constants->Set(Nan::New("STOP").ToLocalChecked(), Nan::New(LUA_GCSTOP)); 40 | constants->Set(Nan::New("RESTART").ToLocalChecked(), Nan::New(LUA_GCRESTART)); 41 | constants->Set(Nan::New("COLLECT").ToLocalChecked(), Nan::New(LUA_GCCOLLECT)); 42 | constants->Set(Nan::New("COUNT").ToLocalChecked(), Nan::New(LUA_GCCOUNT)); 43 | constants->Set(Nan::New("COUNTB").ToLocalChecked(), Nan::New(LUA_GCCOUNTB)); 44 | constants->Set(Nan::New("STEP").ToLocalChecked(), Nan::New(LUA_GCSTEP)); 45 | constants->Set(Nan::New("SETPAUSE").ToLocalChecked(), Nan::New(LUA_GCSETPAUSE)); 46 | constants->Set(Nan::New("SETSTEPMUL").ToLocalChecked(), Nan::New(LUA_GCSETSTEPMUL)); 47 | target->Set(Nan::New("GC").ToLocalChecked(), constants); 48 | } 49 | 50 | void init_lua_constants(Handle target){ 51 | Local constants = Nan::New(); 52 | constants->Set(Nan::New("GLOBALSINDEX").ToLocalChecked(), Nan::New(LUA_GLOBALSINDEX)); 53 | target->Set(Nan::New("LUA").ToLocalChecked(), constants); 54 | } 55 | 56 | void init(v8::Local exports, v8::Local module) { 57 | LuaState::Init(exports); 58 | init_gc_constants(exports); 59 | init_status_constants(exports); 60 | init_info_constants(exports); 61 | init_lua_constants(exports); 62 | // printf("node-lua loaded\n"); 63 | fflush(stdout); 64 | } 65 | NODE_MODULE(nodelua, init) 66 | -------------------------------------------------------------------------------- /src/utils.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "utils.h" 3 | #include 4 | 5 | char * get_str(v8::Local val){ 6 | if(!val->IsString()){ 7 | Nan::ThrowError("Argument Must Be A String"); 8 | return NULL; 9 | } 10 | 11 | v8::String::Utf8Value val_string(val); 12 | char * val_char_ptr = (char *) malloc(val_string.length() + 1); 13 | strcpy(val_char_ptr, *val_string); 14 | return val_char_ptr; 15 | } 16 | 17 | 18 | v8::Local lua_to_value(lua_State* L, int i){ 19 | switch(lua_type(L, i)){ 20 | case LUA_TBOOLEAN: 21 | return Nan::New((int)lua_toboolean(L, i)); 22 | break; 23 | case LUA_TNUMBER: 24 | return Nan::New(lua_tonumber(L, i)); 25 | break; 26 | case LUA_TSTRING: 27 | return Nan::New((char *)lua_tostring(L, i)).ToLocalChecked(); 28 | break; 29 | case LUA_TTABLE: 30 | { 31 | v8::Local obj = Nan::New(); 32 | lua_pushnil(L); 33 | while(lua_next(L, -2) != 0){ 34 | v8::Local key = lua_to_value(L, -2); 35 | v8::Local value = lua_to_value(L, -1); 36 | obj->Set(key, value); 37 | lua_pop(L, 1); 38 | } 39 | return obj; 40 | break; 41 | } 42 | default: 43 | return Nan::Undefined(); 44 | break; 45 | } 46 | } 47 | 48 | void push_value_to_lua(lua_State* L, v8::Local value){ 49 | if (value->IsString()){ 50 | lua_pushstring(L, get_str(value->ToString())); 51 | }else if(value->IsNumber()){ 52 | int i_value = Nan::To(value).FromMaybe(0); 53 | lua_pushinteger(L, i_value); 54 | }else if(value->IsBoolean()){ 55 | int b_value = (int)value->ToBoolean()->Value(); 56 | lua_pushboolean(L, b_value); 57 | }else if(value->IsObject()){ 58 | lua_newtable(L); 59 | v8::Local obj = value->ToObject(); 60 | v8::Local keys = obj->GetPropertyNames(); 61 | for(uint32_t i = 0; i < keys->Length(); ++i){ 62 | v8::Local key = keys->Get(i); 63 | v8::Local val = obj->Get(key); 64 | push_value_to_lua(L, key); 65 | push_value_to_lua(L, val); 66 | lua_settable(L, -3); 67 | } 68 | }else{ 69 | lua_pushnil(L); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef LUAUTILS_H 2 | #define LUAUTILS_H 3 | 4 | #include 5 | #include 6 | 7 | extern "C"{ 8 | #include 9 | #include 10 | #include 11 | } 12 | 13 | char * get_str(v8::Local val); 14 | v8::Local lua_to_value(lua_State* L, int); 15 | void push_value_to_lua(lua_State* L, v8::Handle value); 16 | #endif 17 | -------------------------------------------------------------------------------- /win64luajit/lauxlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions for building Lua libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lauxlib_h 9 | #define lauxlib_h 10 | 11 | 12 | #include 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | 18 | #define luaL_getn(L,i) ((int)lua_objlen(L, i)) 19 | #define luaL_setn(L,i,j) ((void)0) /* no op! */ 20 | 21 | /* extra error code for `luaL_load' */ 22 | #define LUA_ERRFILE (LUA_ERRERR+1) 23 | 24 | typedef struct luaL_Reg { 25 | const char *name; 26 | lua_CFunction func; 27 | } luaL_Reg; 28 | 29 | LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, 30 | const luaL_Reg *l, int nup); 31 | LUALIB_API void (luaL_register) (lua_State *L, const char *libname, 32 | const luaL_Reg *l); 33 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 34 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 35 | LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); 36 | LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); 37 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, 38 | size_t *l); 39 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, 40 | const char *def, size_t *l); 41 | LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); 42 | LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); 43 | 44 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); 45 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, 46 | lua_Integer def); 47 | 48 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 49 | LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); 50 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); 51 | 52 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); 53 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); 54 | 55 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); 56 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); 57 | 58 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, 59 | const char *const lst[]); 60 | 61 | LUALIB_API int (luaL_ref) (lua_State *L, int t); 62 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); 63 | 64 | LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); 65 | LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, 66 | const char *name); 67 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); 68 | 69 | LUALIB_API lua_State *(luaL_newstate) (void); 70 | 71 | 72 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, 73 | const char *r); 74 | 75 | LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, 76 | const char *fname, int szhint); 77 | 78 | /* From Lua 5.2. */ 79 | LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname); 80 | LUALIB_API int luaL_execresult(lua_State *L, int stat); 81 | LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, 82 | const char *mode); 83 | LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, 84 | const char *name, const char *mode); 85 | LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, 86 | int level); 87 | 88 | 89 | /* 90 | ** =============================================================== 91 | ** some useful macros 92 | ** =============================================================== 93 | */ 94 | 95 | #define luaL_argcheck(L, cond,numarg,extramsg) \ 96 | ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) 97 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 98 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 99 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) 100 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) 101 | #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) 102 | #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) 103 | 104 | #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) 105 | 106 | #define luaL_dofile(L, fn) \ 107 | (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 108 | 109 | #define luaL_dostring(L, s) \ 110 | (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 111 | 112 | #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) 113 | 114 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) 115 | 116 | /* 117 | ** {====================================================== 118 | ** Generic Buffer manipulation 119 | ** ======================================================= 120 | */ 121 | 122 | 123 | 124 | typedef struct luaL_Buffer { 125 | char *p; /* current position in buffer */ 126 | int lvl; /* number of strings in the stack (level) */ 127 | lua_State *L; 128 | char buffer[LUAL_BUFFERSIZE]; 129 | } luaL_Buffer; 130 | 131 | #define luaL_addchar(B,c) \ 132 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ 133 | (*(B)->p++ = (char)(c))) 134 | 135 | /* compatibility only */ 136 | #define luaL_putchar(B,c) luaL_addchar(B,c) 137 | 138 | #define luaL_addsize(B,n) ((B)->p += (n)) 139 | 140 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); 141 | LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); 142 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); 143 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); 144 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); 145 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); 146 | 147 | 148 | /* }====================================================== */ 149 | 150 | 151 | /* compatibility with ref system */ 152 | 153 | /* pre-defined references */ 154 | #define LUA_NOREF (-2) 155 | #define LUA_REFNIL (-1) 156 | 157 | #define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ 158 | (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) 159 | 160 | #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) 161 | 162 | #define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) 163 | 164 | 165 | #define luaL_reg luaL_Reg 166 | 167 | #endif 168 | -------------------------------------------------------------------------------- /win64luajit/lua.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ 3 | ** Lua - An Extensible Extension Language 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 5 | ** See Copyright Notice at the end of this file 6 | */ 7 | 8 | 9 | #ifndef lua_h 10 | #define lua_h 11 | 12 | #include 13 | #include 14 | 15 | 16 | #include "luaconf.h" 17 | 18 | 19 | #define LUA_VERSION "Lua 5.1" 20 | #define LUA_RELEASE "Lua 5.1.4" 21 | #define LUA_VERSION_NUM 501 22 | #define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" 23 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" 24 | 25 | 26 | /* mark for precompiled code (`Lua') */ 27 | #define LUA_SIGNATURE "\033Lua" 28 | 29 | /* option for multiple returns in `lua_pcall' and `lua_call' */ 30 | #define LUA_MULTRET (-1) 31 | 32 | 33 | /* 34 | ** pseudo-indices 35 | */ 36 | #define LUA_REGISTRYINDEX (-10000) 37 | #define LUA_ENVIRONINDEX (-10001) 38 | #define LUA_GLOBALSINDEX (-10002) 39 | #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) 40 | 41 | 42 | /* thread status; 0 is OK */ 43 | #define LUA_YIELD 1 44 | #define LUA_ERRRUN 2 45 | #define LUA_ERRSYNTAX 3 46 | #define LUA_ERRMEM 4 47 | #define LUA_ERRERR 5 48 | 49 | 50 | typedef struct lua_State lua_State; 51 | 52 | typedef int (*lua_CFunction) (lua_State *L); 53 | 54 | 55 | /* 56 | ** functions that read/write blocks when loading/dumping Lua chunks 57 | */ 58 | typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); 59 | 60 | typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); 61 | 62 | 63 | /* 64 | ** prototype for memory-allocation functions 65 | */ 66 | typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); 67 | 68 | 69 | /* 70 | ** basic types 71 | */ 72 | #define LUA_TNONE (-1) 73 | 74 | #define LUA_TNIL 0 75 | #define LUA_TBOOLEAN 1 76 | #define LUA_TLIGHTUSERDATA 2 77 | #define LUA_TNUMBER 3 78 | #define LUA_TSTRING 4 79 | #define LUA_TTABLE 5 80 | #define LUA_TFUNCTION 6 81 | #define LUA_TUSERDATA 7 82 | #define LUA_TTHREAD 8 83 | 84 | 85 | 86 | /* minimum Lua stack available to a C function */ 87 | #define LUA_MINSTACK 20 88 | 89 | 90 | /* 91 | ** generic extra include file 92 | */ 93 | #if defined(LUA_USER_H) 94 | #include LUA_USER_H 95 | #endif 96 | 97 | 98 | /* type of numbers in Lua */ 99 | typedef LUA_NUMBER lua_Number; 100 | 101 | 102 | /* type for integer functions */ 103 | typedef LUA_INTEGER lua_Integer; 104 | 105 | 106 | 107 | /* 108 | ** state manipulation 109 | */ 110 | LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); 111 | LUA_API void (lua_close) (lua_State *L); 112 | LUA_API lua_State *(lua_newthread) (lua_State *L); 113 | 114 | LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); 115 | 116 | 117 | /* 118 | ** basic stack manipulation 119 | */ 120 | LUA_API int (lua_gettop) (lua_State *L); 121 | LUA_API void (lua_settop) (lua_State *L, int idx); 122 | LUA_API void (lua_pushvalue) (lua_State *L, int idx); 123 | LUA_API void (lua_remove) (lua_State *L, int idx); 124 | LUA_API void (lua_insert) (lua_State *L, int idx); 125 | LUA_API void (lua_replace) (lua_State *L, int idx); 126 | LUA_API int (lua_checkstack) (lua_State *L, int sz); 127 | 128 | LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); 129 | 130 | 131 | /* 132 | ** access functions (stack -> C) 133 | */ 134 | 135 | LUA_API int (lua_isnumber) (lua_State *L, int idx); 136 | LUA_API int (lua_isstring) (lua_State *L, int idx); 137 | LUA_API int (lua_iscfunction) (lua_State *L, int idx); 138 | LUA_API int (lua_isuserdata) (lua_State *L, int idx); 139 | LUA_API int (lua_type) (lua_State *L, int idx); 140 | LUA_API const char *(lua_typename) (lua_State *L, int tp); 141 | 142 | LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); 143 | LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); 144 | LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); 145 | 146 | LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); 147 | LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); 148 | LUA_API int (lua_toboolean) (lua_State *L, int idx); 149 | LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); 150 | LUA_API size_t (lua_objlen) (lua_State *L, int idx); 151 | LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); 152 | LUA_API void *(lua_touserdata) (lua_State *L, int idx); 153 | LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); 154 | LUA_API const void *(lua_topointer) (lua_State *L, int idx); 155 | 156 | 157 | /* 158 | ** push functions (C -> stack) 159 | */ 160 | LUA_API void (lua_pushnil) (lua_State *L); 161 | LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); 162 | LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); 163 | LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); 164 | LUA_API void (lua_pushstring) (lua_State *L, const char *s); 165 | LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, 166 | va_list argp); 167 | LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); 168 | LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); 169 | LUA_API void (lua_pushboolean) (lua_State *L, int b); 170 | LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); 171 | LUA_API int (lua_pushthread) (lua_State *L); 172 | 173 | 174 | /* 175 | ** get functions (Lua -> stack) 176 | */ 177 | LUA_API void (lua_gettable) (lua_State *L, int idx); 178 | LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); 179 | LUA_API void (lua_rawget) (lua_State *L, int idx); 180 | LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); 181 | LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); 182 | LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); 183 | LUA_API int (lua_getmetatable) (lua_State *L, int objindex); 184 | LUA_API void (lua_getfenv) (lua_State *L, int idx); 185 | 186 | 187 | /* 188 | ** set functions (stack -> Lua) 189 | */ 190 | LUA_API void (lua_settable) (lua_State *L, int idx); 191 | LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); 192 | LUA_API void (lua_rawset) (lua_State *L, int idx); 193 | LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); 194 | LUA_API int (lua_setmetatable) (lua_State *L, int objindex); 195 | LUA_API int (lua_setfenv) (lua_State *L, int idx); 196 | 197 | 198 | /* 199 | ** `load' and `call' functions (load and run Lua code) 200 | */ 201 | LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); 202 | LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); 203 | LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); 204 | LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, 205 | const char *chunkname); 206 | 207 | LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); 208 | 209 | 210 | /* 211 | ** coroutine functions 212 | */ 213 | LUA_API int (lua_yield) (lua_State *L, int nresults); 214 | LUA_API int (lua_resume) (lua_State *L, int narg); 215 | LUA_API int (lua_status) (lua_State *L); 216 | 217 | /* 218 | ** garbage-collection function and options 219 | */ 220 | 221 | #define LUA_GCSTOP 0 222 | #define LUA_GCRESTART 1 223 | #define LUA_GCCOLLECT 2 224 | #define LUA_GCCOUNT 3 225 | #define LUA_GCCOUNTB 4 226 | #define LUA_GCSTEP 5 227 | #define LUA_GCSETPAUSE 6 228 | #define LUA_GCSETSTEPMUL 7 229 | 230 | LUA_API int (lua_gc) (lua_State *L, int what, int data); 231 | 232 | 233 | /* 234 | ** miscellaneous functions 235 | */ 236 | 237 | LUA_API int (lua_error) (lua_State *L); 238 | 239 | LUA_API int (lua_next) (lua_State *L, int idx); 240 | 241 | LUA_API void (lua_concat) (lua_State *L, int n); 242 | 243 | LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); 244 | LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); 245 | 246 | 247 | 248 | /* 249 | ** =============================================================== 250 | ** some useful macros 251 | ** =============================================================== 252 | */ 253 | 254 | #define lua_pop(L,n) lua_settop(L, -(n)-1) 255 | 256 | #define lua_newtable(L) lua_createtable(L, 0, 0) 257 | 258 | #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) 259 | 260 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) 261 | 262 | #define lua_strlen(L,i) lua_objlen(L, (i)) 263 | 264 | #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) 265 | #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) 266 | #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) 267 | #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) 268 | #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) 269 | #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) 270 | #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) 271 | #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) 272 | 273 | #define lua_pushliteral(L, s) \ 274 | lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) 275 | 276 | #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) 277 | #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) 278 | 279 | #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) 280 | 281 | 282 | 283 | /* 284 | ** compatibility macros and functions 285 | */ 286 | 287 | #define lua_open() luaL_newstate() 288 | 289 | #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) 290 | 291 | #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) 292 | 293 | #define lua_Chunkreader lua_Reader 294 | #define lua_Chunkwriter lua_Writer 295 | 296 | 297 | /* hack */ 298 | LUA_API void lua_setlevel (lua_State *from, lua_State *to); 299 | 300 | 301 | /* 302 | ** {====================================================================== 303 | ** Debug API 304 | ** ======================================================================= 305 | */ 306 | 307 | 308 | /* 309 | ** Event codes 310 | */ 311 | #define LUA_HOOKCALL 0 312 | #define LUA_HOOKRET 1 313 | #define LUA_HOOKLINE 2 314 | #define LUA_HOOKCOUNT 3 315 | #define LUA_HOOKTAILRET 4 316 | 317 | 318 | /* 319 | ** Event masks 320 | */ 321 | #define LUA_MASKCALL (1 << LUA_HOOKCALL) 322 | #define LUA_MASKRET (1 << LUA_HOOKRET) 323 | #define LUA_MASKLINE (1 << LUA_HOOKLINE) 324 | #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) 325 | 326 | typedef struct lua_Debug lua_Debug; /* activation record */ 327 | 328 | 329 | /* Functions to be called by the debuger in specific events */ 330 | typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); 331 | 332 | 333 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); 334 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); 335 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); 336 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); 337 | LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); 338 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); 339 | LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); 340 | LUA_API lua_Hook lua_gethook (lua_State *L); 341 | LUA_API int lua_gethookmask (lua_State *L); 342 | LUA_API int lua_gethookcount (lua_State *L); 343 | 344 | /* From Lua 5.2. */ 345 | LUA_API void *lua_upvalueid (lua_State *L, int idx, int n); 346 | LUA_API void lua_upvaluejoin (lua_State *L, int idx1, int n1, int idx2, int n2); 347 | LUA_API int lua_loadx (lua_State *L, lua_Reader reader, void *dt, 348 | const char *chunkname, const char *mode); 349 | 350 | 351 | struct lua_Debug { 352 | int event; 353 | const char *name; /* (n) */ 354 | const char *namewhat; /* (n) `global', `local', `field', `method' */ 355 | const char *what; /* (S) `Lua', `C', `main', `tail' */ 356 | const char *source; /* (S) */ 357 | int currentline; /* (l) */ 358 | int nups; /* (u) number of upvalues */ 359 | int linedefined; /* (S) */ 360 | int lastlinedefined; /* (S) */ 361 | char short_src[LUA_IDSIZE]; /* (S) */ 362 | /* private part */ 363 | int i_ci; /* active function */ 364 | }; 365 | 366 | /* }====================================================================== */ 367 | 368 | 369 | /****************************************************************************** 370 | * Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. 371 | * 372 | * Permission is hereby granted, free of charge, to any person obtaining 373 | * a copy of this software and associated documentation files (the 374 | * "Software"), to deal in the Software without restriction, including 375 | * without limitation the rights to use, copy, modify, merge, publish, 376 | * distribute, sublicense, and/or sell copies of the Software, and to 377 | * permit persons to whom the Software is furnished to do so, subject to 378 | * the following conditions: 379 | * 380 | * The above copyright notice and this permission notice shall be 381 | * included in all copies or substantial portions of the Software. 382 | * 383 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 384 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 385 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 386 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 387 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 388 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 389 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 390 | ******************************************************************************/ 391 | 392 | 393 | #endif 394 | -------------------------------------------------------------------------------- /win64luajit/lua.hpp: -------------------------------------------------------------------------------- 1 | // C++ wrapper for LuaJIT header files. 2 | 3 | extern "C" { 4 | #include "lua.h" 5 | #include "lauxlib.h" 6 | #include "lualib.h" 7 | #include "luajit.h" 8 | } 9 | 10 | -------------------------------------------------------------------------------- /win64luajit/lua51.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/medaeus245/node-lua/13b1b830210256fc6bd24502ec23e5b63b07afd6/win64luajit/lua51.dll -------------------------------------------------------------------------------- /win64luajit/lua51.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/medaeus245/node-lua/13b1b830210256fc6bd24502ec23e5b63b07afd6/win64luajit/lua51.lib -------------------------------------------------------------------------------- /win64luajit/luaconf.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Configuration header. 3 | ** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef luaconf_h 7 | #define luaconf_h 8 | 9 | #ifndef WINVER 10 | #define WINVER 0x0501 11 | #endif 12 | #include 13 | #include 14 | 15 | /* Default path for loading Lua and C modules with require(). */ 16 | #if defined(_WIN32) 17 | /* 18 | ** In Windows, any exclamation mark ('!') in the path is replaced by the 19 | ** path of the directory of the executable file of the current process. 20 | */ 21 | #define LUA_LDIR "!\\lua\\" 22 | #define LUA_CDIR "!\\" 23 | #define LUA_PATH_DEFAULT \ 24 | ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" 25 | #define LUA_CPATH_DEFAULT \ 26 | ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" 27 | #else 28 | /* 29 | ** Note to distribution maintainers: do NOT patch the following lines! 30 | ** Please read ../doc/install.html#distro and pass PREFIX=/usr instead. 31 | */ 32 | #ifndef LUA_MULTILIB 33 | #define LUA_MULTILIB "lib" 34 | #endif 35 | #ifndef LUA_LMULTILIB 36 | #define LUA_LMULTILIB "lib" 37 | #endif 38 | #define LUA_LROOT "/usr/local" 39 | #define LUA_LUADIR "/lua/5.1/" 40 | #define LUA_LJDIR "/luajit-2.0.3/" 41 | 42 | #ifdef LUA_ROOT 43 | #define LUA_JROOT LUA_ROOT 44 | #define LUA_RLDIR LUA_ROOT "/share" LUA_LUADIR 45 | #define LUA_RCDIR LUA_ROOT "/" LUA_MULTILIB LUA_LUADIR 46 | #define LUA_RLPATH ";" LUA_RLDIR "?.lua;" LUA_RLDIR "?/init.lua" 47 | #define LUA_RCPATH ";" LUA_RCDIR "?.so" 48 | #else 49 | #define LUA_JROOT LUA_LROOT 50 | #define LUA_RLPATH 51 | #define LUA_RCPATH 52 | #endif 53 | 54 | #define LUA_JPATH ";" LUA_JROOT "/share" LUA_LJDIR "?.lua" 55 | #define LUA_LLDIR LUA_LROOT "/share" LUA_LUADIR 56 | #define LUA_LCDIR LUA_LROOT "/" LUA_LMULTILIB LUA_LUADIR 57 | #define LUA_LLPATH ";" LUA_LLDIR "?.lua;" LUA_LLDIR "?/init.lua" 58 | #define LUA_LCPATH1 ";" LUA_LCDIR "?.so" 59 | #define LUA_LCPATH2 ";" LUA_LCDIR "loadall.so" 60 | 61 | #define LUA_PATH_DEFAULT "./?.lua" LUA_JPATH LUA_LLPATH LUA_RLPATH 62 | #define LUA_CPATH_DEFAULT "./?.so" LUA_LCPATH1 LUA_RCPATH LUA_LCPATH2 63 | #endif 64 | 65 | /* Environment variable names for path overrides and initialization code. */ 66 | #define LUA_PATH "LUA_PATH" 67 | #define LUA_CPATH "LUA_CPATH" 68 | #define LUA_INIT "LUA_INIT" 69 | 70 | /* Special file system characters. */ 71 | #if defined(_WIN32) 72 | #define LUA_DIRSEP "\\" 73 | #else 74 | #define LUA_DIRSEP "/" 75 | #endif 76 | #define LUA_PATHSEP ";" 77 | #define LUA_PATH_MARK "?" 78 | #define LUA_EXECDIR "!" 79 | #define LUA_IGMARK "-" 80 | #define LUA_PATH_CONFIG \ 81 | LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" \ 82 | LUA_EXECDIR "\n" LUA_IGMARK 83 | 84 | /* Quoting in error messages. */ 85 | #define LUA_QL(x) "'" x "'" 86 | #define LUA_QS LUA_QL("%s") 87 | 88 | /* Various tunables. */ 89 | #define LUAI_MAXSTACK 65500 /* Max. # of stack slots for a thread (<64K). */ 90 | #define LUAI_MAXCSTACK 8000 /* Max. # of stack slots for a C func (<10K). */ 91 | #define LUAI_GCPAUSE 200 /* Pause GC until memory is at 200%. */ 92 | #define LUAI_GCMUL 200 /* Run GC at 200% of allocation speed. */ 93 | #define LUA_MAXCAPTURES 32 /* Max. pattern captures. */ 94 | 95 | /* Compatibility with older library function names. */ 96 | #define LUA_COMPAT_MOD /* OLD: math.mod, NEW: math.fmod */ 97 | #define LUA_COMPAT_GFIND /* OLD: string.gfind, NEW: string.gmatch */ 98 | 99 | /* Configuration for the frontend (the luajit executable). */ 100 | #if defined(luajit_c) 101 | #define LUA_PROGNAME "luajit" /* Fallback frontend name. */ 102 | #define LUA_PROMPT "> " /* Interactive prompt. */ 103 | #define LUA_PROMPT2 ">> " /* Continuation prompt. */ 104 | #define LUA_MAXINPUT 512 /* Max. input line length. */ 105 | #endif 106 | 107 | /* Note: changing the following defines breaks the Lua 5.1 ABI. */ 108 | #define LUA_INTEGER ptrdiff_t 109 | #define LUA_IDSIZE 60 /* Size of lua_Debug.short_src. */ 110 | /* 111 | ** Size of lauxlib and io.* on-stack buffers. Weird workaround to avoid using 112 | ** unreasonable amounts of stack space, but still retain ABI compatibility. 113 | ** Blame Lua for depending on BUFSIZ in the ABI, blame **** for wrecking it. 114 | */ 115 | #define LUAL_BUFFERSIZE (BUFSIZ > 16384 ? 8192 : BUFSIZ) 116 | 117 | /* The following defines are here only for compatibility with luaconf.h 118 | ** from the standard Lua distribution. They must not be changed for LuaJIT. 119 | */ 120 | #define LUA_NUMBER_DOUBLE 121 | #define LUA_NUMBER double 122 | #define LUAI_UACNUMBER double 123 | #define LUA_NUMBER_SCAN "%lf" 124 | #define LUA_NUMBER_FMT "%.14g" 125 | #define lua_number2str(s, n) sprintf((s), LUA_NUMBER_FMT, (n)) 126 | #define LUAI_MAXNUMBER2STR 32 127 | #define LUA_INTFRMLEN "l" 128 | #define LUA_INTFRM_T long 129 | 130 | /* Linkage of public API functions. */ 131 | #if defined(LUA_BUILD_AS_DLL) 132 | #if defined(LUA_CORE) || defined(LUA_LIB) 133 | #define LUA_API __declspec(dllexport) 134 | #else 135 | #define LUA_API __declspec(dllimport) 136 | #endif 137 | #else 138 | #define LUA_API extern 139 | #endif 140 | 141 | #define LUALIB_API LUA_API 142 | 143 | /* Support for internal assertions. */ 144 | #if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK) 145 | #include 146 | #endif 147 | #ifdef LUA_USE_ASSERT 148 | #define lua_assert(x) assert(x) 149 | #endif 150 | #ifdef LUA_USE_APICHECK 151 | #define luai_apicheck(L, o) { (void)L; assert(o); } 152 | #else 153 | #define luai_apicheck(L, o) { (void)L; } 154 | #endif 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /win64luajit/luajit.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ 3 | ** 4 | ** Copyright (C) 2005-2014 Mike Pall. All rights reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining 7 | ** a copy of this software and associated documentation files (the 8 | ** "Software"), to deal in the Software without restriction, including 9 | ** without limitation the rights to use, copy, modify, merge, publish, 10 | ** distribute, sublicense, and/or sell copies of the Software, and to 11 | ** permit persons to whom the Software is furnished to do so, subject to 12 | ** the following conditions: 13 | ** 14 | ** The above copyright notice and this permission notice shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | ** 25 | ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ] 26 | */ 27 | 28 | #ifndef _LUAJIT_H 29 | #define _LUAJIT_H 30 | 31 | #include "lua.h" 32 | 33 | #define LUAJIT_VERSION "LuaJIT 2.0.3" 34 | #define LUAJIT_VERSION_NUM 20003 /* Version 2.0.3 = 02.00.03. */ 35 | #define LUAJIT_VERSION_SYM luaJIT_version_2_0_3 36 | #define LUAJIT_COPYRIGHT "Copyright (C) 2005-2014 Mike Pall" 37 | #define LUAJIT_URL "http://luajit.org/" 38 | 39 | /* Modes for luaJIT_setmode. */ 40 | #define LUAJIT_MODE_MASK 0x00ff 41 | 42 | enum { 43 | LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */ 44 | LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */ 45 | 46 | LUAJIT_MODE_FUNC, /* Change mode for a function. */ 47 | LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */ 48 | LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */ 49 | 50 | LUAJIT_MODE_TRACE, /* Flush a compiled trace. */ 51 | 52 | LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */ 53 | 54 | LUAJIT_MODE_MAX 55 | }; 56 | 57 | /* Flags or'ed in to the mode. */ 58 | #define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */ 59 | #define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */ 60 | #define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */ 61 | 62 | /* LuaJIT public C API. */ 63 | 64 | /* Control the JIT engine. */ 65 | LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode); 66 | 67 | /* Enforce (dynamic) linker error for version mismatches. Call from main. */ 68 | LUA_API void LUAJIT_VERSION_SYM(void); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /win64luajit/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Standard library header. 3 | ** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LUALIB_H 7 | #define _LUALIB_H 8 | 9 | #include "lua.h" 10 | 11 | #define LUA_FILEHANDLE "FILE*" 12 | 13 | #define LUA_COLIBNAME "coroutine" 14 | #define LUA_MATHLIBNAME "math" 15 | #define LUA_STRLIBNAME "string" 16 | #define LUA_TABLIBNAME "table" 17 | #define LUA_IOLIBNAME "io" 18 | #define LUA_OSLIBNAME "os" 19 | #define LUA_LOADLIBNAME "package" 20 | #define LUA_DBLIBNAME "debug" 21 | #define LUA_BITLIBNAME "bit" 22 | #define LUA_JITLIBNAME "jit" 23 | #define LUA_FFILIBNAME "ffi" 24 | 25 | LUALIB_API int luaopen_base(lua_State *L); 26 | LUALIB_API int luaopen_math(lua_State *L); 27 | LUALIB_API int luaopen_string(lua_State *L); 28 | LUALIB_API int luaopen_table(lua_State *L); 29 | LUALIB_API int luaopen_io(lua_State *L); 30 | LUALIB_API int luaopen_os(lua_State *L); 31 | LUALIB_API int luaopen_package(lua_State *L); 32 | LUALIB_API int luaopen_debug(lua_State *L); 33 | LUALIB_API int luaopen_bit(lua_State *L); 34 | LUALIB_API int luaopen_jit(lua_State *L); 35 | LUALIB_API int luaopen_ffi(lua_State *L); 36 | 37 | LUALIB_API void luaL_openlibs(lua_State *L); 38 | 39 | #ifndef lua_assert 40 | #define lua_assert(x) ((void)0) 41 | #endif 42 | 43 | #endif 44 | --------------------------------------------------------------------------------