fixed a massive bug

This commit is contained in:
IonutParau 2025-10-01 16:53:49 +02:00
parent d9ec88dd51
commit b46c6f6dc8
2 changed files with 25 additions and 19 deletions

View File

@ -15,6 +15,7 @@ fn addEngineSources(b: *std.Build, opts: LibBuildOpts) *std.Build.Module {
.optimize = opts.optimize, .optimize = opts.optimize,
.strip = if(opts.optimize == .Debug) false else true, .strip = if(opts.optimize == .Debug) false else true,
.unwind_tables = if(opts.optimize == .Debug) null else .none, .unwind_tables = if(opts.optimize == .Debug) null else .none,
.pic = true,
}); });
const strict = opts.optimize != .Debug; const strict = opts.optimize != .Debug;
@ -89,20 +90,23 @@ fn compileTheRightLua(b: *std.Build, target: std.Build.ResolvedTarget, version:
const dirName = @tagName(version); const dirName = @tagName(version);
// its a static library because COFF is a pile of shit // its a static library because COFF is a pile of shit
const c = b.addStaticLibrary(.{ const c = b.addLibrary(.{
.name = "lua", .name = "lua",
.link_libc = true, .root_module = b.addModule("luamod", .{
.optimize = .ReleaseFast, .link_libc = true,
.target = target, .optimize = .ReleaseFast,
.target = target,
}),
.linkage = .static,
}); });
const rootPath = try std.mem.join(alloc, std.fs.path.sep_str, &.{ "foreign", dirName }); const rootPath = try std.mem.join(alloc, std.fs.path.sep_str, &.{ "foreign", dirName });
// get all the .c files // get all the .c files
var files = std.ArrayList([]const u8).init(alloc); var files = try std.ArrayList([]const u8).initCapacity(b.allocator, 0);
errdefer files.deinit(); errdefer files.deinit(b.allocator);
var dir = try std.fs.cwd().openDir(rootPath, std.fs.Dir.OpenDirOptions{ .iterate = true }); var dir = try std.fs.cwd().openDir(rootPath, std.fs.Dir.OpenOptions { .iterate = true });
defer dir.close(); defer dir.close();
var iter = dir.iterate(); var iter = dir.iterate();
@ -110,7 +114,7 @@ fn compileTheRightLua(b: *std.Build, target: std.Build.ResolvedTarget, version:
while (try iter.next()) |e| { while (try iter.next()) |e| {
if (std.mem.startsWith(u8, e.name, "l") and std.mem.endsWith(u8, e.name, ".c") and !std.mem.eql(u8, e.name, "lua.c")) { if (std.mem.startsWith(u8, e.name, "l") and std.mem.endsWith(u8, e.name, ".c") and !std.mem.eql(u8, e.name, "lua.c")) {
const name = try alloc.dupe(u8, e.name); const name = try alloc.dupe(u8, e.name);
try files.append(name); try files.append(b.allocator, name);
} }
} }
@ -151,18 +155,16 @@ pub fn build(b: *std.Build) !void {
const engineMod = addEngineSources(b, opts); const engineMod = addEngineSources(b, opts);
const engineStatic = b.addStaticLibrary(.{ const engineStatic = b.addLibrary(.{
.name = "neonucleus", .name = "neonucleus",
.root_module = engineMod, .root_module = engineMod,
.pic = true, .linkage = .static,
.code_model = .default,
}); });
const engineShared = b.addSharedLibrary(.{ const engineShared = b.addLibrary(.{
.name = if(os == .windows) "neonucleusdll" else "neonucleus", .name = if(os == .windows) "neonucleusdll" else "neonucleus",
.root_module = engineMod, .root_module = engineMod,
.pic = true, .linkage = .dynamic,
.code_model = .default,
}); });
const engineStep = b.step("engine", "Builds the engine as a static library"); const engineStep = b.step("engine", "Builds the engine as a static library");
@ -178,8 +180,10 @@ pub fn build(b: *std.Build) !void {
if(!noEmu) { if(!noEmu) {
const emulator = b.addExecutable(.{ const emulator = b.addExecutable(.{
.name = "neonucleus", .name = "neonucleus",
.target = target, .root_module = b.addModule("emulator", .{
.optimize = optimize, .target = target,
.optimize = optimize,
}),
}); });
emulator.linkLibC(); emulator.linkLibC();

View File

@ -565,15 +565,16 @@ static nn_vfilesystemImageNode nni_vfsimg_nextNode(nn_vfilesystemImage *stream)
return node; return node;
} }
static nn_vfnode *nni_vfsimg_parseNode(nn_vfilesystem *fs, nn_vfilesystemImage *stream) { static nn_vfnode *nni_vfsimg_parseNode(nn_vfilesystem *fs, nn_vfilesystemImage *stream, nn_vfnode *parent) {
// TODO: make this handle OOMs // TODO: make this handle OOMs
nn_vfilesystemImageNode node = nni_vfsimg_nextNode(stream); nn_vfilesystemImageNode node = nni_vfsimg_nextNode(stream);
if(node.data == NULL) { if(node.data == NULL) {
// directory!!!!! // directory!!!!!
nn_vfnode *dir = nn_vf_allocDirectory(fs, node.name); nn_vfnode *dir = nn_vf_allocDirectory(fs, node.name);
dir->len = node.len; dir->len = node.len;
dir->parent = parent;
for(int i = 0; i < node.len; i++) { for(int i = 0; i < node.len; i++) {
nn_vfnode *entry = nni_vfsimg_parseNode(fs, stream); nn_vfnode *entry = nni_vfsimg_parseNode(fs, stream, dir);
dir->entries[i] = entry; dir->entries[i] = entry;
} }
return dir; return dir;
@ -582,6 +583,7 @@ static nn_vfnode *nni_vfsimg_parseNode(nn_vfilesystem *fs, nn_vfilesystemImage *
nn_vfnode *file = nn_vf_allocFile(fs, node.name); nn_vfnode *file = nn_vf_allocFile(fs, node.name);
nn_vf_ensureFileCapacity(file, node.len); nn_vf_ensureFileCapacity(file, node.len);
file->len = node.len; file->len = node.len;
file->parent = parent;
nn_memcpy(file->data, node.data, node.len); nn_memcpy(file->data, node.data, node.len);
return file; return file;
} }
@ -606,7 +608,7 @@ nn_filesystem *nn_volatileFilesystem(nn_Context *context, nn_vfilesystemOptions
// we got supplied an image, shit // we got supplied an image, shit
fs->root->len = opts.rootEntriesInImage; fs->root->len = opts.rootEntriesInImage;
for(int i = 0; i < opts.rootEntriesInImage; i++) { for(int i = 0; i < opts.rootEntriesInImage; i++) {
nn_vfnode *entry = nni_vfsimg_parseNode(fs, &stream); nn_vfnode *entry = nni_vfsimg_parseNode(fs, &stream, fs->root);
fs->root->entries[i] = entry; fs->root->entries[i] = entry;
} }
} }