Lua and c++/c distribution

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Blazing_Code
Prole
Posts: 3
Joined: Thu Apr 21, 2016 4:50 pm

Lua and c++/c distribution

Post 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

Code: Select all

copy \b 
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
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

Re: Lua and c++/c distribution

Post by Ulydev »

-
Last edited by Ulydev on Thu Apr 21, 2016 8:51 pm, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Lua and c++/c distribution

Post 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.
Blazing_Code
Prole
Posts: 3
Joined: Thu Apr 21, 2016 4:50 pm

Re: Lua and c++/c distribution

Post 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!
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Lua and c++/c distribution

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Blazing_Code
Prole
Posts: 3
Joined: Thu Apr 21, 2016 4:50 pm

Re: Lua and c++/c distribution

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests