├── Example.pb ├── Libraries └── Lua │ ├── Binaries │ ├── Linux │ │ ├── x64 │ │ │ └── liblua53.a │ │ └── x86 │ │ │ └── liblua53.a │ └── Windows │ │ ├── x64 │ │ ├── lua53.dll │ │ └── lua53.lib │ │ └── x86 │ │ ├── lua53.dll │ │ └── lua53.lib │ ├── LICENSE │ └── Lua.pbi ├── README.md ├── Test.lua └── lua53.dll /Example.pb: -------------------------------------------------------------------------------- 1 | XIncludeFile "Libraries\Lua\Lua.pbi" 2 | 3 | UseModule Lua 4 | 5 | ProcedureC PB_Debug(*Lua_State) 6 | Debug PeekS(lua_tostring(*Lua_State, 1),-1, #PB_UTF8) 7 | ProcedureReturn 0 ; Number of results 8 | EndProcedure 9 | 10 | ProcedureC Test_Results(*Lua_State) 11 | String.s = PeekS(lua_tostring(*Lua_State, 1),-1, #PB_UTF8) ; Get the string parameter 12 | 13 | Debug "Test_Results() got called" 14 | 15 | If String = "Test" 16 | Result_Bool = #True 17 | Else 18 | Result_Bool = #False 19 | EndIf 20 | 21 | lua_pushstring(*Lua_State, ReverseString(String)) ; Return a string 22 | lua_pushboolean(*Lua_State, Result_Bool) ; Return a boolean true 23 | ProcedureReturn 2 ; Number of results (If this doesn't equal the number of pushes, there will be a memory leak) 24 | EndProcedure 25 | 26 | ; #### Create the Lua-State 27 | *Lua_State = luaL_newstate() 28 | 29 | ; #### Load some libraries 30 | lua_pushcclosure(*Lua_State, @luaL_openlibs(), 0) 31 | lua_call(*Lua_State, 0, 0) 32 | ;lua_callk(*Lua_State, 0, 0, 0, #Null) 33 | 34 | ; #### Return the lua version 35 | Debug PeekD(lua_version(*Lua_State)) 36 | 37 | ; #### Make our procedure Test() available in lua 38 | lua_register(*Lua_State, "PB_Debug", @PB_Debug()) 39 | lua_register(*Lua_State, "Test_Results", @Test_Results()) 40 | 41 | ; #### Call Test() with some UTF-8 string passed as parameter (Make sure the PB file is formatted as UTF-8) 42 | Debug luaL_dostring(*Lua_State, "PB_Debug('tesä+¡m↓')") 43 | Debug luaL_dostring(*Lua_State, "PB_Debug('hello')") 44 | 45 | file$ = "Test.lua" 46 | 47 | Debug "--- Run" + file$ + " script ---" 48 | 49 | If luaL_dofile(*Lua_State, file$) 50 | ; #### Some error happened, return error message 51 | Debug PeekS(lua_tostring(*Lua_State, -1), -1, #PB_UTF8) 52 | EndIf 53 | 54 | ;CreateThread() 55 | 56 | ;lua_close(l) 57 | ; IDE Options = PureBasic 5.42 LTS (Windows - x64) 58 | ; CursorPosition = 26 59 | ; Folding = - 60 | ; EnableUnicode 61 | ; EnableXP 62 | ; EnableCompileCount = 10 63 | ; EnableBuildCount = 0 64 | ; EnableExeConstant -------------------------------------------------------------------------------- /Libraries/Lua/Binaries/Linux/x64/liblua53.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dadido3/Lua-PureBasic/777729ef78046558f465e84fcbe52aba2b743a59/Libraries/Lua/Binaries/Linux/x64/liblua53.a -------------------------------------------------------------------------------- /Libraries/Lua/Binaries/Linux/x86/liblua53.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dadido3/Lua-PureBasic/777729ef78046558f465e84fcbe52aba2b743a59/Libraries/Lua/Binaries/Linux/x86/liblua53.a -------------------------------------------------------------------------------- /Libraries/Lua/Binaries/Windows/x64/lua53.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dadido3/Lua-PureBasic/777729ef78046558f465e84fcbe52aba2b743a59/Libraries/Lua/Binaries/Windows/x64/lua53.dll -------------------------------------------------------------------------------- /Libraries/Lua/Binaries/Windows/x64/lua53.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dadido3/Lua-PureBasic/777729ef78046558f465e84fcbe52aba2b743a59/Libraries/Lua/Binaries/Windows/x64/lua53.lib -------------------------------------------------------------------------------- /Libraries/Lua/Binaries/Windows/x86/lua53.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dadido3/Lua-PureBasic/777729ef78046558f465e84fcbe52aba2b743a59/Libraries/Lua/Binaries/Windows/x86/lua53.dll -------------------------------------------------------------------------------- /Libraries/Lua/Binaries/Windows/x86/lua53.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dadido3/Lua-PureBasic/777729ef78046558f465e84fcbe52aba2b743a59/Libraries/Lua/Binaries/Windows/x86/lua53.lib -------------------------------------------------------------------------------- /Libraries/Lua/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright © 1994–2016 Lua.org, PUC-Rio. 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. -------------------------------------------------------------------------------- /Libraries/Lua/Lua.pbi: -------------------------------------------------------------------------------- 1 | ; #### Translated to PB by David Vogel (Dadido3) 2 | ; #### Updated: 29.12.2016 3 | ; #### http://github.com/Dadido3 4 | ; #### http://D3nexus.de 5 | 6 | DeclareModule Lua 7 | 8 | CompilerSelect #PB_Compiler_OS 9 | CompilerCase #PB_OS_Windows 10 | CompilerSelect #PB_Compiler_Processor 11 | CompilerCase #PB_Processor_x86 12 | #Lua_Library_File = ".\Binaries\Windows\x86\lua53.lib" ; Windows x86 13 | CompilerCase #PB_Processor_x64 14 | #Lua_Library_File = ".\Binaries\Windows\x64\lua53.lib" ; Windows x86-64 15 | CompilerEndSelect 16 | 17 | CompilerCase #PB_OS_Linux 18 | CompilerSelect #PB_Compiler_Processor 19 | CompilerCase #PB_Processor_x86 20 | Import "/usr/lib/libm.so" 21 | EndImport 22 | Import "/usr/lib/libdl.so" 23 | EndImport 24 | #Lua_Library_File = "/Binaries/Linux/x86/liblua53.a" ; Linux x86 25 | CompilerCase #PB_Processor_x64 26 | #Lua_Library_File = "/Binaries/Linux/x64/liblua53.a" ; Linux x86-64 27 | CompilerEndSelect 28 | 29 | CompilerDefault 30 | CompilerError "Lua-Module: OS not supported." 31 | 32 | CompilerEndSelect 33 | 34 | ; #### Information about the data types: 35 | ; #### On x64 Windows LLP64 is used. on x64 Linux and MacOS X LP64 is used. The x86 version of Windows, Linux and MacOS use ILP32. Therefore: 36 | ; ╔══════╤══════════╤═════════════════╗ 37 | ; ║ │ Windows │ Linux, MacOS ║ 38 | ; ║ │ ├────────┬────────╢ 39 | ; ║ │ x86, x64 │ x86 │ x64 ║ 40 | ; ╟──────┼──────────┼────────┼────────╢ 41 | ; ║ int │ 32 bit │ 32 bit │ 32 bit ║ 42 | ; ╟──────┼──────────┼────────┼────────╢ 43 | ; ║ long │ 32 bit │ 32 bit │ 64 bit ║ 44 | ; ╚══════╧══════════╧════════╧════════╝ 45 | ; #### uInt is defined as "unsigned int" and uLong as "unsigned long". 46 | Macro C_int : l : EndMacro 47 | Macro C_uInt : l : EndMacro 48 | CompilerIf #PB_Compiler_OS = #PB_OS_Linux Or #PB_Compiler_OS = #PB_OS_MacOS 49 | Macro C_long : i : EndMacro 50 | Macro C_uLong : i : EndMacro 51 | CompilerElse 52 | Macro C_long : l : EndMacro 53 | Macro C_uLong : l : EndMacro 54 | CompilerEndIf 55 | 56 | ; =============================================================== 57 | ;- ======== lua.h ======== 58 | ; =============================================================== 59 | 60 | ; $Id: lua.h,v 1.325 2014/12/26 17:24:27 roberto Exp $ 61 | ; Lua - A Scripting Language 62 | ; Lua.org, PUC-Rio, Brazil (http://www.lua.org) 63 | ; See Copyright Notice at the End of this file 64 | 65 | #LUA_VERSION_MAJOR = "5" 66 | #LUA_VERSION_MINOR = "3" 67 | #LUA_VERSION_NUM = 503 68 | #LUA_VERSION_RELEASE = "0" 69 | 70 | #LUA_VERSION = "Lua " + #LUA_VERSION_MAJOR + "." + #LUA_VERSION_MINOR 71 | #LUA_RELEASE = #LUA_VERSION + "." + #LUA_VERSION_RELEASE 72 | #LUA_COPYRIGHT = #LUA_RELEASE + " Copyright (C) 1994-2015 Lua.org, PUC-Rio" 73 | #LUA_AUTHORS = "R. Ierusalimschy, L. H. de Figueiredo, W. Celes" 74 | 75 | ; mark For precompiled code ('Lua') 76 | #LUA_SIGNATURE = Chr($1B) + "Lua" 77 | 78 | ; option For multiple returns in 'lua_pcall' And 'lua_call' 79 | #LUA_MULTRET = -1 80 | 81 | ; pseudo-indices 82 | ;#LUA_REGISTRYINDEX = #LUAI_FIRSTPSEUDOIDX 83 | ;Macro lua_upvalueindex(i) : (#LUA_REGISTRYINDEX - (i)) : EndMacro 84 | 85 | ; thread status 86 | #LUA_OK = 0 87 | #LUA_YIELD = 1 88 | #LUA_ERRRUN = 2 89 | #LUA_ERRSYNTAX = 3 90 | #LUA_ERRMEM = 4 91 | #LUA_ERRGCMM = 5 92 | #LUA_ERRERR = 6 93 | 94 | Structure lua_State : EndStructure 95 | 96 | ; basic types 97 | #LUA_TNONE = -1 98 | 99 | #LUA_TNIL = 0 100 | #LUA_TBOOLEAN = 1 101 | #LUA_TLIGHTUSERDATA = 2 102 | #LUA_TNUMBER = 3 103 | #LUA_TSTRING = 4 104 | #LUA_TTABLE = 5 105 | #LUA_TFUNCTION = 6 106 | #LUA_TUSERDATA = 7 107 | #LUA_TTHREAD = 8 108 | 109 | #LUA_NUMTAGS = 9 110 | 111 | ; minimum Lua stack available To a C function 112 | #LUA_MINSTACK = 20 113 | 114 | ; predefined values in the registry 115 | #LUA_RIDX_MAINTHREAD = 1 116 | #LUA_RIDX_GLOBALS = 2 117 | #LUA_RIDX_LAST = #LUA_RIDX_GLOBALS 118 | 119 | ; type of numbers in Lua 120 | Macro lua_Number : d : EndMacro 121 | 122 | 123 | ; type For integer functions 124 | Macro lua_Integer : q : EndMacro 125 | 126 | ; unsigned integer type 127 | Macro lua_Unsigned : q : EndMacro 128 | 129 | ; type For continuation-function contexts 130 | Structure lua_KContext : EndStructure 131 | 132 | ; Type For C functions registered With Lua 133 | PrototypeC.C_int lua_CFunction(*L.lua_State) 134 | 135 | ; Type For continuation functions 136 | PrototypeC.C_int lua_KFunction(*L.lua_State, status.C_int, *ctx.lua_KContext) 137 | 138 | 139 | ; Type For functions that Read/write blocks when loading/dumping Lua chunks 140 | PrototypeC.i lua_Reader(*L.lua_State, *ud, *sz.Integer) ; Returns pointer to a string 141 | 142 | PrototypeC.C_int lua_Writer(*L.lua_State, p.p-utf8, sz.i, *ud) 143 | 144 | 145 | ; Type For memory-allocation functions 146 | PrototypeC lua_Alloc(*ud, *ptr, osize.i, nsize.i) 147 | 148 | ImportC #Lua_Library_File 149 | 150 | ; /* 151 | ; ** state manipulation 152 | ; */ 153 | 154 | lua_newstate.i (*f.lua_Alloc, *ud) 155 | lua_close (*L.lua_State) 156 | lua_newthread.i (*L.lua_State) 157 | 158 | lua_atpanic.i (*L.lua_State, *panicf.lua_CFunction) 159 | 160 | lua_version.i (*L.lua_State) ; Returns pointer to a lua_Number 161 | 162 | 163 | ; /* 164 | ; ** basic stack manipulation 165 | ; */ 166 | 167 | lua_absindex.C_int (*L.lua_State, idx.C_int) 168 | lua_gettop.C_int (*L.lua_State) 169 | lua_settop (*L.lua_State, idx.C_int) 170 | lua_pushvalue (*L.lua_State, idx.C_int) 171 | lua_rotate (*L.lua_State, idx.C_int, n.C_int) 172 | lua_copy (*L.lua_State, fromidx.C_int, toidx.C_int) 173 | lua_checkstack.C_int (*L.lua_State, sz.C_int) 174 | 175 | lua_xmove (*from.lua_State, *to.lua_State, n.C_int) 176 | 177 | 178 | ; /* 179 | ; ** access functions (stack -> C) 180 | ; */ 181 | 182 | lua_isnumber.C_int (*L.lua_State, idx.C_int) 183 | lua_isstring.C_int (*L.lua_State, idx.C_int) 184 | lua_iscfunction.C_int (*L.lua_State, idx.C_int) 185 | lua_isinteger.C_int (*L.lua_State, idx.C_int) 186 | lua_isuserdata.C_int (*L.lua_State, idx.C_int) 187 | lua_type.C_int (*L.lua_State, idx.C_int) 188 | lua_typename.i (*L.lua_State, tp.C_int) ; Returns pointer to a string 189 | 190 | lua_tonumberx.lua_Number (*L.lua_State, idx.C_int, *isnum) 191 | lua_tointegerx.lua_Integer (*L.lua_State, idx.C_int, *isnum) 192 | lua_toboolean (*L.lua_State, idx.C_int) 193 | lua_tolstring.i (*L.lua_State, idx.C_int, *len.Integer) ; Returns pointer to a string 194 | lua_rawlen.i (*L.lua_State, idx.C_int) 195 | lua_tocfunction.lua_CFunction (*L.lua_State, idx.C_int) 196 | lua_touserdata (*L.lua_State, idx.C_int) 197 | lua_tothread.i (*L.lua_State, idx.C_int) 198 | lua_topointer.i (*L.lua_State, idx.C_int) 199 | 200 | EndImport 201 | 202 | ; /* 203 | ; ** Comparison And arithmetic functions 204 | ; */ 205 | 206 | #LUA_OPADD = 0 ; ORDER TM, ORDER OP 207 | #LUA_OPSUB = 1 208 | #LUA_OPMUL = 2 209 | #LUA_OPMOD = 3 210 | #LUA_OPPOW = 4 211 | #LUA_OPDIV = 5 212 | #LUA_OPIDIV = 6 213 | #LUA_OPBAND = 7 214 | #LUA_OPBOR = 8 215 | #LUA_OPBXOR = 9 216 | #LUA_OPSHL = 10 217 | #LUA_OPSHR = 11 218 | #LUA_OPUNM = 12 219 | #LUA_OPBNOT = 13 220 | 221 | #LUA_OPEQ = 0 222 | #LUA_OPLT = 1 223 | #LUA_OPLE = 2 224 | 225 | ImportC #Lua_Library_File 226 | 227 | lua_arith (*L.lua_State, op.C_int) 228 | 229 | lua_rawequal.C_int (*L.lua_State, idx1.C_int, idx2.C_int) 230 | lua_compare.C_int (*L.lua_State, idx1.C_int, idx2.C_int, op.C_int) 231 | 232 | 233 | ; /* 234 | ; ** push functions (C -> stack) 235 | ; */ 236 | lua_pushnil (*L.lua_State) 237 | lua_pushnumber (*L.lua_State, n.lua_Number) 238 | lua_pushinteger (*L.lua_State, n.lua_Integer) 239 | lua_pushlstring.i (*L.lua_State, s.p-utf8, len.i) ; Returns pointer to a string 240 | lua_pushstring.i (*L.lua_State, s.p-utf8) ; Returns pointer to a string 241 | ;lua_pushvfstring.i (*L.lua_State, fmt.p-utf8, argp.va_list) ; Returns pointer to a string 242 | lua_pushfstring.i (*L.lua_State, fmt.p-utf8);, ...) ; Returns pointer to a string 243 | lua_pushcclosure (*L.lua_State, *fn.lua_CFunction, n.C_int) 244 | lua_pushboolean (*L.lua_State, b.C_int) 245 | lua_pushlightuserdata (*L.lua_State, *p) 246 | lua_pushthread.C_int (*L.lua_State) 247 | 248 | 249 | ; /* 250 | ; ** get functions (Lua -> stack) 251 | ; */ 252 | lua_getglobal.C_int (*L.lua_State, name.p-utf8) 253 | lua_gettable.C_int (*L.lua_State, idx.C_int) 254 | lua_getfield.C_int (*L.lua_State, idx.C_int, k.p-utf8) 255 | lua_geti.C_int (*L.lua_State, idx.C_int, n.lua_Integer) 256 | lua_rawget.C_int (*L.lua_State, idx.C_int) 257 | lua_rawgeti.C_int (*L.lua_State, idx.C_int, n.lua_Integer) 258 | lua_rawgetp.C_int (*L.lua_State, idx.C_int, p.p-utf8) 259 | 260 | lua_createtable (*L.lua_State, narr.C_int, nrec.C_int) 261 | lua_newuserdata.i (*L.lua_State, sz.i) 262 | lua_getmetatable.C_int (*L.lua_State, objindex.C_int) 263 | lua_getuservalue.C_int (*L.lua_State, idx.C_int) 264 | 265 | 266 | ; /* 267 | ; ** set functions (stack -> Lua) 268 | ; */ 269 | lua_setglobal (*L.lua_State, name.p-utf8) 270 | lua_settable (*L.lua_State, idx.C_int) 271 | lua_setfield (*L.lua_State, idx.C_int, k.p-utf8) 272 | lua_seti (*L.lua_State, idx.C_int, n.lua_Integer) 273 | lua_rawset (*L.lua_State, idx.C_int) 274 | lua_rawseti (*L.lua_State, idx.C_int, n.lua_Integer) 275 | lua_rawsetp (*L.lua_State, idx.C_int, p.p-utf8) 276 | lua_setmetatable.C_int (*L.lua_State, objindex.C_int) 277 | lua_setuservalue (*L.lua_State, idx.C_int) 278 | 279 | 280 | ; /* 281 | ; ** 'load' And 'call' functions (load And run Lua code) 282 | ; */ 283 | lua_callk (*L.lua_State, nargs.C_int, nresults.C_int, *ctx.lua_KContext, k.lua_KFunction) 284 | Macro lua_call(L,n,r) : lua_callk(L, (n), (r), 0, #Null) : EndMacro 285 | 286 | lua_pcallk.C_int (*L.lua_State, nargs.C_int, nresults.C_int, errfunc.C_int, *ctx.lua_KContext, k.lua_KFunction) 287 | Macro lua_pcall(L,n,r,f) : lua_pcallk(L, (n), (r), (f), 0, #Null) : EndMacro 288 | 289 | lua_load.C_int (*L.lua_State, reader.lua_Reader, *dt, chunkname.p-utf8, mode.p-utf8) 290 | 291 | lua_dump.C_int (*L.lua_State, writer.lua_Writer, *Data, strip.C_int) 292 | 293 | 294 | ; /* 295 | ; ** coroutine functions 296 | ; */ 297 | lua_yieldk.C_int (*L.lua_State, nresults.C_int, *ctx.lua_KContext, k.lua_KFunction) 298 | lua_resume.C_int (*L.lua_State, *from.lua_State, narg.C_int) 299 | lua_status.C_int (*L.lua_State) 300 | lua_isyieldable.C_int (*L.lua_State) 301 | 302 | Macro lua_yield(L,n) : lua_yieldk(L, (n), 0, #Null) : EndMacro 303 | 304 | EndImport 305 | 306 | 307 | ; /* 308 | ; ** garbage-collection function And options 309 | ; */ 310 | 311 | #LUA_GCSTOP = 0 312 | #LUA_GCRESTART = 1 313 | #LUA_GCCOLLECT = 2 314 | #LUA_GCCOUNT = 3 315 | #LUA_GCCOUNTB = 4 316 | #LUA_GCSTEP = 5 317 | #LUA_GCSETPAUSE = 6 318 | #LUA_GCSETSTEPMUL = 7 319 | #LUA_GCISRUNNING = 9 320 | 321 | ImportC #Lua_Library_File 322 | 323 | lua_gc.C_int (*L.lua_State, what.C_int, _Data.C_int) 324 | 325 | 326 | ; /* 327 | ; ** miscellaneous functions 328 | ; */ 329 | 330 | lua_error.C_int (*L.lua_State) 331 | 332 | lua_next.C_int (*L.lua_State, idx.C_int) 333 | 334 | lua_concat (*L.lua_State, n.C_int) 335 | lua_len (*L.lua_State, idx.C_int) 336 | 337 | lua_stringtonumber.i (*L.lua_State, s.p-utf8) 338 | 339 | lua_getallocf.i (*L.lua_State, *ud) 340 | lua_setallocf (*L.lua_State, *f.lua_Alloc, *ud) 341 | 342 | EndImport 343 | 344 | ; /* 345 | ; ** {============================================================== 346 | ; ** some useful macros 347 | ; ** =============================================================== 348 | ; */ 349 | 350 | ;Macro lua_getextraspace(L) : ((void *)((char *)(L) - #LUA_EXTRASPACE)) : EndMacro 351 | 352 | Macro lua_tonumber(L,i) : lua_tonumberx(L,(i),#Null) : EndMacro 353 | Macro lua_tointeger(L,i) : lua_tointegerx(L,(i),#Null) : EndMacro 354 | 355 | Macro lua_pop(L,n) : lua_settop(L, -(n)-1) : EndMacro 356 | 357 | Macro lua_newtable(L) : lua_createtable(L, 0, 0) : EndMacro 358 | 359 | Macro lua_register(L,n,f) 360 | lua_pushcfunction(L, (f)) 361 | lua_setglobal(L, (n)) 362 | EndMacro 363 | 364 | Macro lua_pushcfunction(L,f) : lua_pushcclosure(L, (f), 0) : EndMacro 365 | 366 | Macro lua_isfunction(L,n) : Bool(lua_type(L, (n)) = #UA_TFUNCTION) : EndMacro 367 | Macro lua_istable(L,n) : Bool(lua_type(L, (n)) = #LUA_TTABLE) : EndMacro 368 | Macro lua_islightuserdata(L,n) : Bool(lua_type(L, (n)) = #LUA_TLIGHTUSERDATA) : EndMacro 369 | Macro lua_isnil(L,n) : Bool(lua_type(L, (n)) = #LUA_TNIL) : EndMacro 370 | Macro lua_isboolean(L,n) : Bool(lua_type(L, (n)) = #LUA_TBOOLEAN) : EndMacro 371 | Macro lua_isthread(L,n) : Bool(lua_type(L, (n)) = #LUA_TTHREAD) : EndMacro 372 | Macro lua_isnone(L,n) : Bool(lua_type(L, (n)) = #LUA_TNONE) : EndMacro 373 | Macro lua_isnoneornil(L, n) : Bool(lua_type(L, (n)) <= 0) : EndMacro 374 | 375 | Macro lua_pushliteral(L, s) : lua_pushlstring(L, s, (SizeOf(s)/SizeOf(Character))-1) : EndMacro 376 | 377 | Macro lua_pushglobaltable(L) : lua_rawgeti(L, #LUA_REGISTRYINDEX, #LUA_RIDX_GLOBALS) : EndMacro 378 | 379 | Macro lua_tostring(L,i) : lua_tolstring(L, (i), #Null) : EndMacro 380 | 381 | 382 | Macro lua_insert(L,idx) : lua_rotate(L, (idx), 1) : EndMacro 383 | 384 | Macro lua_remove(L,idx) : Bool(lua_rotate(L, (idx), -1) And lua_pop(L, 1)) : EndMacro 385 | 386 | Macro lua_replace(L,idx) : Bool(lua_copy(L, -1, (idx)) And lua_pop(L, 1)) : EndMacro 387 | 388 | ; /* }============================================================== */ 389 | 390 | 391 | ; /* 392 | ; ** {============================================================== 393 | ; ** compatibility macros For unsigned conversions 394 | ; ** =============================================================== 395 | ; */ 396 | CompilerIf Defined(LUA_COMPAT_APIINTCASTS, #PB_Constant) 397 | 398 | Macro lua_pushunsigned(L,n) : lua_pushinteger(L, (n)) : EndMacro 399 | Macro lua_tounsignedx(L,i,is) : lua_tointegerx(L,i,is) : EndMacro 400 | Macro lua_tounsigned(L,i) : lua_tounsignedx(L,(i),#Null) : EndMacro 401 | 402 | CompilerEndIf 403 | 404 | ; =============================================================== 405 | ;- ======== lualib.h ======== 406 | ; =============================================================== 407 | 408 | #LUA_COLIBNAME = "coroutine" 409 | #LUA_TABLIBNAME = "table" 410 | #LUA_IOLIBNAME = "io" 411 | #LUA_OSLIBNAME = "os" 412 | #LUA_STRLIBNAME = "string" 413 | #LUA_UTF8LIBNAME = "utf8" 414 | #LUA_BITLIBNAME = "bit32" 415 | #LUA_MATHLIBNAME = "math" 416 | #LUA_DBLIBNAME = "debug" 417 | #LUA_LOADLIBNAME = "package" 418 | 419 | ImportC #Lua_Library_File 420 | 421 | luaopen_base.C_int (*L.lua_State) 422 | 423 | 424 | luaopen_coroutine.C_int (*L.lua_State) 425 | 426 | luaopen_table.C_int (*L.lua_State) 427 | 428 | luaopen_io.C_int (*L.lua_State) 429 | 430 | luaopen_os.C_int (*L.lua_State) 431 | 432 | luaopen_string.C_int (*L.lua_State) 433 | 434 | luaopen_utf8.C_int (*L.lua_State) 435 | 436 | luaopen_bit32.C_int (*L.lua_State) 437 | 438 | luaopen_math.C_int (*L.lua_State) 439 | 440 | luaopen_debug.C_int (*L.lua_State) 441 | 442 | luaopen_package.C_int (*L.lua_State) 443 | 444 | 445 | ; open all previous libraries 446 | luaL_openlibs (*L.lua_State) 447 | 448 | EndImport 449 | 450 | ; =============================================================== 451 | ;- ======== lauxlib.h ======== 452 | ; =============================================================== 453 | 454 | ; extra error code For 'luaL_load' 455 | #LUA_ERRFILE = #LUA_ERRERR+1 456 | 457 | Structure luaL_Reg 458 | name.i ; Pointer to a string 459 | func.lua_CFunction 460 | EndStructure 461 | 462 | ;#LUAL_NUMSIZES = SizeOf(lua_Integer)*16 + SizeOf(lua_Number) 463 | #LUAL_NUMSIZES = 8*16 + 8 464 | 465 | ImportC #Lua_Library_File 466 | 467 | luaL_checkversion_ (*L.lua_State, ver.lua_Number, sz.i) 468 | Macro luaL_checkversion(L) : luaL_checkversion_(L, #LUA_VERSION_NUM, #LUAL_NUMSIZES) : EndMacro 469 | 470 | luaL_getmetafield.C_int (*L.lua_State, obj.C_int, e.p-utf8) 471 | luaL_callmeta.C_int (*L.lua_State, obj.C_int, e.p-utf8) 472 | luaL_tolstring.i (*L.lua_State, idx.C_int, *len.Integer) ; Returns pointer to a string 473 | luaL_argerror.C_int (*L.lua_State, arg.C_int, extramsg.p-utf8) 474 | luaL_checklstring.i (*L.lua_State, arg.C_int, *len.Integer) ; Returns pointer to a string 475 | luaL_optlstring.i (*L.lua_State, arg.C_int, def.p-utf8, *len.Integer) ; Returns pointer to a string 476 | luaL_checknumber.lua_Number (*L.lua_State, arg.C_int) 477 | luaL_optnumber.lua_Number (*L.lua_State, arg.C_int, def.lua_Number) 478 | 479 | luaL_checkinteger.lua_Integer (*L.lua_State, arg.C_int) 480 | luaL_optinteger.lua_Integer (*L.lua_State, arg.C_int, def.lua_Integer) 481 | 482 | luaL_checkstack (*L.lua_State, sz.C_int, msg.p-utf8) 483 | luaL_checktype (*L.lua_State, arg.C_int, t.C_int) 484 | luaL_checkany (*L.lua_State, arg.C_int) 485 | 486 | luaL_newmetatable.C_int (*L.lua_State, tname.p-utf8) 487 | luaL_setmetatable (*L.lua_State, tname.p-utf8) 488 | luaL_testudata.i (*L.lua_State, ud.C_int, tname.p-utf8) 489 | luaL_checkudata.i (*L.lua_State, ud.C_int, tname.p-utf8) 490 | 491 | luaL_where (*L.lua_State, lvl.C_int) 492 | luaL_error.C_int (*L.lua_State, fmt.p-utf8);, ...) 493 | 494 | luaL_checkoption.C_int (*L.lua_State, arg.C_int, def.p-utf8, *lst) 495 | 496 | luaL_fileresult.C_int (*L.lua_State, stat.C_int, fname.p-utf8) 497 | luaL_execresult.C_int (*L.lua_State, stat.C_int) 498 | 499 | EndImport 500 | 501 | ; pre-defined references 502 | #LUA_NOREF = -2 503 | #LUA_REFNIL = -1 504 | 505 | ImportC #Lua_Library_File 506 | 507 | luaL_ref.C_int (*L.lua_State, t.C_int) 508 | luaL_unref (*L.lua_State, t.C_int, ref.C_int) 509 | 510 | luaL_loadfilex.C_int (*L.lua_State, filename.p-utf8, mode.p-utf8) 511 | 512 | Macro luaL_loadfile(L,f) : luaL_loadfilex(L,f,"bt") : EndMacro ; mode: Format can be binary or text (The pseudotype converts the null-string into an empty string, so #Null$ can't be used) 513 | 514 | luaL_loadbufferx.C_int (*L.lua_State, buff.p-utf8, sz.i, name.p-utf8, mode.p-utf8) 515 | luaL_loadstring.C_int (*L.lua_State, s.p-utf8) 516 | 517 | luaL_newstate.i () 518 | 519 | luaL_len.lua_Integer (*L.lua_State, idx.C_int) 520 | 521 | luaL_gsub.i (*L.lua_State, s.p-utf8, p.p-utf8, r.p-utf8) ; Returns pointer to a string 522 | 523 | luaL_setfuncs (*L.lua_State, *lr.luaL_Reg, nup.C_int) 524 | 525 | luaL_getsubtable.C_int (*L.lua_State, idx.C_int, fname.p-utf8) 526 | 527 | luaL_traceback (*L.lua_State, *L1.lua_State, msg.p-utf8, level.C_int) 528 | 529 | luaL_requiref (*L.lua_State, modname.p-utf8, openf.lua_CFunction, glb.C_int) 530 | 531 | EndImport 532 | 533 | ; /* 534 | ; ** =============================================================== 535 | ; ** some useful macros 536 | ; ** =============================================================== 537 | ; */ 538 | 539 | 540 | ;Macro luaL_newlibtable(L,l) : lua_createtable(L, 0, SizeOf(l)/SizeOf((l)[0]) - 1) : EndMacro 541 | 542 | ;Macro luaL_newlib(L,l) : Bool(luaL_checkversion(L) And luaL_newlibtable(L,l) And luaL_setfuncs(L,l,0)) : EndMacro 543 | 544 | Macro luaL_argcheck(L, cond,arg,extramsg) : Bool((cond) Or luaL_argerror(L, (arg), (extramsg))) : EndMacro 545 | Macro luaL_checkstring(L,n) : luaL_checklstring(L, (n), #Null) : EndMacro 546 | Macro luaL_optstring(L,n,d) : luaL_optlstring(L, (n), (d), #Null) : EndMacro 547 | 548 | Macro luaL_typename(L,i) : lua_typename(L, lua_type(L,(i))) : EndMacro 549 | 550 | Macro luaL_dofile(L, fn) : Bool(luaL_loadfile(L, fn) Or lua_pcall(L, 0, #LUA_MULTRET, 0)) : EndMacro ; FIXME: All these functions should return errors. Bool is preventing that 551 | 552 | Macro luaL_dostring(L, s) : Bool(luaL_loadstring(L, s) Or lua_pcall(L, 0, #LUA_MULTRET, 0)) : EndMacro 553 | 554 | Macro luaL_getmetatable(L,n) : lua_getfield(L, #LUA_REGISTRYINDEX, (n)) : EndMacro 555 | 556 | ;Macro luaL_opt(L,f,n,d) : (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) : EndMacro 557 | 558 | Macro luaL_loadbuffer(L,s,sz,n) : luaL_loadbufferx(L,s,sz,n,"bt") : EndMacro ; mode: Format can be binary or text (The pseudotype converts the null-string into an empty string, so #Null$ can't be used) 559 | 560 | EndDeclareModule 561 | 562 | Module Lua 563 | 564 | ; ################## Procedures and Macros for some exceptions ################## 565 | 566 | EndModule 567 | 568 | ; /****************************************************************************** 569 | ; * Copyright (C) 1994-2015 Lua.org, PUC-Rio. 570 | ; * 571 | ; * Permission is hereby granted, free of charge, To any person obtaining 572 | ; * a copy of this software And associated documentation files (the 573 | ; * "Software"), To deal in the Software without restriction, including 574 | ; * without limitation the rights To use, copy, modify, merge, publish, 575 | ; * distribute, sublicense, And/Or sell copies of the Software, And To 576 | ; * permit persons To whom the Software is furnished To do so, subject To 577 | ; * the following conditions: 578 | ; * 579 | ; * The above copyright notice And this permission notice shall be 580 | ; * included in all copies Or substantial portions of the Software. 581 | ; * 582 | ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 583 | ; * EXPRESS Or IMPLIED, INCLUDING BUT Not LIMITED To THE WARRANTIES OF 584 | ; * MERCHANTABILITY, FITNESS For A PARTICULAR PURPOSE And NONINFRINGEMENT. 585 | ; * IN NO EVENT SHALL THE AUTHORS Or COPYRIGHT HOLDERS BE LIABLE For ANY 586 | ; * CLAIM, DAMAGES Or OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 587 | ; * TORT Or OTHERWISE, ARISING FROM, OUT OF Or IN CONNECTION With THE 588 | ; * SOFTWARE Or THE USE Or OTHER DEALINGS IN THE SOFTWARE. 589 | ; ******************************************************************************/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LUA 5.3.0 include for PureBasic 2 | ===== 3 | 4 | This repository contains all needed binaries and include files to embed Lua into PureBasic. 5 | Supported operating systems are Windows and any Linux derivative (Even though Linux was only tested with an older version of Lua). 6 | MacOS should also work, but for this some additions have to be made to the include and the correct shared/static library files have to be gathered or compiled manually. 7 | 8 | ## Usage 9 | An [example](/Example.pb) on how to use Lua is included in this repository. It shows how to create a Lua state, how to register PB functions to make them accessible from within Lua, and how to load and run Lua-strings or Lua-files. 10 | 11 | To make Lua work on Windows you have to copy the according (x86 or x64) shared library (*.dll) into the same folder as your application. 12 | The *.dll files can be found in `Libraries\Lua\Binaries\Windows\x__\`, for Linux no files have to be copied because the static version of Lua is used there for easiness. 13 | 14 | ## License 15 | Lua itself is distributed under the terms of the [MIT license](/Libraries/Lua/LICENSE). 16 | 17 | However, i can't give any warranty on the correctness of the code, therefore: 18 | ``` 19 | 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. 20 | ``` 21 | 22 | ## Bugs? 23 | If you find an include related bug, feel free to open a new issue here or send me a PM on the PureBasic forums. 24 | -------------------------------------------------------------------------------- /Test.lua: -------------------------------------------------------------------------------- 1 | a, b = Test_Results('Hi there') 2 | PB_Debug(a) -- Should print: ereht iH 3 | PB_Debug(tostring(b)) -- Should print: false 4 | 5 | a, b = Test_Results('Test') 6 | PB_Debug(a) -- Should print: tseT 7 | PB_Debug(tostring(b)) -- Should print: true -------------------------------------------------------------------------------- /lua53.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dadido3/Lua-PureBasic/777729ef78046558f465e84fcbe52aba2b743a59/lua53.dll --------------------------------------------------------------------------------