I don't know if you've tried a fresh install but kitten isn't rendering for me. I've tried to track it down but alas I can't find the issue.. Also, I know I should probably make a fresh issue but.. there are a couple little things I've stumbled across.
function browser:spawn_renderer()
-- This isn't actually a thread. renderer.main_loop is just being called and running infinitely.
return thread.create(renderer.main_loop(renderer,self))
end
function browser:spawn_renderer()
-- thread.create takes a function value and passes the args at thread start
return thread.create(renderer.main_loop, renderer, self)
end
After thinking about it some more, we shouldn't really bother saving scripts themselves to a file but rather the whole page(if we care to cache them). Scripts will also need some sort of environment with relevant object to manipulate the page.
function browser:parse_dom(page)
local parser = xml.newParser()
self.dom = parser:ParseXmlText(page)
self.scripts = {}
self.script_env = { -- we should consider pointing to a sandbox
dom = self.dom
}
for i, node in ipairs(self.dom:children()) do
if node:name() == "script" then
-- no need to cache scripts really..
local ok, result = pcall(load, node:value(), "=script["..tostring(i).."]", "t", self.script.env)
if ok then
table.insert(self.scripts, result)
else
-- we can do better :p
print("script "..tostring(i)..":", "error loading script")
end
end
end
end
Dunno if the renderer is the best place to execute scripts.. Not that it really matters unless kitten becomes a big kitty. Also we may want to execute scripts after the page has rendered.
function renderer:main_loop(browser)
while true do
gpu.setBackground(0x000000)
term.clear()
for _, v in ipairs(browser.dom:children()) do
self:render(v)
end
for _, script in ipairs(browser.scripts) do
-- we don't need to return an object per script anymore. just run the code block.
script(browser) -- no more script:run(browser)
end
-- If we're using threads not much sense in using os.sleep. We can push updates at intervals
-- such as every second or better yet only when the dom has been modified.
event.pull("render_update")
end
end
These are just a couple ideas I had while looking deeper at the code whilst trying to find out why a fresh kitten install won't render.. (still haven't figured that out yet :/)