Skip to content

Commit

Permalink
backport game stuff and fix bundled stuff (woops)
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed May 29, 2024
1 parent b8c6c92 commit 60db149
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 32 deletions.
9 changes: 6 additions & 3 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ DoneAction RunLOVE(int argc, char** argv, int& retval, Variant& restartValue)
lua_rawseti(L, -2, -2);
}

std::vector<const char*> args(argv, argv + argc);
args.push_back("game");

lua_pushstring(L, "embedded boot.lua");
lua_rawseti(L, -2, -1);

for (int i = 1; i < argc; i++)
for (int index = 1; index < (int)args.size(); index++)
{
lua_pushstring(L, argv[i]);
lua_rawseti(L, -2, i);
lua_pushstring(L, args[index]);
lua_rawseti(L, -2, index);
}

lua_setglobal(L, "arg");
Expand Down
14 changes: 6 additions & 8 deletions source/modules/love/scripts/arg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ R"luastring"--(
-- There is a matching delimiter at the bottom of the file.

--[[
Copyright (c) 2006-2021 LOVE Development Team
Copyright (c) 2006-2024 LOVE Development Team
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -45,7 +45,6 @@ end

-- Checks whether a path is absolute or not.
function love.path.abs(p)

local tmp = love.path.normalslashes(p)

-- Path is absolute if it starts with a "/".
Expand All @@ -61,7 +60,6 @@ function love.path.abs(p)

-- Relative.
return false

end

-- Converts any path into a full path.
Expand All @@ -71,7 +69,6 @@ function love.path.getFull(p)
end

local cwd = love.filesystem.getWorkingDirectory()

cwd = love.path.normalslashes(cwd)
cwd = love.path.endslash(cwd)

Expand Down Expand Up @@ -115,7 +112,9 @@ end
love.arg.options = {
console = { a = 0 },
fused = { a = 0 },
game = { a = 1 }
game = { a = 1 },
renderers = { a = 1 },
excluderenderers = { a = 1 },
}

love.arg.optionIndices = {}
Expand All @@ -131,11 +130,10 @@ function love.arg.parseOption(m, i)
end
end

table.insert(m.arg, "game")
return m.a
end

function love.arg.parseOptions()
function love.arg.parseOptions(arg)
local game
local argc = #arg

Expand All @@ -147,7 +145,7 @@ function love.arg.parseOptions()
if m and m ~= "" and love.arg.options[m] and not love.arg.options[m].set then
love.arg.optionIndices[i] = true
i = i + love.arg.parseOption(love.arg.options[m], i + 1)
elseif m == "" then -- handle '--' as an option
elseif m == "" then -- handle '--' as an option
love.arg.optionIndices[i] = true
if not game then -- handle '--' followed by game name
game = i + 1
Expand Down
23 changes: 3 additions & 20 deletions source/modules/love/scripts/boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ local function uridecode(s)
end)
end

local function https_setup_certs()
local https = require("https")

if love._os == "Cafe" then
return https.setCertificateFile("/sdcard/config/ssl/cacert.pem")
end
https.setCertificateFile("sdmc/config/ssl/cacert.pem")
end

local no_game_code = false
local invalid_game_path = nil
local main_file = "main.lua"
Expand All @@ -56,7 +47,6 @@ function love.boot()
love.rawGameArguments = arg

local arg0 = love.arg.getLow(love.rawGameArguments)

love.filesystem.init(arg0)

local exepath = love.filesystem.getExecutablePath()
Expand Down Expand Up @@ -108,11 +98,10 @@ function love.boot()
main_file = source_leaf
custom_main_file = true
full_source = love.path.getFull(full_source:sub(1, -(#source_leaf + 1)))
elseif nouri:match("%.love$") then
full_source = nouri
end

can_has_game = pcall(love.filesystem.setSource, full_source)

if not can_has_game then
invalid_game_path = full_source
end
Expand All @@ -134,23 +123,17 @@ function love.boot()
identity = identity:gsub("^([%.]+)", "") -- strip leading "."'s
identity = identity:gsub("%.([^%.]+)$", "") -- strip extension
identity = identity:gsub("%.", "_") -- replace remaining "."'s with "_"
identity = #identity > 0 and identity or "game"
identity = #identity > 0 and identity or "lovegame"

-- When conf.lua is initially loaded, the main source should be checked
-- before the save directory (the identity should be appended.)
pcall(love.filesystem.setIdentity, identity, true)

local has_main_file = love.filesystem.getInfo(main_file)
local has_conf_file = love.filesystem.getInfo("conf.lua")

if can_has_game and not (has_main_file or (not custom_main_file and has_conf_file)) then
if can_has_game and not (love.filesystem.getInfo(main_file) or (not custom_main_file and love.filesystem.getInfo("conf.lua"))) then
no_game_code = true
end

-- https_setup_certs()

if not can_has_game then
invalid_game_path = false
local nogame = require("love.nogame")
nogame()
end
Expand Down
2 changes: 1 addition & 1 deletion source/modules/love/scripts/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ end

function love.run()
if love.load then
love.load(arg)
love.load(love.parsedGameArguments, love.rawGameArguments)
end

if love.timer then
Expand Down

0 comments on commit 60db149

Please sign in to comment.