LuPPC/src/lua/core/computer.lua

53 lines
943 B
Lua
Raw Normal View History

2016-01-06 08:29:49 +11:00
local computer = {}
2016-01-07 02:58:05 +11:00
local api = {}
computer.api = api
2016-01-05 04:20:40 +11:00
2016-01-14 12:13:00 +11:00
--computer.tmp - set in init.lua
2016-01-06 08:29:49 +11:00
function computer.prepare( ... )
end
2016-01-14 12:13:00 +11:00
function api.address()
return modules.address
end
2016-01-14 11:10:04 +11:00
local signalQueue = {}
2016-01-07 02:58:05 +11:00
function api.pushSignal(...)
2016-01-14 11:10:04 +11:00
signalQueue[#signalQueue + 1] = {...}
2016-01-07 02:58:05 +11:00
end
2016-01-13 11:12:01 +11:00
function api.pullSignal(timeout)
2016-01-14 11:10:04 +11:00
if signalQueue[1] then return table.remove(signalQueue, 1) end
2016-01-13 11:12:01 +11:00
if type(timeout) == "number" then
native.sleep(timeout * 1000000);
end
2016-01-14 11:10:04 +11:00
if signalQueue[1] then return table.remove(signalQueue, 1) end
2016-01-13 11:12:01 +11:00
--print(debug.traceback())
end
function api.uptime()
2016-01-13 11:15:51 +11:00
return native.uptime() / 1000
2016-01-13 11:12:01 +11:00
end
2016-01-10 05:39:48 +11:00
function api.beep(freq, time)
2016-01-13 11:12:01 +11:00
if not freq then freq = 1000 end
if not time then time = 0.2 end
native.beep(freq, time * 1000)
2016-01-10 05:39:48 +11:00
end
2016-01-14 12:13:00 +11:00
function api.tmpAddress()
return computer.tmp
end
function api.freeMemory()
return native.freeMemory()
end
function api.totalMemory()
return native.totalMemory()
end
2016-01-06 08:29:49 +11:00
return computer