diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2018-10-18 08:07:33 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2018-10-18 08:08:54 +0000 |
| commit | e38d6d5c8e098cff0c4eb941693edb5844d51411 (patch) | |
| tree | a4dd56bba857eff94ede46961d74703f1076a6a3 | |
| parent | animate CoM (diff) | |
| parent | fix realities (diff) | |
| download | mmm-e38d6d5c8e098cff0c4eb941693edb5844d51411.tar.gz mmm-e38d6d5c8e098cff0c4eb941693edb5844d51411.zip | |
Merge branch 'duct_tape'
| -rw-r--r-- | app/html.client.moon | 5 | ||||
| -rw-r--r-- | app/html.server.moon | 5 | ||||
| -rw-r--r-- | app/realities.moon | 50 | ||||
| -rw-r--r-- | duct_tape.moon | 132 | ||||
| -rw-r--r-- | server.moon | 4 |
5 files changed, 175 insertions, 21 deletions
diff --git a/app/html.client.moon b/app/html.client.moon index fdec714..77d6c51 100644 --- a/app/html.client.moon +++ b/app/html.client.moon @@ -28,8 +28,9 @@ element = (element) -> (...) -> elements = {} add = (e) -> elements[e] = element e -for e in *{'div', 'span', 'a', 'p', 'pre', 'button', 'ul', 'li', 'i', 'b', 'u', 'tt'} do add e -for e in *{'br', 'img', 'input', 'p'} do add e +for e in *{'div', 'form', 'span', 'a', 'p', 'button', 'ul', 'ol', 'li', 'i', 'b', 'u', 'tt'} do add e +for e in *{'article', 'section', 'header', 'footer', 'content'} do add e +for e in *{'br', 'hr', 'img', 'input', 'p', 'textarea'} do add e for i=1,8 do add "h" .. i elements diff --git a/app/html.server.moon b/app/html.server.moon index 6bd05e1..3a27b37 100644 --- a/app/html.server.moon +++ b/app/html.server.moon @@ -29,8 +29,9 @@ element = (element) -> (...) -> elements = {} add = (e) -> elements[e] = element e -for e in *{'div', 'span', 'a', 'p', 'pre', 'button', 'ul', 'li', 'i', 'b', 'u', 'tt'} do add e -for e in *{'br', 'img', 'input', 'p'} do add e +for e in *{'div', 'form', 'span', 'a', 'p', 'button', 'ul', 'ol', 'li', 'i', 'b', 'u', 'tt'} do add e +for e in *{'article', 'section', 'header', 'footer', 'content'} do add e +for e in *{'br', 'hr', 'img', 'input', 'p', 'textarea'} do add e for i=1,8 do add "h" .. i elements diff --git a/app/realities.moon b/app/realities.moon index b3c5020..d4713a0 100644 --- a/app/realities.moon +++ b/app/realities.moon @@ -1,8 +1,24 @@ -import append, tohtml, h1, h2, p, a, i, div, ol, li, br, hr, span, button, section, article from require 'app.component' +import append, h1, h2, p, a, i, div, ol, li, br, hr, span, button, section, article from require 'app.component' local Diagram, o GRID_W = 50 GRID_H = 40 + +on_client = switch MODE + when 'SERVER' + import compile from require 'duct_tape' + (fn, ...) -> + code = compile fn + -- warn code + append "<script type=\"application/lua\"> + local fn = #{code} + fn(#{table.concat { ... }, ', '}) + </script>" + when 'CLIENT' + (fn, ...) -> fn ... + +-- script https://cdnjs.cloudflare.com/ajax/libs/svg.js/2.6.6/svg.min.js + if MODE == 'CLIENT' require 'svg.js' eval = js.global\eval @@ -105,7 +121,6 @@ figures = do 'justify-content': 'space-evenly' (...) -> div { :style, ... } - sources = do short = (id) => "#{id} #{@year}" long = => @names, " (#{@year}): ", (i @title), ", #{@published}" @@ -189,32 +204,33 @@ append with article style: { margin: 'auto', 'max-width': '750px' } \append with sect "Terminology" \append p "We propose the following terms and definitions that will be used extensively for the remainder of the paper:" - for term, definition in pairs { - "layer of reality": "a closed system consisting of a world model and a set of rules or dynamics operating on and - constraining said model.", - "world model": "describes a world state containing objects, agents and/or concepts on an arbitrary abstraction level.", - break: 1, - "reality stack": "structure consisting of all layers of reality encoding an agent's interaction with his environment - in their world model at a given moment, as well as all layers supporting these respectively." - next: 2, - "physical reality": "layer of reality defined by physical matter and the physical laws acting upon it. + for definition in *{ + { "layer of reality": "a closed system consisting of a world model and a set of rules or dynamics operating on and + constraining said model." }, + { "world model": "describes a world state containing objects, agents and/or concepts on an arbitrary abstraction level." }, + '------', + { "reality stack": "structure consisting of all layers of reality encoding an agent's interaction with his environment + in their world model at a given moment, as well as all layers supporting these respectively." }, + '------', + { "physical reality": "layer of reality defined by physical matter and the physical laws acting upon it. While the emergent phenomena of micro- and macro physics as well as layers of social existence etc. may be seen - as separate layers, for the purpose of this paper we will group these together under the term of physical reality." - "mental reality": "layer of reality perceived and processed by the brain of a human agent.", - "digital reality": "layer of reality created and simulated by a digital system, e.g. a virtual reality game." - "phys, mind, digi": "abbreviations for physical, mental and digital reality respectively.", + as separate layers, for the purpose of this paper we will group these together under the term of physical reality." }, + { "mental reality": "layer of reality perceived and processed by the brain of a human agent." }, + { "digital reality": "layer of reality created and simulated by a digital system, e.g. a virtual reality game." }, + { "phys, mind, digi": "abbreviations for physical, mental and digital reality respectively." }, } - if 'number' == type definition + if 'string' == type definition \append hr! continue \append with div style: { 'margin-left': '2rem' } + term = next definition \append span term, style: { display: 'inline-block', 'margin-left': '-2rem', 'font-weight': 'bold', 'min-width': '140px' } - \append span definition + \append span definition[term] \append with sect "Introduction" \append p "We identify two different types of relationships between layers in multi-reality environments. diff --git a/duct_tape.moon b/duct_tape.moon new file mode 100644 index 0000000..53a3f56 --- /dev/null +++ b/duct_tape.moon @@ -0,0 +1,132 @@ +-- package.noompath = './?.noom;./?/init.noom' +package.noompath = './?.moon;./?/init.moon' + +export __FNDEF_NOOM_CACHE +__FNDEF_NOOM_CACHE = {} + +assert MODE == 'SERVER', "duct_tape only works on the server" + +compile = require 'moonscript.compile' +parse = require 'moonscript.parse' + +import smart_node, build from require 'moonscript.types' +import dirsep from require 'moonscript.base' +import get_options, unpack from require 'moonscript.util' + +line_tables = require 'moonscript.line_tables' +lua = :loadstring, :load + +local * + +escape_str = (str) -> + (str\gsub('\\', '\\\\')\gsub '"', '\\"'), nil + +deep_clone = (value) -> + if 'table' == type value + { deep_clone(k), deep_clone(v) for k,v in pairs value } + else -- number, string, boolean, etc + value + +transform_fndef = (fndef, parent, i) -> + -- compile the function to Lua separately + code, ltable, pos = compile.tree { deep_clone fndef } + if not code + return compile.format_error(ltable, pos, text) + + code = "(function() #{code} end)()" + + -- assign the lua code to __FNDEF_NOOM_CACHE[function] so it can be retrieved by `compile` + fn = -> { 'ref', 'fn' } + cache = build.chain { + base: '__FNDEF_NOOM_CACHE', + { 'index', fn! } + } + + parent[i] = build.do { + { 'declare_with_shadows', { 'fn' } } + build.assign_one fn!, fndef + build.assign_one cache, { 'string', '"', escape_str code } + -- build.assign_one cache, { 'string', '[[', code } + fn! + } + + nil + +find_fndefs = (node, p, i) -> + if node[1] == "fndef" + transform_fndef node, p, i + else + for i = 1,#node + v = node[i] + find_fndefs v, node, i if 'table' == type v + +to_lua = (text, options={}) -> + if "string" != type text + t = type text + return nil, "expecting string (got ".. t ..")" + + tree, err = parse.string text + if not tree + return nil, err + + find_fndefs tree + + code, ltable, pos = compile.tree tree, options + if not code + return nil, compile.format_error(ltable, pos, text) + + code, ltable + +noom_loader = (name) -> + name_path = name\gsub "%.", dirsep + + local file, file_path + for path in package.noompath\gmatch "[^;]+" + file_path = path\gsub "?", name_path + file = io.open file_path + break if file + + if file + text = file\read "*a" + file\close! + res, err = loadstring text, "@#{file_path}" + if not res + error file_path .. ": " .. err + + return res + + return nil, "Could not find noom file" + +loadstring = (...) -> + options, str, chunk_name, mode, env = get_options ... + chunk_name or= "=(noom.loadstring)" + + code, ltable_or_err = to_lua str, options + unless code + return nil, ltable_or_err + + line_tables[chunk_name] = ltable_or_err if chunk_name + + -- the unpack prevents us from passing nil + (lua.loadstring or lua.load) code, chunk_name, unpack { mode, env } + +do + local compile + insert_loader = (pos=2) -> + -- if not package.moonpath + -- package.moonpath = create_moonpath package.path + + loaders = package.loaders or package.searchers + for loader in *loaders + return false if loader == noom_loader + + table.insert loaders, pos, noom_loader + true + + compile = (fn) -> with code = __FNDEF_NOOM_CACHE[fn] + assert code, 'cannot compile function not loaded from noomscript source.' + + { + :insert_loader + :compile + } diff --git a/server.moon b/server.moon index 5a79039..fb33806 100644 --- a/server.moon +++ b/server.moon @@ -14,6 +14,9 @@ flush = -> with x = buffer buffer = '' +import insert_loader from require 'duct_tape' +insert_loader! + error "please specify the module to build as an argumnet" unless arg[1] require "app.#{arg[1]}" @@ -21,6 +24,7 @@ require "app.#{arg[1]}" print "<!DOCTYPE html> <html> <head> + <script src=\"fengari-web.js\"></script> <title>MMM: lunar low-gravity scripting playground</title> </head> <body> |
