Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- by David Vogel (Dadido3, Xaardas)
- ; ########################################## Konstanten ########################################
- #LUA_VERSION_MAJOR = "5"
- #LUA_VERSION_MINOR = "2"
- #LUA_VERSION_NUM = 502
- #LUA_VERSION_RELEASE = "1"
- #LUA_VERSION = "Lua "+#LUA_VERSION_MAJOR+"."+#LUA_VERSION_MINOR
- #LUA_RELEASE = #LUA_VERSION+"."+#LUA_VERSION_RELEASE
- #LUA_COPYRIGHT = #LUA_RELEASE+" Copyright (C) 1994-2012 Lua.org, PUC-Rio"
- #LUA_AUTHORS = "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
- ; mark For precompiled code ('<esc>Lua')
- #LUA_SIGNATURE = "\033Lua"
- ; option For multiple returns in 'lua_pcall' And 'lua_call'
- #LUA_MULTRET = -1
- ; thread status
- #LUA_OK = 0
- #LUA_YIELD = 1
- #LUA_ERRRUN = 2
- #LUA_ERRSYNTAX = 3
- #LUA_ERRMEM = 4
- #LUA_ERRGCMM = 5
- #LUA_ERRERR = 6
- ; basic types
- #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_NUMTAGS = 9
- ; minimum Lua stack available To a C function
- #LUA_MINSTACK = 20
- ; predefined values in the registry
- #LUA_RIDX_MAINTHREAD = 1
- #LUA_RIDX_GLOBALS = 2
- #LUA_RIDX_LAST = #LUA_RIDX_GLOBALS
- ; Comparison And arithmetic functions
- #LUA_OPADD = 0 ; ORDER TM
- #LUA_OPSUB = 1
- #LUA_OPMUL = 2
- #LUA_OPDIV = 3
- #LUA_OPMOD = 4
- #LUA_OPPOW = 5
- #LUA_OPUNM = 6
- #LUA_OPEQ = 0
- #LUA_OPLT = 1
- #LUA_OPLE = 2
- ; garbage-collection function And options
- #LUA_GCSTOP = 0
- #LUA_GCRESTART = 1
- #LUA_GCCOLLECT = 2
- #LUA_GCCOUNT = 3
- #LUA_GCCOUNTB = 4
- #LUA_GCSTEP = 5
- #LUA_GCSETPAUSE = 6
- #LUA_GCSETSTEPMUL = 7
- #LUA_GCSETMAJORINC = 8
- #LUA_GCISRUNNING = 9
- #LUA_GCGEN = 10
- #LUA_GCINC = 11
- ; pseudo-indices
- #LUA_REGISTRYINDEX = (-10000)
- #LUA_ENVIRONINDEX = (-10001)
- #LUA_GLOBALSINDEX = (-10002)
- ; Event codes
- #LUA_HOOKCALL = 0
- #LUA_HOOKRET = 1
- #LUA_HOOKLINE = 2
- #LUA_HOOKCOUNT = 3
- #LUA_HOOKTAILRET = 4
- ; Event masks
- #LUA_MASKCALL = 1 << #LUA_HOOKCALL
- #LUA_MASKRET = 1 << #LUA_HOOKRET
- #LUA_MASKLINE = 1 << #LUA_HOOKLINE
- #LUA_MASKCOUNT = 1 << #LUA_HOOKCOUNT
- ; ########################################## Variablen ##########################################
- ; ########################################## Ladekram ############################################
- ; ########################################## Declares ############################################
- Declare Lua_Do_Function(Function.s, Arguments, Results)
- ; ########################################## Imports ##########################################
- CompilerIf #PB_Compiler_OS = #PB_OS_Windows
- CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
- ;#Lua_Import_Prefix = "_"
- ImportC #Library_Path+"lua52.x86.lib" ; Windows x86
- CompilerElse
- ;#Lua_Import_Prefix = ""
- ImportC #Library_Path+"lua52.x64.lib" ; Windows x64
- CompilerEndIf
- CompilerElse
- CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
- ;#Lua_Import_Prefix = ""
- Import "/usr/lib/libm.so"
- EndImport
- Import "/usr/lib/libdl.so"
- EndImport
- ImportC "../../Librarys/lua52.x86.a" ; Linux x86
- CompilerElse
- ;#Lua_Import_Prefix = ""
- ImportC "../../Librarys/lua52.x64.a" ; Linux x64
- CompilerEndIf
- CompilerEndIf
- ; /*
- ; ** state manipulation
- ; */
- lua_newstate (*f, *ud)
- lua_close (lua_State.i)
- lua_newthread (lua_State.i)
- lua_atpanic (lua_State.i, *panicf)
- ; /*
- ; ** basic stack manipulation
- ; */
- lua_absindex (lua_State.i, idx.l)
- lua_gettop (lua_State.i)
- lua_settop (lua_State.i, idx.l)
- lua_pushvalue (lua_State.i, idx.l)
- lua_remove (lua_State.i, idx.l)
- lua_insert (lua_State.i, idx.l)
- lua_replace (lua_State.i, idx.l)
- lua_copy (lua_State.i, fromidx.l, toidx.l)
- lua_checkstack (lua_State.i, sz.l)
- lua_xmove (lua_State_from.i, lua_State_to.i, n.l)
- ; /*
- ; ** access functions (stack -> C)
- ; */
- lua_isnumber (lua_State.i, idx.l)
- lua_isstring (lua_State.i, idx.l)
- lua_iscfunction (lua_State.i, idx.l)
- lua_isuserdata (lua_State.i, idx.l)
- lua_type (lua_State.i, idx.l)
- lua_typename (lua_State.i, tp.l)
- lua_tonumberx.d (lua_State.i, idx.l, *isnum)
- lua_tointegerx (lua_State.i, idx.l, *isnum)
- lua_tounsignedx (lua_State.i, idx.l, *isnum)
- lua_toboolean (lua_State.i, idx.l)
- lua_tolstring (lua_State.i, idx.l, *len)
- lua_rawlen (lua_State.i, idx.l)
- lua_tocfunction (lua_State.i, idx.l)
- lua_touserdata (lua_State.i, idx.l)
- lua_tothread (lua_State.i, idx.l)
- lua_topointer (lua_State.i, idx.l)
- ; /*
- ; ** Comparison And arithmetic functions
- ; */
- lua_arith (lua_State.i, op.l)
- lua_rawequal (lua_State.i, idx1.l, idx2.l)
- lua_compare (lua_State.i, idx1.l, idx2.l, op.l)
- ; /*
- ; ** push functions (C -> stack)
- ; */
- lua_pushnil (lua_State.i)
- lua_pushnumber (lua_State.i, n.d)
- lua_pushinteger (lua_State.i, n.q)
- lua_pushunsigned (lua_State.i, n.q)
- lua_pushlstring (lua_State.i, string.p-ascii, size.i)
- lua_pushstring (lua_State.i, string.p-ascii)
- ;lua_pushvfstring (lua_State.i, string.p-ascii, *argp)
- ;lua_pushfstring (lua_State.i, string.p-ascii, ...)
- lua_pushcclosure (lua_State.i, *fn, n.l)
- lua_pushboolean (lua_State.i, b.l)
- lua_pushlightuserdata (lua_State.i, *p)
- lua_pushthread (lua_State.i)
- ; /*
- ; ** get functions (Lua -> stack)
- ; */
- lua_getglobal (lua_State.i, *string_var) ; Because of a memory leak with .p-ascii
- lua_gettable (lua_State.i, idx.l)
- lua_getfield (lua_State.i, idx.l, k.p-ascii)
- lua_rawget (lua_State.i, idx.l)
- lua_rawgeti (lua_State.i, idx.l, n.l)
- lua_rawgetp (lua_State.i, idx.l, p.p-ascii)
- lua_createtable (lua_State.i, narr.l, nrec.l)
- lua_newuserdata (lua_State.i, sz.i)
- lua_getmetatable (lua_State.i, objindex.l)
- lua_getuservalue (lua_State.i, idx.l)
- ; /*
- ; ** set functions (stack -> Lua)
- ; */
- lua_setglobal (lua_State.i, var.p-ascii)
- lua_settable (lua_State.i, idx.l)
- lua_setfield (lua_State.i, idx.l, k.p-ascii)
- lua_rawset (lua_State.i, idx.l)
- lua_rawseti (lua_State.i, idx.l, n.l)
- lua_rawsetp (lua_State.i, idx.l, p.p-ascii)
- lua_setmetatable (lua_State.i, objindex.l)
- lua_setuservalue (lua_State.i, idx.l)
- ; /*
- ; ** 'load' And 'call' functions (load And run Lua code)
- ; */
- lua_callk (lua_State.i, nargs.l, nresults.l, ctx.l, *k)
- lua_getctx (lua_State.i, *ctx)
- lua_pcallk (lua_State.i, nargs.l, nresults.l, *errfunc, ctx.l, *k)
- lua_load (lua_State.i, reader.i, *dt, chunkname.p-ascii, mode.p-ascii)
- lua_dump (lua_State.i, writer.i, *data_)
- ; /*
- ; ** coroutine functions
- ; */
- lua_yieldk (lua_State.i, nresults.l, ctx.l, *k)
- lua_resume (lua_State.i, lua_State_from.i, narg.l)
- lua_status (lua_State.i)
- ; /*
- ; ** garbage-collection function And options
- ; */
- lua_gc (lua_State.i, what.l, data_.i)
- ; /*
- ; ** miscellaneous functions
- ; */
- lua_error (lua_State.i)
- lua_next (lua_State.i, idx.l)
- lua_concat (lua_State.i, n.l)
- lua_len (lua_State.i, idx.l)
- lua_getallocf (lua_State.i, *ud)
- lua_setallocf (lua_State.i, *f, *ud)
- ; lualib.h
- luaopen_base (lua_State.i)
- luaopen_coroutine (lua_State.i)
- luaopen_table (lua_State.i)
- luaopen_io (lua_State.i)
- luaopen_os (lua_State.i)
- luaopen_string (lua_State.i)
- luaopen_bit32 (lua_State.i)
- luaopen_math (lua_State.i)
- luaopen_debug (lua_State.i)
- luaopen_package (lua_State.i)
- ; open all previous libraries
- luaL_openlibs (lua_State.i)
- ;lauxlib_h
- luaI_openlib (lua_State.i, libname.p-ascii, *luaL_Reg.l, nup.l)
- luaL_register (lua_State.i, libname.p-ascii, *luaL_Reg.l)
- luaL_getmetafield (lua_State.i, obj.l, e.p-ascii)
- luaL_callmeta (lua_State.i, obj.l, e.p-ascii)
- luaL_typerror (lua_State.i, narg.l, tname.p-ascii)
- luaL_argerror (lua_State.i, numarg.l, extramsg.p-ascii)
- luaL_checklstring (lua_State.i, numarg.l, size.l)
- luaL_optlstring (lua_State.i, numarg.l, def.p-ascii, size.l)
- luaL_checknumber (lua_State.i, numarg.l)
- luaL_optnumber (lua_State.i, narg, LUA_NUMBER.d)
- luaL_checkinteger (lua_State.i, numarg.l)
- luaL_optinteger (lua_State.i, narg.l, LUA_INTEGER.l)
- luaL_checkstack (lua_State.i, sz.l, msg.p-ascii)
- luaL_checktype (lua_State.i, narg.l, t.l)
- luaL_checkany (lua_State.i, narg.l)
- luaL_newmetatable (lua_State.i, tname.p-ascii)
- luaL_checkudata (lua_State.i, ud.l, tname.p-ascii)
- luaL_where (lua_State.i, lvl.l)
- ;luaL_error (lua_State.i, const char *fmt, ...)
- luaL_checkoption (lua_State.i, narg.l, def.p-ascii, *string_array.l)
- luaL_ref (lua_State.i, t.l)
- luaL_unref (lua_State.i, t.l, ref.l)
- ;luaL_loadfile (lua_State.i, filename.p-ascii)
- luaL_loadfilex (lua_State.i, filename.p-ascii, *mode)
- luaL_loadbuffer (lua_State.i, buff.l, size.l, name.p-ascii)
- luaL_loadstring (lua_State.i, string.p-ascii)
- luaL_newstate ()
- luaL_gsub (lua_State.i, s.p-ascii, p.p-ascii, r.p-ascii)
- luaL_findtable (lua_State.i, Index.l, fname.p-ascii)
- luaL_buffinit (lua_State.i, *luaL_Buffer.l)
- luaL_prepbuffer (*luaL_Buffer.l)
- luaL_addlstring (*luaL_Buffer.l, s.p-ascii, size.l)
- luaL_addstring (*luaL_Buffer.l, s.p-ascii)
- luaL_addvalue (*luaL_Buffer.l)
- luaL_pushresult (*luaL_Buffer.l)
- EndImport
- ; ########################################## Macros #############################################
- Macro lua_call(L, n, r)
- lua_callk((L), (n), (r), 0, #Null)
- EndMacro
- Macro lua_pcall(L, n, r, f)
- lua_pcallk((L), (n), (r), (f), 0, #Null)
- EndMacro
- Macro lua_yield(L, n)
- lua_yieldk((L), (n), 0, #Null)
- EndMacro
- Procedure.d lua_tonumber(L, i)
- Protected Value.d = lua_tonumberx((L), (i), #Null)
- CompilerIf #PB_Compiler_OS = #PB_OS_Windows And #PB_Compiler_Processor = #PB_Processor_x64
- EnableASM
- MOVQ Value, XMM0
- DisableASM
- CompilerEndIf
- ProcedureReturn Value
- EndProcedure
- Macro lua_tointeger(L, i)
- lua_tointegerx((L), (i), #Null)
- EndMacro
- Macro lua_tounsigned(L, i)
- lua_tounsignedx((L), (i), #Null)
- EndMacro
- Macro lua_pop(L, n)
- lua_settop((L), -(n)-1)
- EndMacro
- Macro lua_newtable(L)
- lua_createtable((L), 0, 0)
- EndMacro
- Macro lua_register(L, n, f)
- lua_pushcfunction((L), (f))
- lua_setglobal((L), n)
- EndMacro
- Macro lua_pushcfunction(L, f)
- lua_pushcclosure((L), (f), 0)
- EndMacro
- Macro lua_isfunction(L, n)
- (lua_type((L), (n)) = #LUA_TFUNCTION)
- EndMacro
- Macro lua_istable(L, n)
- (lua_type((L), (n)) = #LUA_TTABLE)
- EndMacro
- Macro lua_islightuserdata(L, n)
- (lua_type((L), (n)) = #LUA_TLIGHTUSERDATA)
- EndMacro
- Macro lua_isnil(L, n)
- (lua_type((L), (n)) = #LUA_TNIL)
- EndMacro
- Macro lua_isboolean(L, n)
- (lua_type((L), (n)) = #LUA_TBOOLEAN)
- EndMacro
- Macro lua_isthread(L, n)
- (lua_type((L), (n)) = #LUA_TTHREAD)
- EndMacro
- Macro lua_isnone(L, n)
- (lua_type((L), (n)) = #LUA_TNONE)
- EndMacro
- Macro lua_isnoneornil(L, n)
- (lua_type((L), (n)) <= 0)
- EndMacro
- ;#define lua_pushliteral(L, s) \
- ; lua_pushlstring(L, "" s, (SizeOf(s)/SizeOf(char))-1)
- ;#define lua_pushglobaltable(L) \
- ; lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
- Macro lua_tostring(Result_String, Lua_State, idx)
- *Temp_String = lua_tolstring(Lua_State, idx, #Null)
- If *Temp_String : Result_String = PeekS(*Temp_String, -1, #PB_Ascii) : Else : Result_String = "" : EndIf
- EndMacro
- Macro luaL_dofile(Lua_State, Filename)
- luaL_loadfile(Lua_State, Filename)
- lua_pcall(Lua_State, 0, #LUA_MULTRET, 0)
- EndMacro
- Macro luaL_dostring(Lua_State, String)
- luaL_loadstring(Lua_State, String)
- lua_pcall(Lua_State, 0, #LUA_MULTRET, 0)
- EndMacro
- ;Macro lua_setglobal(Lua_State, String)
- ; lua_setfield(Lua_State, #LUA_GLOBALSINDEX, String)
- ;EndMacro
- ;Macro lua_getglobal(Lua_State, String)
- ; lua_getfield(Lua_State, #LUA_GLOBALSINDEX, String)
- ;EndMacro
- ;Macro lua_call(Lua_State, nargs, nresults)
- ; lua_callk(Lua_State, nargs, nresults, 0, #Null)
- ;EndMacro
- ;Macro lua_pcall(Lua_State, nargs, nresults, lua_errCFunction)
- ; lua_pcallk(Lua_State, nargs, nresults, lua_errCFunction, 0, #Null)
- ;EndMacro
- Macro luaL_loadfile(L, f)
- luaL_loadfilex((L),f,#Null)
- EndMacro
- Macro lua_getglobal_fixed(L, String) ; Because of a memory leak with .p-ascii
- Protected *String_Buffer = AllocateMemory(StringByteLength(String, #PB_Ascii)+1)
- If *String_Buffer
- PokeS(*String_Buffer, String, -1, #PB_Ascii)
- EndIf
- lua_getglobal(Lua_Main\State, *String_Buffer)
- FreeMemory(*String_Buffer)
- EndMacro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement