Memory checking functions

This commit is contained in:
Łukasz Magiera 2016-01-14 02:13:00 +01:00
parent 44aabacc4c
commit ffc3705ea8
4 changed files with 44 additions and 0 deletions

View File

@ -325,6 +325,21 @@ static int l_uptime (lua_State *L) { //Return ms
return 1; 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) { void luanative_start(lua_State *L) {
lua_createtable (L, 0, 1); lua_createtable (L, 0, 1);
@ -348,6 +363,8 @@ void luanative_start(lua_State *L) {
pushctuple(L, "beep", l_beep); pushctuple(L, "beep", l_beep);
pushctuple(L, "uptime", l_uptime); pushctuple(L, "uptime", l_uptime);
pushctuple(L, "totalMemory", l_totalMemory);
pushctuple(L, "freeMemory", l_freeMemory);
lua_setglobal(L, "native"); lua_setglobal(L, "native");
} }

View File

@ -122,4 +122,8 @@ function api.proxy(address)
return components[address].proxy return components[address].proxy
end end
function api.slot() --legacy
return 0
end
return component return component

View File

@ -2,10 +2,16 @@ local computer = {}
local api = {} local api = {}
computer.api = api computer.api = api
--computer.tmp - set in init.lua
function computer.prepare( ... ) function computer.prepare( ... )
end end
function api.address()
return modules.address
end
local signalQueue = {} local signalQueue = {}
function api.pushSignal(...) function api.pushSignal(...)
@ -31,4 +37,17 @@ function api.beep(freq, time)
native.beep(freq, time * 1000) native.beep(freq, time * 1000)
end end
function api.tmpAddress()
return computer.tmp
end
function api.freeMemory()
return native.freeMemory()
end
function api.totalMemory()
return native.totalMemory()
end
return computer return computer

View File

@ -15,6 +15,7 @@ function checkArg(n, have, ...)
end end
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
math.randomseed(native.uptime())--TODO: Make it better?
print("LuPI L1 INIT") print("LuPI L1 INIT")
modules = {} modules = {}
@ -45,6 +46,8 @@ function main()
loadModule("utf8data") loadModule("utf8data")
loadModule("utf8") loadModule("utf8")
modules.address = modules.random.uuid() --TODO: PREALPHA: Make constant
--Core --Core
loadModule("component") loadModule("component")
loadModule("computer") loadModule("computer")
@ -64,6 +67,7 @@ function main()
modules.eeprom.register() modules.eeprom.register()
modules.filesystem.register("root") modules.filesystem.register("root")
modules.computer.tmp = modules.filesystem.register("/tmp/" .. modules.random.uuid())
modules.textgpu.start() modules.textgpu.start()
modules.boot.boot() modules.boot.boot()