Re: LUA - Script with PureBasic
Posted: Thu May 14, 2020 2:30 pm
here are the LUA54rc3 binaries for Windows
http://www.purebasic.com
https://www.purebasic.fr/english/
Just a heads up on this, the following is the proper structure:GG wrote:>> This one maybe ?<<
So on windows you have to copy one of the dll files next to where you compile and run your executable. The lib files don't need to be moved/copied to get it working. But you can still do so if you want to use another structure. In this case you have to change the #Lua_Library_File constant.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. 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.
The idea of using a scripting language along with a binary program is generally to allow users to customize or extend the program via external file, which is why video games (for example) often rely on a scripting language to control settings or allow custom extensions via scripted plug-ins.lesserpanda wrote: Sun Dec 04, 2022 12:32 pm Hi, I was wondering what you would use LUA for with PureBasic?
Sure, it's possible. Many server software (e.g. Apache) do provide support for Lua scripting via extra modules, although Lua is not often used on the server side (unlike JS, Perl, etc.).lesserpanda wrote: Sun Dec 04, 2022 12:32 pm Am I right to say PureBasic, write a server like a HTTP API server, then run LUA?
The practical uses are limited only by your imagination. Lua is often used to handle configuration files, for example, because the nature of the language allows to write neat definitions of variables and tables in a simple notation. Before the JSON standard came about, Lua was often used for handling configurations. The advantage of using Lua for configurations is that end users can exploit the full power of the Lua language in their configurations: instead of static definitions they can exploit Lua API calls, system calls, or write their custom functions to calculate settings on the fly.
Code: Select all
Enumeration
#LUA_OK
#LUA_ERRRUN
#LUA_ERRMEM
#LUA_ERRERR
#LUA_YIELD
#LUA_ERRFILE
EndEnumeration
ProcedureC.l test(*L)
If CallFunction(0,"lua_gettop",*L)>0
Debug CallFunction(0,"lua_tolstring",*L,CallFunction(0,"lua_upvalueindex",1))
EndIf
EndProcedure
If OpenLibrary(0,"lua54.dll")
*L=CallFunction(0,"luaL_newstate")
If *L
CallFunction(0,"luaL_openlibs",*L)
CallFunction(0,"lua_pushcclosure",*L,@test(),1)
aaa.s="test('12345')"
err=CallFunction(0,"luaL_dostring",*L,@aaa)
Select err
Case 0
;string pushed to stack now execute
response=CallFunction(0,"lua_pcallk",*L,0,0,0)
Select response
Case 1
Debug #LUA_ERRRUN
Case 2
Debug #LUA_ERRMEM
Case 3
Debug #LUA_ERRERR
Case 4
Debug #LUA_YIELD
Case 5
Debug #LUA_ERRFILE
EndSelect
Case 1
Debug #LUA_ERRRUN
Case 2
Debug #LUA_ERRMEM
Case 3
Debug #LUA_ERRERR
Case 4
Debug #LUA_YIELD
Case 5
Debug #LUA_ERRFILE
EndSelect
CallFunction(0,"lua_close",*L)
EndIf
CloseLibrary(0)
EndIf
End