Page 1 of 1
Lua and c++/c distribution
Posted: Thu Apr 21, 2016 5:25 pm
by Blazing_Code
For a project I'm working on I want to be able to run Lua in c++ (which i know about states and stuff) but i don't know how to distribute the .exe and .lua as one file.
but the i saw that Love2d achieves this through the
command in windows so i tried this with two .txt files and it just copied one too the end of the other so i looked at the github but I'm a bit of a n00b to c++ so I didn't really know how it works (I'm used to java, python etc.) could someone explain how love2d uses this to make combined executables.
many thanks and kind regards,
Blazing
ps: I know that storing lua code in a string literal is possible but it dosen't work too well for what I'm doing
Re: Lua and c++/c distribution
Posted: Thu Apr 21, 2016 6:54 pm
by Ulydev
-
Re: Lua and c++/c distribution
Posted: Thu Apr 21, 2016 8:14 pm
by pgimeno
The trick is to open the running executable and look for the data.
If the appended data is a zip file, it turns out that the zip file format has a directory of the files it contains at its end. Programs use that to find the contents.
I don't know for sure, but it's likely that LÖVE (most likely through zip handling library like physfs) looks for that directory at the end automatically and finds the files that way.
That trick can't be used with text files directly. You could use a zip handling library to do the same that LÖVE does, and zip your Lua files and append them to the end of your executable.
You can also try to embed the Lua file as a resource. You'll need information on resource compilers. That would make the program pretty much Windows-only, though.
Re: Lua and c++/c distribution
Posted: Thu Apr 21, 2016 8:35 pm
by Blazing_Code
thanks pigmeno this is gonna be a windows only feature I'm mainly doing this because if i make it in java next year my application will be redundant because of all the changes in java but anyway Thanks!
Re: Lua and c++/c distribution
Posted: Thu Apr 21, 2016 10:23 pm
by zorg
Data can be raw, or it can have headers, footers, or even both.
A header contains metadata at the start of the data, the footer at the end.
Windows executables have headers, and zip archives have footers.
.lua files are source code and technically raw, as in, they don't have neither headers nor footers, so it wouldn't be easy for an application to search its own file, and guess how much from the end would be a "tacked-on" file it should read/parse. zipping and binary copying like how it's done could work, but idk about the specifics.
Re: Lua and c++/c distribution
Posted: Fri Apr 22, 2016 4:28 pm
by Blazing_Code
Thanks for the info zorg I have scoured the Love2d bitbucket physfs source to see if i can find any help there but I assume reading a zip file appended to an exe (or cpp, whatever) would consist of a filepath such as "myexe.exe/myzip/mylua.lua" or something along the lines of that