56 lines
1.5 KiB
Lua
56 lines
1.5 KiB
Lua
-- The following api-calls need the unixy extension,
|
|
-- so we init them via an adhoc extension here:
|
|
|
|
api.ext.lua = {
|
|
|
|
enabled = true,
|
|
|
|
main = function()
|
|
-- main loop
|
|
local last_time = os.clock()
|
|
api.ecs.filterUpdate = api.ecs.requireAll('updatethread')
|
|
api.ecs.filterDraw = api.ecs.requireAll('drawthread')
|
|
|
|
while true do
|
|
local current_time = os.clock()
|
|
local dt = current_time - last_time
|
|
last_time = current_time
|
|
-- update extensions
|
|
api.ext.exec("update", dt)
|
|
api.ecs.update( api.world, dt, api.ecs.filterUpdate )
|
|
end
|
|
end,
|
|
|
|
init = function()
|
|
|
|
-- reroute http request
|
|
if not api.protocol.http then
|
|
|
|
api.protocol.http = {}
|
|
|
|
-- via wget
|
|
api.protocol.http.request = api.ext.unixy.proxyCLI(
|
|
"wget",
|
|
function(url,opts, cb) return string.format( "out=$(mktemp); wget -O $out %s; cat $out; rm $out", url ) end,
|
|
function( stdout, stderr, retcode, url, opts, cb)
|
|
local status = 200
|
|
if retcode ~= 'exit' then status = 500 end
|
|
cb( status, stdout, {string = stderr, retcode = retcode})
|
|
end
|
|
)
|
|
|
|
-- via curl
|
|
api.protocol.http.request = api.ext.unixy.proxyCLI(
|
|
"curl",
|
|
function(url,opts, cb) return string.format( "curl -v -s %s", url ) end,
|
|
function( stdout, stderr, retcode, url, opts, cb)
|
|
local status = 200
|
|
if retcode ~= 'exit' then status = 500 end
|
|
cb( status, stdout, {string = stderr, retcode = retcode})
|
|
end
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
}
|