Embedding LUA in PureBasic!?

Everything else that doesn't fall into one of the other PB categories.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Embedding LUA in PureBasic!?

Post by DoubleDutch »

Updated again to include the mac version of the lib, thanks to @jack .

https://dl.dropboxusercontent.com/u/171 ... lua514.zip
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: Embedding LUA in PureBasic!?

Post by wombats »

Would someone be willing to create a tutorial on how to build Lua statically for use with PureBasic? I think it would be very useful, as this question seems to come up often. It would be helpful for people to be able to build the new versions as they come out.

I have been trying to build Lua 5.3.0 for x64 with Visual Studio Express 2012, but when I try to use the .lib file with PureBasic x64, I get errors such as, ""POLINK: fatal error: Corrupt library: 'C:\...\lua5.3.0.lib'; unable to find symbol 'luaopen_base' in member 'x64\Release\lbaselib.obj'."

Eventually I'd like to be able to use Lua on all three platforms, both x86 and x64, where applicable...but that's probably a battle later down the road.

Thanks.
acreis
Enthusiast
Enthusiast
Posts: 204
Joined: Fri Jun 01, 2012 12:20 am

Re: Embedding LUA in PureBasic!?

Post by acreis »

Hi,

Try disable optimizations and incremental linking!
wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: Embedding LUA in PureBasic!?

Post by wombats »

acreis wrote:Hi,

Try disable optimizations and incremental linking!
I disabled optimizations, and I get the same errors. I cannot find an option to disable incremental linking (I also have no "Linker" options in the Project Properties).
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Embedding LUA in PureBasic!?

Post by jack »

hello wombats
would you post your test code?
I would like to the the lua libs on my system
wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: Embedding LUA in PureBasic!?

Post by wombats »

I used the code in the zip file posted by DoubleDutch.

I wanted to create an x64 build of Lua, since that's what I mainly use.

All I've done is created a static library project in Visual Studio 2012 and added the Lua source and header files to it. I updated the version, etc. in the lua.pbi file to match the version of Lua I built:

Code: Select all

#LUA_VERSION 					=	"Lua 5.3"
#LUA_RELEASE 					=	"Lua 5.3.0"
#LUA_VERSION_NUM 				=	503
#LUA_COPYRIGHT 				=	"Copyright (C) 1994-2007 Lua.org, PUC-Rio"
#LUA_AUTHORS					=	"R. Ierusalimschy, L. H. de Figueiredo & W. Celes"

;  mark for precompiled code
#LUA_SIGNATURE 				=	"\x1bLua" ;"\033Lua"
Am I missing some vital step? Haha.
acreis
Enthusiast
Enthusiast
Posts: 204
Joined: Fri Jun 01, 2012 12:20 am

Re: Embedding LUA in PureBasic!?

Post by acreis »

wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: Embedding LUA in PureBasic!?

Post by wombats »

I had seen that page, but as I said, I do not have that option: http://imgur.com/a/ovM1g

I had read that it is because my project is setup to create a static library.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Embedding LUA in PureBasic!?

Post by jack »

@wombats
I compiled lua5.3.0 to 64-bit lib but there are polink errors, then I tried lua5.1.5 but still get polink errors.
then I built a dll using msys2 and polib to build the import lib, everything works ok with version 5.1.5 but not with version 5.3.0.
wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: Embedding LUA in PureBasic!?

Post by wombats »

I don't know anything about mysys2 and polib.

I tried Lua 5.1.4, but I get new errors: http://imgur.com/a/J8c6G
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Embedding LUA in PureBasic!?

Post by DoubleDutch »

The one in my zip file?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Embedding LUA in PureBasic!?

Post by DoubleDutch »

By the way, the reason I've stuck with 5.1.4/5 is because 5.3 has change the way floats and ints are recognised - you define a float with 5.3 with a . else it's and int. In versions below this everything was a float. No-one seems to like the way you define the floats (it breaks compatibility) so this may change to another method with 5.4 .
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: Embedding LUA in PureBasic!?

Post by wombats »

No, I've been trying to build it successfully myself so I know how. I want to be able to use it with x64 PureBasic, also. I'm just not getting anywhere.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Embedding LUA in PureBasic!?

Post by jack »

hello wombats
I have not tried this myself but if you want to try compile using the command line then the instructions found on https://lua64bit.wordpress.com
might do the trick
from the command prompt cd to the lua src directory
(edit the path of your vs installation and lua version below)
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64
cl /MD /O2 /c /GS- /DLUA_BUILD_AS_DLL *.c
ren lua.obj lua.o
ren luac.obj luac.o
link /DLL /IMPLIB:lua5.3.0.lib /OUT:lua5.3.0.dll *.obj
link /OUT:lua.exe lua.o lua5.3.0.lib
lib /OUT:lua5.3.0-static.lib *.obj
link /OUT:luac.exe luac.o lua5.3.0-static.lib
note that lua version 5.3.0 does not have some of the functions that are in version 5.1.5 so your test code may need changing

edit: just tried it and the static lib of version 5.1.5 works ok compiling as above
also the dll and import lib work ok
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Embedding LUA in PureBasic!?

Post by DoubleDutch »

Make sure that if you compile with Visual C that you also don't need all the visual C baggage (sometimes you need to distribute extra dll s)...
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply