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;
}
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");
}

View File

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

View File

@ -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

View File

@ -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()