Example usage of LuaPreprocess+LÖVE.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I have a separate installation of Lua that I use to build the game (though you could use LÖVE too). | |
I run build.lua which processes all Lua files in the project and starts the game. | |
> lua buildSystem/build.lua | |
This example uses 3 folders: | |
- buildSystem/ for things used to build the game. | |
- src/ for unprocessed files. | |
- srcgen/ for processed/generated files. | |
I use a different extension for unprocessed files (.lua2p) so I don't get confused while working on the game. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- buildSystem/build.lua | |
local pp = require("buildSystem.preprocess") | |
-- Settings for the build system. | |
local OUTPUT_ZIP = false | |
-- Add values that all files use. The values in pp.metaEnvironment | |
-- will be globals in the files we're about to process. | |
pp.metaEnvironment.DEVELOPER_MODE = true | |
pp.metaEnvironment.DISABLE_SOUNDS = false | |
pp.metaEnvironment.GAME_VERSION_NAME = "v1.0.8 (Tomato)" | |
-- Get paths to all Lua files in the src/ folder. | |
local paths = getLuaFilesInDirectory("src") | |
for _, pathIn in ipairs(paths) do | |
local pathOut = pathIn | |
-- Output the files into the srcgen/ folder. | |
pathOut = pathOut:gsub("^src/", "srcgen/") | |
-- The unprocessed files have a different extension (.lua2p) | |
-- so I don't get confused. | |
pathOut = pathOut:gsub("%.lua2p$", ".lua") | |
-- Output main.lua into the top folder instead of srcgen/. | |
if pathOut == "srcgen/main.lua" then | |
pathOut = "main.lua" | |
end | |
local info, err = pp.processFile{ pathIn=pathIn, pathOut=pathOut } | |
-- Just exit if there was an error while processing the file. | |
-- An error message should already have been printed to the console. | |
if not info then os.exit(1) end | |
end | |
if OUTPUT_ZIP then | |
-- Output a .zip file. | |
os.execute("some_program_that_creates_a_zip_file.exe") | |
else | |
-- Execute LÖVE in the top/current folder to start the game. | |
os.execute("love.exe .") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- src/main.lua2p | |
-- require() should look in the top folder or the srcgen/ folder. | |
package.path = "?.lua;srcgen/?.lua" | |
function love.load() | |
!if DEVELOPER_MODE then | |
doDevStuff() | |
!end | |
require("menus") | |
showMainMenu() | |
end |
You'll have to define it yourself. Since Lua has no way of retrieving files in a directory by default you'll have to use something like LuaFileSystem.
I suggest you also provide one?
here's a working one on my case
local getLuaFilesInDirectory = function(str)
local f = io.popen("ls " .. str)
if f then
local files = {}
for line in f:lines() do
local path = str .. "/" .. line
table.insert(files, path)
end
return files
end
return nil
end
I left out implementation details involving the operative system on purpose because things work differently everywhere. For Windows you'd use something like io.popen("dir /b "..str)
instead of io.popen("ls "..str)
.
Oh yeah, got it! Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where is this function
getLuaFilesInDirectory
found?