More debug-mode stuff

This commit is contained in:
Łukasz Magiera 2016-02-11 21:45:46 +01:00
parent b06532228c
commit 574eed69e3
3 changed files with 23 additions and 5 deletions

View File

@ -10,9 +10,11 @@ local componentCallback = {
__tostring = function(self) return (components[self.address] ~= nil and components[self.address].doc[self.name] ~= nil) and components[self.address].doc[self.name] or "function" end __tostring = function(self) return (components[self.address] ~= nil and components[self.address].doc[self.name] ~= nil) and components[self.address].doc[self.name] or "function" end
} }
if native.debug then --Debug only
local start = native.uptime() local start = native.uptime()
local last = native.uptime() local last = native.uptime()
if native.debug then
componentCallback.__call = function(self, ...) componentCallback.__call = function(self, ...)
local t = {} local t = {}
for k,v in pairs({...}) do for k,v in pairs({...}) do
@ -89,6 +91,20 @@ function api.invoke(address, method, ...)
if not components[address].rawproxy[method] then if not components[address].rawproxy[method] then
error("No such method: " .. tostring(components[address].type) .. "." .. tostring(method)) error("No such method: " .. tostring(components[address].type) .. "." .. tostring(method))
end end
if native.debug then --TODO: This may generate little performance hit
local t = {}
for k,v in pairs({...}) do
if type(v) == "string" then
v = "\"" .. v .. "\""
end
t[k] = tostring(v)
end
local caller = debug.getinfo(2)
local msg = tostring((native.uptime() - start) / 1000) .. " [+" .. native.uptime() - last .. "] " .. caller.short_src .. ":".. caller.currentline .. " > c.invoke(" .. address .. "): "
.. components[address].type .. "." .. method
.. "(" .. table.concat(t, ", ") .. ")"
end
return components[address].rawproxy[method](...) return components[address].rawproxy[method](...)
end end

View File

@ -50,7 +50,7 @@ local function concat(pathA, pathB, ...)
return canonical(_concat(2, pathA, pathB, ...)) return canonical(_concat(2, pathA, pathB, ...))
end end
function filesystem.register(basePath) function filesystem.register(basePath, uuid)
checkArg(1, basePath, "string") checkArg(1, basePath, "string")
if not native.fs_exists(basePath) then if not native.fs_exists(basePath) then
@ -156,7 +156,7 @@ function filesystem.register(basePath)
checkArg(1, value, "number") checkArg(1, value, "number")
return value --TODO: Implement, use real labels return value --TODO: Implement, use real labels
end end
return modules.component.api.register(nil, "filesystem", fs) return modules.component.api.register(uuid, "filesystem", fs)
end end
return filesystem return filesystem

View File

@ -77,7 +77,9 @@ function main()
modules.eeprom.register() modules.eeprom.register()
modules.internet.start() modules.internet.start()
modules.filesystem.register("root") modules.filesystem.register("root")
modules.filesystem.register("/") --TODO: remove from release if native.debug then
modules.filesystem.register("/", "11111111-1111-1111-1111-111111111111")
end
modules.computer.tmp = modules.filesystem.register("/tmp/lupi-" .. modules.random.uuid()) modules.computer.tmp = modules.filesystem.register("/tmp/lupi-" .. modules.random.uuid())
modules.textgpu.start() modules.textgpu.start()