I tried to write a Lua DLL in PB and to use it with the official Lua interpreter and ran into problems.
You have two choices: either all DLL's including your app/exe compile with the static lib (embedded mode), or all "plug-in" DLL's including the main app use the DLL (extension mode). Otherwise there will be problems when mixing static/dynamic modes.
I used the extension approach, because I couldn't manage to make or find a static Lua lib for the current version that should be 5.4, but the Lua interpreter has the lib statically linked. So I would have a few seemingly successful calls and then errors.
Your code will always produce an error when called from Lua.
Code: Select all
ProcedureCDLL test2()
ProcedureReturn 2
EndProcedure
Lua "C-functions" have to look like this:
Code: Select all
ProcedureCDLL tolua_myproc(*L)
Protected return_values
ProcedureReturn return_values
EndProcedure
You need to have the amount of return values on the Lua stack otherwise they will be replaced/fill with nil values.
No matter if you use a DLL, or embedded "C" functions (PureBasic main app), or Lua scripts to create modules, you should check the documentation about the new package-system, how the "require" command works, among other things.