Created
September 30, 2020 22:40
-
-
Save edubart/0662eb5a67efdba7eb8bdf5fb1e75fb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##[=[ | |
linklib 'lua' | |
cinclude '<lua.h>' | |
cinclude '<lauxlib.h>' | |
cinclude '<lualib.h>' | |
local ccdefs = require 'nelua.ccompiler'.get_cc_defines('<lua.h>') | |
static_assert(ccdefs.LUA_VERSION_NUM == 504, 'unsupported Lua version') | |
local c2nelua = { | |
['double'] = float64, | |
['ptrdiff_t'] = cptrdiff, | |
["int"] = cint, | |
["long"] = clong, | |
['intptr_t'] = isize, | |
["__int64"] = int64, | |
["long long"] = clonglong, | |
["unsigned long"] = culong, | |
["unsigned __int64"] = yint64, | |
["unsigned int"] = cuint, | |
["unsigned long long"] = culonglong, | |
} | |
local LUA_NUMBER = c2nelua[ccdefs.LUA_NUMBER] | |
local LUA_INTEGER = c2nelua[ccdefs.LUA_INTEGER] | |
local LUA_UNSIGNED = c2nelua["unsigned " .. ccdefs[ccdefs[ccdefs.LUA_UNSIGNED:match("unsigned (%S+)$")]]] | |
local LUA_KCONTEXT = c2nelua[ccdefs.LUA_KCONTEXT] | |
local LUA_IDSIZE = ccdefs.LUA_IDSIZE | |
]=]## | |
global lua_State <cimport, nodecl> = @record{} | |
global luaL_Buffer <cimport, nodecl> = @record{} | |
global lua_Number = #[LUA_NUMBER]# | |
global lua_Integer = #[LUA_INTEGER]# | |
global lua_Unsigned = #[LUA_UNSIGNED]# | |
global lua_KContext = #[LUA_KCONTEXT]# | |
global lua_CFunction <cimport, nodecl> = @function(L: *lua_State): cint | |
global lua_KFunction <cimport, nodecl> = @function(L: *lua_State, status: cint, ctx: lua_KContext): cint | |
global lua_Reader <cimport, nodecl> = @function(L: *lua_State, ud: pointer, sz: *csize): cstring | |
global lua_Writer <cimport, nodecl> = @function(L: *lua_State, p: pointer, sz: csize, ud: pointer): cint | |
global lua_Alloc <cimport, nodecl> = @function(ud: pointer, ptr: pointer, osize: csize, nsize: csize): pointer | |
global lua_WarnFunction <cimport, nodecl> = @function(ud: pointer, msg: cstring, tocont: cint) | |
global lua_Debug <cimport, nodecl> = @record{ | |
event: cint, | |
name: cstring, | |
namewhat: cstring, | |
what: cstring, | |
source: cstring, | |
srclen: csize, | |
currentline: cint, | |
linedefined: cint, | |
lastlinedefined: cint, | |
nups: cuchar, | |
nparams: cuchar, | |
isvararg: cchar, | |
istailcall: cchar, | |
ftransfer: cushort, | |
ntransfer: cushort, | |
short_src: [#[LUA_IDSIZE]#]cchar, | |
i_ci: pointer | |
} | |
global lua_Hook <cimport, nodecl> = @function(L: *lua_State, ar: *lua_Debug) | |
global luaL_Reg <cimport, nodecl> = @record{ | |
name: cstring, | |
func: lua_CFunction | |
} | |
global LUA_VERSUFFIX: cstring <cimport, nodecl> | |
global LUA_VERSION_MAJOR: cstring <cimport, nodecl> | |
global LUA_VERSION_MINOR: cstring <cimport, nodecl> | |
global LUA_VERSION_RELEASE: cstring <cimport, nodecl> | |
global LUA_VERSION_NUM: cint <cimport, nodecl> | |
global LUA_VERSION_RELEASE_NUM: cint <cimport, nodecl> | |
global LUA_VERSION: cstring <cimport, nodecl> | |
global LUA_RELEASE: cstring <cimport, nodecl> | |
global LUA_COPYRIGHT: cstring <cimport, nodecl> | |
global LUA_AUTHORS: cstring <cimport, nodecl> | |
global LUA_MULTRET: cint <cimport, nodecl> | |
global LUA_REGISTRYINDEX: cint <cimport, nodecl> | |
global LUA_OK: cint <cimport, nodecl> | |
global LUA_YIELD: cint <cimport, nodecl> | |
global LUA_ERRRUN: cint <cimport, nodecl> | |
global LUA_ERRSYNTAX: cint <cimport, nodecl> | |
global LUA_ERRMEM: cint <cimport, nodecl> | |
global LUA_ERRERR: cint <cimport, nodecl> | |
global LUA_TNONE: cint <cimport, nodecl> | |
global LUA_TNIL: cint <cimport, nodecl> | |
global LUA_TBOOLEAN: cint <cimport, nodecl> | |
global LUA_TLIGHTUSERDATA: cint <cimport, nodecl> | |
global LUA_TNUMBER: cint <cimport, nodecl> | |
global LUA_TSTRING: cint <cimport, nodecl> | |
global LUA_TTABLE: cint <cimport, nodecl> | |
global LUA_TFUNCTION: cint <cimport, nodecl> | |
global LUA_TUSERDATA: cint <cimport, nodecl> | |
global LUA_TTHREAD: cint <cimport, nodecl> | |
global LUA_NUMTYPES: cint <cimport, nodecl> | |
global LUA_MINSTACK: cint <cimport, nodecl> | |
global LUA_RIDX_MAINTHREAD: cint <cimport, nodecl> | |
global LUA_RIDX_GLOBALS: cint <cimport, nodecl> | |
global LUA_RIDX_LAST: cint <cimport, nodecl> | |
global LUA_OPADD: cint <cimport, nodecl> | |
global LUA_OPSUB: cint <cimport, nodecl> | |
global LUA_OPMUL: cint <cimport, nodecl> | |
global LUA_OPMOD: cint <cimport, nodecl> | |
global LUA_OPPOW: cint <cimport, nodecl> | |
global LUA_OPDIV: cint <cimport, nodecl> | |
global LUA_OPIDIV: cint <cimport, nodecl> | |
global LUA_OPBAND: cint <cimport, nodecl> | |
global LUA_OPBOR: cint <cimport, nodecl> | |
global LUA_OPBXOR: cint <cimport, nodecl> | |
global LUA_OPSHL: cint <cimport, nodecl> | |
global LUA_OPSHR: cint <cimport, nodecl> | |
global LUA_OPUNM: cint <cimport, nodecl> | |
global LUA_OPBNOT: cint <cimport, nodecl> | |
global LUA_OPEQ: cint <cimport, nodecl> | |
global LUA_OPLT: cint <cimport, nodecl> | |
global LUA_OPLE: cint <cimport, nodecl> | |
global LUA_GCSTOP: cint <cimport, nodecl> | |
global LUA_GCRESTART: cint <cimport, nodecl> | |
global LUA_GCCOLLECT: cint <cimport, nodecl> | |
global LUA_GCCOUNT: cint <cimport, nodecl> | |
global LUA_GCCOUNTB: cint <cimport, nodecl> | |
global LUA_GCSTEP: cint <cimport, nodecl> | |
global LUA_GCSETPAUSE: cint <cimport, nodecl> | |
global LUA_GCSETSTEPMUL: cint <cimport, nodecl> | |
global LUA_GCISRUNNING: cint <cimport, nodecl> | |
global LUA_GCGEN: cint <cimport, nodecl> | |
global LUA_GCINC: cint <cimport, nodecl> | |
global LUA_NUMTAGS: cint <cimport, nodecl> | |
global LUA_HOOKCALL: cint <cimport, nodecl> | |
global LUA_HOOKRET: cint <cimport, nodecl> | |
global LUA_HOOKLINE: cint <cimport, nodecl> | |
global LUA_HOOKCOUNT: cint <cimport, nodecl> | |
global LUA_HOOKTAILCALL: cint <cimport, nodecl> | |
global LUA_MASKCALL: cint <cimport, nodecl> | |
global LUA_MASKRET: cint <cimport, nodecl> | |
global LUA_MASKLINE: cint <cimport, nodecl> | |
global LUA_MASKCOUNT: cint <cimport, nodecl> | |
global LUA_ERRFILE: cint <cimport, nodecl> | |
global LUA_NOREF: cint <cimport, nodecl> | |
global LUA_REFNIL: cint <cimport, nodecl> | |
global function lua_strlen(L: *lua_State, idx: cint): lua_Unsigned <cimport, nodecl> end | |
global function lua_objlen(L: *lua_State, idx: cint): lua_Unsigned <cimport, nodecl> end | |
global function lua_equal(L: *lua_State, idx1: cint, idx2: cint): cint <cimport, nodecl> end | |
global function lua_lessthan(L: *lua_State, idx1: cint, idx2: cint): cint <cimport, nodecl> end | |
global function lua_upvalueindex(i: cint): cint <cimport, nodecl> end | |
global function lua_newstate(f: lua_Alloc, ud: pointer): *lua_State <cimport, nodecl> end | |
global function lua_close(L: *lua_State) <cimport, nodecl> end | |
global function lua_newthread(L: *lua_State): *lua_State <cimport, nodecl> end | |
global function lua_resetthread(L: *lua_State): cint <cimport, nodecl> end | |
global function lua_atpanic(L: *lua_State, panicf: lua_CFunction): lua_CFunction <cimport, nodecl> end | |
global function lua_version(L: *lua_State): lua_Number <cimport, nodecl> end | |
global function lua_absindex(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_gettop(L: *lua_State): cint <cimport, nodecl> end | |
global function lua_settop(L: *lua_State, idx: cint) <cimport, nodecl> end | |
global function lua_pushvalue(L: *lua_State, idx: cint) <cimport, nodecl> end | |
global function lua_rotate(L: *lua_State, idx: cint, n: cint) <cimport, nodecl> end | |
global function lua_copy(L: *lua_State, fromidx: cint, toidx: cint) <cimport, nodecl> end | |
global function lua_checkstack(L: *lua_State, n: cint): cint <cimport, nodecl> end | |
global function lua_xmove(from: *lua_State, to: *lua_State, n: cint) <cimport, nodecl> end | |
global function lua_isnumber(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_isstring(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_iscfunction(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_isinteger(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_isuserdata(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_type(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_typename(L: *lua_State, tp: cint): cstring <cimport, nodecl> end | |
global function lua_tonumberx(L: *lua_State, idx: cint, isnum: *cint): lua_Number <cimport, nodecl> end | |
global function lua_tointegerx(L: *lua_State, idx: cint, isnum: *cint): lua_Integer <cimport, nodecl> end | |
global function lua_toboolean(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_tolstring(L: *lua_State, idx: cint, len: *csize): cstring <cimport, nodecl> end | |
global function lua_rawlen(L: *lua_State, idx: cint): lua_Unsigned <cimport, nodecl> end | |
global function lua_tocfunction(L: *lua_State, idx: cint): lua_CFunction <cimport, nodecl> end | |
global function lua_touserdata(L: *lua_State, idx: cint): pointer <cimport, nodecl> end | |
global function lua_tothread(L: *lua_State, idx: cint): *lua_State <cimport, nodecl> end | |
global function lua_topointer(L: *lua_State, idx: cint): pointer <cimport, nodecl> end | |
global function lua_arith(L: *lua_State, op: cint) <cimport, nodecl> end | |
global function lua_rawequal(L: *lua_State, idx1: cint, idx2: cint): cint <cimport, nodecl> end | |
global function lua_compare(L: *lua_State, idx1: cint, idx2: cint, op: cint): cint <cimport, nodecl> end | |
global function lua_pushnil(L: *lua_State) <cimport, nodecl> end | |
global function lua_pushnumber(L: *lua_State, n: lua_Number) <cimport, nodecl> end | |
global function lua_pushinteger(L: *lua_State, n: lua_Integer) <cimport, nodecl> end | |
global function lua_pushlstring(L: *lua_State, s: cstring, len: csize): cstring <cimport, nodecl> end | |
global function lua_pushstring(L: *lua_State, s: cstring): cstring <cimport, nodecl> end | |
--global function lua_pushvfstring(L: *lua_State, fmt: cstring, argp: va_list): cstring <cimport, nodecl> end | |
global function lua_pushfstring(L: *lua_State, fmt: cstring, ...): cstring <cimport, nodecl> end | |
global function lua_pushcclosure(L: *lua_State, fn: lua_CFunction, n: cint) <cimport, nodecl> end | |
global function lua_pushboolean(L: *lua_State, b: cint) <cimport, nodecl> end | |
global function lua_pushlightuserdata(L: *lua_State, p: pointer) <cimport, nodecl> end | |
global function lua_pushthread(L: *lua_State): cint <cimport, nodecl> end | |
global function lua_getglobal(L: *lua_State, name: cstring): cint <cimport, nodecl> end | |
global function lua_gettable(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_getfield(L: *lua_State, idx: cint, k: cstring): cint <cimport, nodecl> end | |
global function lua_geti(L: *lua_State, idx: cint, n: lua_Integer): cint <cimport, nodecl> end | |
global function lua_rawget(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_rawgeti(L: *lua_State, idx: cint, n: lua_Integer): cint <cimport, nodecl> end | |
global function lua_rawgetp(L: *lua_State, idx: cint, p: pointer): cint <cimport, nodecl> end | |
global function lua_createtable(L: *lua_State, narr: cint, nrec: cint) <cimport, nodecl> end | |
global function lua_newuserdatauv(L: *lua_State, sz: csize, nuvalue: cint): pointer <cimport, nodecl> end | |
global function lua_getmetatable(L: *lua_State, objindex: cint): cint <cimport, nodecl> end | |
global function lua_getiuservalue(L: *lua_State, idx: cint, n: cint): cint <cimport, nodecl> end | |
global function lua_setglobal(L: *lua_State, name: cstring) <cimport, nodecl> end | |
global function lua_settable(L: *lua_State, idx: cint) <cimport, nodecl> end | |
global function lua_setfield(L: *lua_State, idx: cint, k: cstring) <cimport, nodecl> end | |
global function lua_seti(L: *lua_State, idx: cint, n: lua_Integer) <cimport, nodecl> end | |
global function lua_rawset(L: *lua_State, idx: cint) <cimport, nodecl> end | |
global function lua_rawseti(L: *lua_State, idx: cint, n: lua_Integer) <cimport, nodecl> end | |
global function lua_rawsetp(L: *lua_State, idx: cint, p: pointer) <cimport, nodecl> end | |
global function lua_setmetatable(L: *lua_State, objindex: cint): cint <cimport, nodecl> end | |
global function lua_setiuservalue(L: *lua_State, idx: cint, n: cint): cint <cimport, nodecl> end | |
global function lua_callk(L: *lua_State, nargs: cint, nresults: cint, ctx: lua_KContext, k: lua_KFunction) <cimport, nodecl> end | |
global function lua_call(L: *lua_State,nargs: cint,nresults: cint) <cimport, nodecl> end | |
global function lua_pcallk(L: *lua_State, nargs: cint, nresults: cint, errfunc: cint, ctx: lua_KContext, k: lua_KFunction): cint <cimport, nodecl> end | |
global function lua_pcall(L: *lua_State,nargs: cint, nresults: cint, errfunc: cint): cint <cimport, nodecl> end | |
global function lua_load(L: *lua_State, reader: lua_Reader, dt: pointer, chunkname: cstring, mode: cstring): cint <cimport, nodecl> end | |
global function lua_dump(L: *lua_State, writer: lua_Writer, data: pointer, strip: cint): cint <cimport, nodecl> end | |
global function lua_yieldk(L: *lua_State, nresults: cint, ctx: lua_KContext, k: lua_KFunction): cint <cimport, nodecl> end | |
global function lua_resume(L: *lua_State, from: *lua_State, narg: cint, nres: *cint): cint <cimport, nodecl> end | |
global function lua_status(L: *lua_State): cint <cimport, nodecl> end | |
global function lua_isyieldable(L: *lua_State): cint <cimport, nodecl> end | |
global function lua_yield(L: *lua_State, nresults: cint): cint <cimport, nodecl> end | |
global function lua_setwarnf(L: *lua_State, f: lua_WarnFunction, ud: pointer) <cimport, nodecl> end | |
global function lua_warning(L: *lua_State, msg: cstring, tocont: cint) <cimport, nodecl> end | |
global function lua_gc(L: *lua_State, what: cint, ...): cint <cimport, nodecl> end | |
global function lua_error(L: *lua_State): cint <cimport, nodecl> end | |
global function lua_next(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_concat(L: *lua_State, n: cint) <cimport, nodecl> end | |
global function lua_len(L: *lua_State, idx: cint) <cimport, nodecl> end | |
global function lua_stringtonumber(L: *lua_State, s: cstring): csize <cimport, nodecl> end | |
global function lua_getallocf(L: *lua_State, ud: *pointer): lua_Alloc <cimport, nodecl> end | |
global function lua_setallocf(L: *lua_State, f: lua_Alloc, ud: pointer) <cimport, nodecl> end | |
global function lua_toclose(L: *lua_State, idx: cint) <cimport, nodecl> end | |
global function lua_getextraspace(L: *lua_State):pointer <cimport, nodecl> end | |
global function lua_tonumber(L: *lua_State, idx: cint): lua_Number <cimport, nodecl> end | |
global function lua_tointeger(L: *lua_State, idx: cint): lua_Integer <cimport, nodecl> end | |
global function lua_pop(L: *lua_State, idx: cint) <cimport, nodecl> end | |
global function lua_newtable(L: *lua_State) <cimport, nodecl> end | |
global function lua_register(L: *lua_State, name: cstring, f: lua_CFunction) <cimport, nodecl> end | |
global function lua_pushcfunction(L: *lua_State, fn: lua_CFunction) <cimport, nodecl> end | |
global function lua_isfunction(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_istable(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_islightuserdata(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_isnil(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_isboolean(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_isthread(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_isnone(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_isnoneornil(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_pushliteral(L: *lua_State, s: cstring): cstring <cimport, nodecl> end | |
global function lua_pushglobaltable(L: *lua_State) <cimport, nodecl> end | |
global function lua_tostring(L: *lua_State, idx: cint): cstring <cimport, nodecl> end | |
global function lua_insert(L: *lua_State, idx: cint) <cimport, nodecl> end | |
global function lua_remove(L: *lua_State, idx: cint) <cimport, nodecl> end | |
global function lua_replace(L: *lua_State, idx: cint) <cimport, nodecl> end | |
global function lua_newuserdata(L: *lua_State, sz: csize): pointer <cimport, nodecl> end | |
global function lua_getuservalue(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_setuservalue(L: *lua_State, idx: cint): cint <cimport, nodecl> end | |
global function lua_getstack(L: *lua_State, level: cint, ar: *lua_Debug): cint <cimport, nodecl> end | |
global function lua_getinfo(L: *lua_State, what: cstring, ar: *lua_Debug): cint <cimport, nodecl> end | |
global function lua_getlocal(L: *lua_State, ar: *lua_Debug, n: cint): cstring <cimport, nodecl> end | |
global function lua_setlocal(L: *lua_State, ar: *lua_Debug, n: cint): cstring <cimport, nodecl> end | |
global function lua_getupvalue(L: *lua_State, funcindex: cint, n: cint): cstring <cimport, nodecl> end | |
global function lua_setupvalue(L: *lua_State, funcindex: cint, n: cint): cstring <cimport, nodecl> end | |
global function lua_upvalueid(L: *lua_State, fidx: cint, n: cint): pointer <cimport, nodecl> end | |
global function lua_upvaluejoin(L: *lua_State, fidx1: cint, n1: cint, fidx2: cint, n2: cint) <cimport, nodecl> end | |
global function lua_sethook(L: *lua_State, func: lua_Hook, mask: cint, count: cint) <cimport, nodecl> end | |
global function lua_gethook(L: *lua_State): lua_Hook <cimport, nodecl> end | |
global function lua_gethookmask(L: *lua_State): cint <cimport, nodecl> end | |
global function lua_gethookcount(L: *lua_State): cint <cimport, nodecl> end | |
global function lua_setcstacklimit(L: *lua_State, limit: cuint): cint <cimport, nodecl> end | |
global function luaL_checkversion_(L: *lua_State, ver: lua_Number, sz: csize) <cimport, nodecl> end | |
global function luaL_checkversion(L: *lua_State) <cimport, nodecl> end | |
global function luaL_getmetafield(L: *lua_State, obj: cint, e: cstring): cint <cimport, nodecl> end | |
global function luaL_callmeta(L: *lua_State, obj: cint, e: cstring): cint <cimport, nodecl> end | |
global function luaL_tolstring(L: *lua_State, idx: cint, len: *csize): cstring <cimport, nodecl> end | |
global function luaL_argerror(L: *lua_State, arg: cint, extramsg: cstring): cint <cimport, nodecl> end | |
global function luaL_typeerror(L: *lua_State, arg: cint, tname: cstring): cint <cimport, nodecl> end | |
global function luaL_checklstring(L: *lua_State, arg: cint, l: *csize): cstring <cimport, nodecl> end | |
global function luaL_optlstring(L: *lua_State, arg: cint, def: cstring, l: *csize): cstring <cimport, nodecl> end | |
global function luaL_checknumber(L: *lua_State, arg: cint): lua_Number <cimport, nodecl> end | |
global function luaL_optnumber(L: *lua_State, arg: cint, def: lua_Number): lua_Number <cimport, nodecl> end | |
global function luaL_checkinteger(L: *lua_State, arg: cint): lua_Integer <cimport, nodecl> end | |
global function luaL_optinteger(L: *lua_State, arg: cint, def: lua_Integer): lua_Integer <cimport, nodecl> end | |
global function luaL_checkstack(L: *lua_State, sz: cint, msg: cstring) <cimport, nodecl> end | |
global function luaL_checktype(L: *lua_State, arg: cint, t: cint) <cimport, nodecl> end | |
global function luaL_checkany(L: *lua_State, arg: cint) <cimport, nodecl> end | |
global function luaL_newmetatable(L: *lua_State, tname: cstring): cint <cimport, nodecl> end | |
global function luaL_setmetatable(L: *lua_State, tname: cstring) <cimport, nodecl> end | |
global function luaL_testudata(L: *lua_State, ud: cint, tname: cstring): pointer <cimport, nodecl> end | |
global function luaL_checkudata(L: *lua_State, ud: cint, tname: cstring): pointer <cimport, nodecl> end | |
global function luaL_where(L: *lua_State, lvl: cint) <cimport, nodecl> end | |
global function luaL_error(L: *lua_State, fmt: cstring, ...): cint <cimport, nodecl> end | |
global function luaL_checkoption(L: *lua_State, arg: cint, def: cstring, lst: *[0]cstring): cint <cimport, nodecl> end | |
global function luaL_fileresult(L: *lua_State, stat: cint, fname: cstring): cint <cimport, nodecl> end | |
global function luaL_execresult(L: *lua_State, stat: cint): cint <cimport, nodecl> end | |
global function luaL_ref(L: *lua_State, t: cint): cint <cimport, nodecl> end | |
global function luaL_unref(L: *lua_State, t: cint, ref: cint) <cimport, nodecl> end | |
global function luaL_loadfilex(L: *lua_State, filename: cstring, mode: cstring): cint <cimport, nodecl> end | |
global function luaL_loadfile(L: *lua_State, filename: cstring): cint <cimport, nodecl> end | |
global function luaL_loadbufferx(L: *lua_State, buff: cstring, sz: csize, name: cstring, mode: cstring): cint <cimport, nodecl> end | |
global function luaL_loadstring(L: *lua_State, s: cstring): cint <cimport, nodecl> end | |
global function luaL_newstate(): *lua_State <cimport, nodecl> end | |
global function luaL_len(L: *lua_State, idx: cint): lua_Integer <cimport, nodecl> end | |
global function luaL_addgsub(b: *luaL_Buffer, s: cstring, p: cstring, r: cstring) <cimport, nodecl> end | |
global function luaL_gsub(L: *lua_State, s: cstring, p: cstring, r: cstring): cstring <cimport, nodecl> end | |
global function luaL_setfuncs(L: *lua_State, l: *luaL_Reg, nup: cint) <cimport, nodecl> end | |
global function luaL_getsubtable(L: *lua_State, idx: cint, fname: cstring): cint <cimport, nodecl> end | |
global function luaL_traceback(L: *lua_State, L1: *lua_State, msg: cstring, level: cint) <cimport, nodecl> end | |
global function luaL_requiref(L: *lua_State, modname: cstring, openf: lua_CFunction, glb: cint) <cimport, nodecl> end | |
global function luaL_newlibtable(L: *lua_State, l: *[0]luaL_Reg) <cimport, nodecl> end | |
global function luaL_newlib(L: *lua_State, l: *[0]luaL_Reg) <cimport, nodecl> end | |
global function luaL_argcheck(L: *lua_State, cond: cint, arg: cint, extramsg: cstring) <cimport, nodecl> end | |
global function luaL_argexpected(L: *lua_State, cond: cint, arg: cint, tname: cstring) <cimport, nodecl> end | |
global function luaL_checkstring(L: *lua_State, arg: cint): cstring <cimport, nodecl> end | |
global function luaL_optstring(L: *lua_State, arg: cint, def: cstring): cstring <cimport, nodecl> end | |
global function luaL_typename(L: *lua_State, idx: cint): cstring <cimport, nodecl> end | |
global function luaL_dofile(L: *lua_State, fn: cstring): cint <cimport, nodecl> end | |
global function luaL_dostring(L: *lua_State, s: cstring): cint <cimport, nodecl> end | |
global function luaL_getmetatable(L: *lua_State, n: cstring): cint <cimport, nodecl> end | |
global function luaL_opt(L: *lua_State, func: auto, arg: cint, dflt: auto) | |
if lua_isnoneornil(L, arg) ~= 0 then return dflt else return func(L, arg) end | |
end | |
global function luaL_loadbuffer(L: *lua_State, buff: cstring, sz: csize, name: cstring): cint <cimport, nodecl> end | |
global function luaL_pushfail(L: *lua_State) <cimport, nodecl> end | |
global function luaL_bufflen(B: *luaL_Buffer): csize <cimport, nodecl> end | |
global function luaL_buffaddr(B: *luaL_Buffer): cstring <cimport, nodecl> end | |
global function luaL_addchar(B: *luaL_Buffer,c: cchar) <cimport, nodecl> end | |
global function luaL_addsize(B: *luaL_Buffer,s: csize) <cimport, nodecl> end | |
global function luaL_buffsub(B: *luaL_Buffer,s: cint) <cimport, nodecl> end | |
global function luaL_buffinit(L: *lua_State, B: *luaL_Buffer) <cimport, nodecl> end | |
global function luaL_prepbuffsize(B: *luaL_Buffer, sz: csize): cstring <cimport, nodecl> end | |
global function luaL_addlstring(B: *luaL_Buffer, s: cstring, l: csize) <cimport, nodecl> end | |
global function luaL_addstring(B: *luaL_Buffer, s: cstring) <cimport, nodecl> end | |
global function luaL_addvalue(B: *luaL_Buffer) <cimport, nodecl> end | |
global function luaL_pushresult(B: *luaL_Buffer) <cimport, nodecl> end | |
global function luaL_pushresultsize(B: *luaL_Buffer, sz: csize) <cimport, nodecl> end | |
global function luaL_buffinitsize(L: *lua_State, B: *luaL_Buffer, sz: csize): cstring <cimport, nodecl> end | |
global function luaL_prepbuffer(B: *luaL_Buffer): cstring <cimport, nodecl> end | |
global function luaopen_base(L: *lua_State): cint <cimport, nodecl> end | |
global function luaopen_coroutine(L: *lua_State): cint <cimport, nodecl> end | |
global function luaopen_table(L: *lua_State): cint <cimport, nodecl> end | |
global function luaopen_io(L: *lua_State): cint <cimport, nodecl> end | |
global function luaopen_os(L: *lua_State): cint <cimport, nodecl> end | |
global function luaopen_string(L: *lua_State): cint <cimport, nodecl> end | |
global function luaopen_utf8(L: *lua_State): cint <cimport, nodecl> end | |
global function luaopen_math(L: *lua_State): cint <cimport, nodecl> end | |
global function luaopen_debug(L: *lua_State): cint <cimport, nodecl> end | |
global function luaopen_package(L: *lua_State): cint <cimport, nodecl> end | |
global function luaL_openlibs(L: *lua_State) <cimport, nodecl> end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'lua' | |
##[[ | |
cflags '-shared -fPIC' | |
pragmas.nogc = true | |
local function table_len(t) | |
local i = 0; | |
for _ in next,t do i = i + 1 end | |
return i | |
end | |
function make_lua_library(librecord) | |
local libmetafields = librecord.value.metafields | |
]] | |
## for name,sym in pairs(libmetafields) do | |
local function #|name|#(L: *lua_State): cint | |
## local argtypes = sym.type.argtypes | |
## local callargs = {} | |
## for i,argtype in ipairs(argtypes) do | |
## if argtype.is_integral then | |
local #|'a'..i|# = lua_tointeger(L, #[i]#) | |
## elseif argtype.is_stringview then | |
local #|'a'..i|# = lua_tostring(L, #[i]#) | |
## end | |
## callargs[i] = aster.Id{'a'..i} | |
## end | |
local func = #[sym]# | |
local ret = #[aster.Call{callargs, aster.Id{'func'}}]# | |
## local rettype = sym.type:get_return_type(1) | |
## if rettype.is_void then | |
return 0 | |
## elseif rettype.is_integral then | |
lua_pushinteger(L, ret) | |
return 1 | |
## elseif rettype.is_stringview then | |
lua_pushlstring(L, ret, #ret) | |
return 1 | |
## end | |
end | |
## end | |
local function nelua_main(argc: cint, argv: *cstring): cint <cimport,nodecl> end | |
local function luaopen_mylib(L: *lua_State): cint <cexport, entrypoint> | |
nelua_main(0, nilptr) | |
-- setup library | |
local libfuncs: luaL_Reg[#[table_len(libmetafields)+1]#] | |
## local i = 0 | |
## for name,sym in pairs(libmetafields) do | |
libfuncs[#[i]#] = {#[name]#, #|name|#} | |
## i = i + 1 | |
## end | |
lua_createtable(L, 0, #libfuncs) | |
luaL_setfuncs(L, &libfuncs[0], 0) | |
return 1 | |
end | |
## end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'luabinder' | |
local mylib = @record{} | |
function mylib.sum(a: integer, b: integer): integer | |
return a + b | |
end | |
function mylib.getstr(): stringview | |
return 'hi' | |
end | |
## make_lua_library(mylib) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local mylib = require 'mylib' | |
print('sum', mylib.sum(1,2)) | |
print(mylib.getstr(1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment