support for Windows .love/.zip

This commit is contained in:
Zack Buhman 2026-03-22 16:54:15 -07:00
parent 8d33b39730
commit 0b30988408
5 changed files with 35 additions and 18 deletions

4
.gitignore vendored
View File

@ -4,6 +4,10 @@
*.pdb
*.idb
*.def
*.exe
*.zip
*.love
dist/
.~*
.\#*
\#*

View File

@ -96,7 +96,7 @@ pack_main: src/pack_main.o
.SUFFIXES:
.INTERMEDIATE:
.SECONDARY:
.PHONY: all clean phony
.PHONY: all clean phony dist
%: RCS/%,v
%: RCS/%

11
dist.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/sh
set -eux
rm -rf dist/
mkdir dist/
[ -f "test.so" ] && cp test.so dist/
[ -f "test.dll" ] && cp test.dll dist/
cp conf.lua main.lua dist/
( cd dist/ ; zip -r ../test.zip . )

View File

@ -39,33 +39,33 @@ void update(float time);
local platform = love.system.getOS()
local lib_name
local love_name
if platform == "Linux" then
lib_name = "test.so"
love_name = "love"
elseif platform == "Windows" then
lib_name = "test.dll"
love_name = "LOVE"
else
assert(false, "unsupported platform " .. platform)
end
if is_zip or is_love then
if love.filesystem.isFused() then
local archive = love.filesystem.getSourceBaseDirectory()
end
local contents, size = love.filesystem.read("data", "test.so")
local contents, size = love.filesystem.read("data", lib_name)
assert(contents ~= nil, size)
local write_success, message = love.filesystem.write("test.so", contents, size)
local write_success, message = love.filesystem.write(lib_name, contents, size)
assert(write_success, lib_name, message)
local app_data = love.filesystem.getAppdataDirectory()
-- the love2d "filesystem" API is the worst possible design in the
-- entire history of computing
if platform == "Linux" then
test = ffi.load(app_data .. "/love/love-demo2/test.so")
elseif platform == "Windows" then
test = ffi.load(app_data .. "/love/love-demo2/test.dll")
test = ffi.load(app_data .. "/" .. love_name .. "/love-demo2/" .. lib_name)
else
assert(false, "unsupported platform: " .. platform)
end
else
if platform == "Linux" then
test = ffi.load("./test.so")
elseif platform == "Windows" then
test = ffi.load("./test.dll")
else
assert(false, "unsupported platform: " .. platform)
end
test = ffi.load("./" .. lib_name)
end
test.load(source_path)
end

View File

@ -21,6 +21,8 @@ namespace file {
void const * read_file(const char * r_filename, int * out_size)
{
fprintf(stderr, "(pack) filename: %s\n", r_filename);
pack::header const * header = (pack::header const *)&_binary_test_pack_start[0];
assert(header->magic == pack::magic_value);
ptrdiff_t data = (ptrdiff_t)&_binary_test_pack_start[header->header_size];