GithubHelp home page GithubHelp logo

kore-signet / alis-opencomputers Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 2.0 11 KB

A web browser for OpenComputers, with a DOM tree and working scripts. + Nest, a simple "web" server and Pathfinder, a simple "dns" server

Lua 100.00%

alis-opencomputers's Introduction

pronouns - it/its trans - rights

hi i'm kore signet

maker of weird little search engines and compression systems. ๐Ÿฆ€ programmer reach out to me at kore at cat-girl.gay

alis-opencomputers's People

Contributors

kore-signet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

anonyes webserfer

alis-opencomputers's Issues

kitten script loading

I want to re-work how scripts are loaded and stored. Storing them in /lib is going to pollute the dir and although new pages will overwrite say .0.lua and so on eventually there will be leftover scripts just lingering. Also it would be nice if multiple scripts shared an environment so the browser could expose variables and scripts can share them as well as some states.

function browser:parse_dom(page, page_name)
  self.dom = xml.newParser()
  self.dom = self.dom:ParseXmlText(page)

  self.scripts = {}
  self.script_env = {}
  local counter = 0 -- maybe this could be a hash string instead? uuid?
  for _, v in ipairs(self.dom:children()) do
    if v:name() == "script" then
      -- if scripts had hashes then we could cache them and only serve updated scripts?..
      local script_path = "/tmp/kitten/page_name." .. counter  .. ".lua"
      local f = io.open(script_path, "w")
      f:write(v:value())
      f:close()
      -- now we wont need to define script:run() in each script. When the dom is loaded
      --   we can just loop over self.scripts i.e self.scripts[n](window)
      local script = load(script_path, "="..script_path, "t", self.script_env)
      table.insert(self.scripts, script) -- save script to execute later.
      counter = counter + 1
    end
  end
end

Fresh install not rendering

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 :/)

kitten not working

the kitten file args gives me errors
and when l try to run kitten it wont run

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.