WIP fs impl

This commit is contained in:
2026-02-10 17:48:36 +01:00
parent c0d965be26
commit 9c5e4a3d5b
6 changed files with 842 additions and 83 deletions

View File

@@ -31,13 +31,13 @@ void *luaArch_alloc(void *ud, void *ptr, size_t osize, size_t nsize) {
return NULL;
}
if(ptr == NULL) {
if(arch->freeMem < nsize) return NULL;
//if(arch->freeMem < nsize) return NULL;
void *mem = malloc(nsize);
if(mem == NULL) return NULL;
arch->freeMem -= nsize;
return mem;
}
if(arch->freeMem + osize < nsize) return NULL;
//if(arch->freeMem + osize < nsize) return NULL;
void *mem = realloc(ptr, nsize);
if(mem == NULL) return NULL;
arch->freeMem += osize;
@@ -101,6 +101,19 @@ static void luaArch_nnToLua(luaArch *arch, size_t nnIdx) {
lua_pushboolean(L, nn_toboolean(C, nnIdx));
return;
}
if(nn_istable(C, nnIdx)) {
size_t start = nn_getstacksize(C);
size_t len;
nn_dumptable(C, nnIdx, &len);
lua_createtable(L, 0, len);
for(size_t i = 0; i < len; i++) {
luaArch_nnToLua(arch, start + i * 2);
luaArch_nnToLua(arch, start + i * 2 + 1);
lua_settable(L, -3);
}
nn_popn(C, len * 2);
return;
}
luaL_error(L, "bad NN value: %s", nn_typenameof(C, nnIdx));
}
@@ -214,6 +227,12 @@ static int luaArch_computer_shutdown(lua_State *L) {
return 0;
}
static int luaArch_computer_isOverused(lua_State *L) {
nn_Computer *c = luaArch_from(L)->computer;
lua_pushboolean(L, nn_componentsOverused(c));
return 1;
}
static int luaArch_component_list(lua_State *L) {
luaArch *arch = luaArch_from(L);
lua_createtable(L, 64, 0);
@@ -385,6 +404,8 @@ static void luaArch_loadEnv(lua_State *L) {
lua_setfield(L, computer, "setArchitecture");
lua_pushcfunction(L, luaArch_computer_shutdown);
lua_setfield(L, computer, "shutdown");
lua_pushcfunction(L, luaArch_computer_isOverused);
lua_setfield(L, computer, "isOverused");
lua_setglobal(L, "computer");
lua_createtable(L, 0, 10);
int component = lua_gettop(L);