2 Star 17 Fork 3

tanhunu / luajit_aardioLib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
_.aau 5.63 KB
一键复制 编辑 原始数据 按行查看 历史
tanhunu 提交于 2016-06-05 11:33 . 优化了点体积
//luajit 脚本库
luajit = class {
ctor(str){
this.code = str:""
this.L = luaL_newstate()
luaL_openlibs(this.L)
..table.gc(this,"close")
};
getValue = function(varName){
lua_getglobal(this.L, varName);
return this.checkValue(-1);
}
checkValue = function(v = -1){
select(lua_type(this.L,v)) {
case LUA_TBOOLEAN {
return lua_toboolean(this.L,v)
}
case LUA_TLIGHTUSERDATA {
}
case LUA_TNUMBER {
return lua_tonumber(this.L,v)
}
case LUA_TSTRING {
return lua_tolstring(this.L,v,0)
}
case LUA_TTABLE {
}
case LUA_TFUNCTION {
return lua_tocfunction(this.L,v)
}
case LUA_TUSERDATA {
}
case LUA_TTHREAD {
}
}
}
setValue = function(varName,v){
this.pushValue(v)
lua_setglobal(this.L,varName)
}
pushValue = function(...){
var arg = {...}
for(i=1;#arg;1){//压入参数
if(type(arg[i]) = type.number){
lua_pushnumber(this.L, arg[i]);
}
if(type(arg[i]) = type.string){
lua_pushstring(this.L, arg[i]);
}
if(type(arg[i]) = type.boolean){
lua_pushboolean(this.L, arg[i]);
}
if(type(arg[i]) = type.null){
lua_pushnil(this.L, arg[i]);
}
}
return #arg;
}
getFunc = function(funcName,reNum = 0){
return function(...){
var ct,nt = #{...},{}
lua_getglobal(this.L, funcName); // 获取函数,压入栈中
this.pushValue(...)
lua_call(this.L, ct, reNum);//调用
for(i=reNum;1;-1){
..table.push(nt,this.checkValue(-i))
}
return ..table.unpackArgs(nt);
}
}
getTable = function(tabName){
lua_getglobal(this.L, tabName);
var n = luaL_len(L, -1);
for(i=1;n;1){
lua_pushnumber(L, i);
lua_gettable(L, -2);
lua_pop(L, 1)
}
}
register = function(n,f,fm){//注册aauto脚本
var pf = ..raw.tocdecl(function(){
var ct = lua_gettop(this.L)
var args = {}
for(i=ct;1;-1){
..table.push(args,this.checkValue(-i))
}
return this.pushValue(f(..table.unpackArgs(args)));
},"INT(INT L)")
lua_register(this.L,n,pf)
}
run = function(){//执行脚本
luaL_dostring(this.L,this.code)
}
close = function(){
lua_close(this.L);
}
}
namespace luajit{
dll = ..raw.loadDll($"~\lib\luajit\.res\Lua51.dll",,"cdecl")
luaL_newstate = dll.api("luaL_newstate","INT()")
luaL_openlibs = dll.api("luaL_openlibs","INT(INT L)")
luaL_loadfile = dll.api("luaL_loadfile","INT(INT L,string filename)")
lua_pcall = dll.api("lua_pcall","INT(INT L,INT nargs,INT nresults,INT errfunc)")
lua_call = dll.api("lua_call","INT(INT L,INT nargs,INT nresults)")
lua_close = dll.api("lua_close","INT(INT L)")
luaL_loadstring = dll.api("luaL_loadstring","INT(INT L,string s)")
luaL_loadbuffer = dll.api("luaL_loadbuffer","INT(INT L,string buff,INT size,string name)")
luaL_loadbufferx = dll.api("luaL_loadbufferx","(INT L,string buff,INT size,string name,INT mode)")
luaL_register = dll.api("luaL_register","(INT L,string libname,struct l)")
lua_gettop = dll.api("lua_gettop","INT(INT L)")
lua_settop = dll.api("lua_settop","INT(INT L,INT idx)")
lua_tonumber = dll.api("lua_tonumber","double(INT L,INT idx)")
lua_tointeger = dll.api("lua_tointeger","INT(INT L,INT idx)")
lua_tocfunction = dll.api("lua_tocfunction","INT(INT L,INT idx)")
lua_toboolean = dll.api("lua_toboolean","bool(INT L,INT idx)")
lua_tolstring = dll.api("lua_tolstring","string(INT L,INT idx,INT len)")
lua_pushnil = dll.api("lua_pushnil","(INT L,INT idx,INT len)")
lua_pushnumber = dll.api("lua_pushnumber","(INT L,double n)")
lua_pushinteger = dll.api("lua_pushinteger","(INT L,INT n)")
lua_pushstring = dll.api("lua_pushstring","(INT L,string s)")
lua_pushboolean = dll.api("lua_pushboolean","(INT L,bool b)")
lua_gettable = dll.api("lua_gettable","(INT L,INT idx)")
lua_rawget = dll.api("lua_rawget","(INT L,INT idx)")
lua_rawgeti = dll.api("lua_rawgeti","(INT L,INT idx,INT n)")
lua_createtable = dll.api("lua_createtable","(INT L,INT narr,INT nrec)")
lua_settable = dll.api("lua_settable","(INT L,INT idx)")
lua_setfield = dll.api("lua_setfield","(INT L,INT idx,string k)")
lua_getfield = dll.api("lua_getfield","(INT L,INT idx,string k)")
lua_rawset = dll.api("lua_rawset","(INT L,INT idx)")
lua_rawseti = dll.api("lua_rawseti","(INT L,INT idx,INT n)")
lua_type = dll.api("lua_type","INT(INT L,INT idx)")
lua_objlen = dll.api("lua_objlen","INT(INT L,INT idx,INT n)")
lua_next = dll.api("lua_next","INT(INT L,INT idx,INT n)")
lua_remove = dll.api("lua_remove","(INT L,INT idx)")
lua_pushcclosure = dll.api("lua_pushcclosure","(INT L,pointer f,INT n)")
lua_pushUserData = dll.api("lua_pushlightuserdata","(INT L,pointer p)")
LUA_REGISTRYINDEX = -10000
LUA_ENVIRONINDEX = -10001
LUA_GLOBALSINDEX = -10002
LUA_YIELD = 1
LUA_ERRRUN = 2
LUA_ERRSYNTAX = 3
LUA_ERRMEM = 4
LUA_ERRERR = 5
LUA_TNONE =-1
LUA_TNIL = 0
LUA_TBOOLEAN = 1
LUA_TLIGHTUSERDATA= 2
LUA_TNUMBER = 3
LUA_TSTRING = 4
LUA_TTABLE = 5
LUA_TFUNCTION = 6
LUA_TUSERDATA = 7
LUA_TTHREAD = 8
lua_doFile = function(L,fn){
luaL_loadfile(L, fn)
lua_pcall(L,0,0,0);
}
luaL_dostring = function(L,s){
luaL_loadstring(L,s)
lua_pcall(L,0,0,0);
}
lua_getglobal = function(L,s){
lua_getfield(L,LUA_GLOBALSINDEX,s)
}
lua_setglobal = function(L,s){
lua_setfield(L,LUA_GLOBALSINDEX,s)
}
lua_upvalueindex = function(i){
return LUA_GLOBALSINDEX-(i)
}
lua_pushcfunction = function(L,f){
lua_pushcclosure(L,f, 0)
}
lua_register = function(L,n,f){
lua_pushcfunction(L,f)
lua_setglobal(L,n)
}
}
Lua
1
https://gitee.com/tanhunu/luajit_aardioLib.git
git@gitee.com:tanhunu/luajit_aardioLib.git
tanhunu
luajit_aardioLib
luajit_aardioLib
master

搜索帮助