diff --git a/src/c/lnative.c b/src/c/lnative.c index af03e55..98a8ef2 100644 --- a/src/c/lnative.c +++ b/src/c/lnative.c @@ -325,6 +325,21 @@ static int l_uptime (lua_State *L) { //Return ms return 1; } +static int l_totalMemory (lua_State *L) { + long pages = sysconf(_SC_PHYS_PAGES); + long page_size = sysconf(_SC_PAGE_SIZE); + lua_pushnumber(L, pages * page_size); + return 1; +} + +static int l_freeMemory (lua_State *L) { + long pages = sysconf(_SC_AVPHYS_PAGES); + long page_size = sysconf(_SC_PAGE_SIZE); + lua_pushnumber(L, pages * page_size); + return 1; +} + + void luanative_start(lua_State *L) { lua_createtable (L, 0, 1); @@ -348,6 +363,8 @@ void luanative_start(lua_State *L) { pushctuple(L, "beep", l_beep); pushctuple(L, "uptime", l_uptime); + pushctuple(L, "totalMemory", l_totalMemory); + pushctuple(L, "freeMemory", l_freeMemory); lua_setglobal(L, "native"); } \ No newline at end of file diff --git a/src/lua/core/component.lua b/src/lua/core/component.lua index bd7b91c..a8590e2 100644 --- a/src/lua/core/component.lua +++ b/src/lua/core/component.lua @@ -122,4 +122,8 @@ function api.proxy(address) return components[address].proxy end +function api.slot() --legacy + return 0 +end + return component diff --git a/src/lua/core/computer.lua b/src/lua/core/computer.lua index e005815..531cf3e 100644 --- a/src/lua/core/computer.lua +++ b/src/lua/core/computer.lua @@ -2,10 +2,16 @@ local computer = {} local api = {} computer.api = api +--computer.tmp - set in init.lua + function computer.prepare( ... ) end +function api.address() + return modules.address +end + local signalQueue = {} function api.pushSignal(...) @@ -31,4 +37,17 @@ function api.beep(freq, time) native.beep(freq, time * 1000) end +function api.tmpAddress() + return computer.tmp +end + + +function api.freeMemory() + return native.freeMemory() +end + +function api.totalMemory() + return native.totalMemory() +end + return computer \ No newline at end of file diff --git a/src/lua/core/init.lua b/src/lua/core/init.lua index 5bed66d..0585b91 100644 --- a/src/lua/core/init.lua +++ b/src/lua/core/init.lua @@ -15,6 +15,7 @@ function checkArg(n, have, ...) end ------------------------------------------------------------------------------- +math.randomseed(native.uptime())--TODO: Make it better? print("LuPI L1 INIT") modules = {} @@ -45,6 +46,8 @@ function main() loadModule("utf8data") loadModule("utf8") + modules.address = modules.random.uuid() --TODO: PREALPHA: Make constant + --Core loadModule("component") loadModule("computer") @@ -64,6 +67,7 @@ function main() modules.eeprom.register() modules.filesystem.register("root") + modules.computer.tmp = modules.filesystem.register("/tmp/" .. modules.random.uuid()) modules.textgpu.start() modules.boot.boot()