在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):brettlangdon/NodeLua开源软件地址(OpenSource Url):https://github.com/brettlangdon/NodeLua开源编程语言(OpenSource Language):C++ 97.0%开源软件介绍(OpenSource Introduction):NodeLuaThis project is no longer maintained. NodeLua is a module to expose Lua bindings to Node.JS. This is still a work in progress, collaborators welcome. InstallRequires Lua 5.1, will not work with 5.2 Lua and it's C libraries are required for this module to work. npm install nodelua var nodelua = require('nodelua'); Environment VariablesThese two environment variables should really only be used when there are installation problems
Installation ProblemsTo try and narrow down where the error is coming from try running the following commands: $ find /usr/include /usr/local/include -name lua.h | sed s/lua.h//
/usr/include/lua5.1/
$ pkg-config --libs-only-l --silence-errors lua || pkg-config --libs-only-l --silence-errors lua5.1
-llua5.1 If instead they show nothing or an error then there are a few possible explanations:
APINodeLuaThe var lua = new nodelua.LuaState('lua') -- STATUS
-- GC
-- INFO
LuaStateThe -- new LuaState(name)When creating a new -- getName()Returns the name provided when creating creating the -- doFile(file_name, callback)The lua.doFile('test.lua', function(error, ret_value){
if(!error && ret_value){
console.dir(ret_value);
} else{
console.error(error);
}
}); -- doFileSync(file_name)This is the synchronous version of var ret_value = lua.doFileSync('test.lua');
console.dir(ret_value); -- doString(lua_code, callback)The lua.doString("print('Hello, Lua')", function(error, ret_value){
if(!error && ret_value){
console.dir(ret_value);
} else{
console.error(error);
}
}); -- doStringSync(lua_code)This is the synchronous version of var ret_value = lua.doString("return 5");
console.dir(ret_value); -- setGlobal(name, value)The lua.setGlobal('test', 'value'); -- getGlobal(name)The console.log(lua.getGlobal('test')); -- registerFunction(name, func)
lua.registerFunction('add_them', function(a, b){
return a + b;
});
var ret_value = lua.doStringSync('return add_them(2, 4)');
console.dir(ret_value); -- status(callback)
lua.status(function(code){
if(code == nodelua.STATUS.ERRSYNTAX){
console.error('Lua Syntax Error');
}
}); -- statusSync()This is the synchronous version of var code = lua.statusSync();
console.dir(code); -- collectGarbage(GC_CODE, callback)
lua.collectGarbage(nodelua.GC.COLLECT, function(code){
console.dir(code);
}); -- collectGarbageSync(GC_CODE)This is the synchronous version of var code = lua.collectGarbageSync(nodelua.GC.COLLECT);
console.dir(code); -- push(value)Push lua.push(5); -- pop(num)Pop lua.pop(5); -- getTop()Return the number of elements on the Lua stack. var num = lua.getTop(); -- setTop(index)Set the top of the Lua stack to lua.setTop(3); -- replace(index)Replaces the top stack element into the specified lua.replace(3); -- close()
ExampleSee var nodelua = require('nodelua');
var lua = new nodelua.LuaState('example');
lua.registerFunction('add_them', function(a, b){
return a + b;
});
lua.doFile('some_file.lua', function(error, ret_value){
console.dir(lua.getGlobal('some_var'));
}); LicenseThe MIT License (MIT) Copyright (c) 2012 Brett Langdon [email protected] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论