From 7f5d84ee5e484c205cc088fcd740211b198e45a7 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Thu, 6 Aug 2026 16:43:17 +0200 Subject: [PATCH] crossplatform optimisation --- README.md | 6 ++++++ src/.init.lua | 15 ++++++--------- src/page/admin/index.lua | 8 ++++++++ src/page/janusxr.html | 22 +++++++++++++++------- src/plugin/janusxr.lua | 3 +-- src/test/cheatsheet.txt | 10 ++++++++++ src/test/main.lua | 1 + src/test/plugin_diskscan.lua | 19 +++++++++++++++++++ src/test/plugin_xrfragment.lua | 30 ++++++++++++++++++++++++++++++ src/util/xrforge.sh | 16 +++++++++++++--- src/xrforge.lua | 1 - 11 files changed, 109 insertions(+), 22 deletions(-) create mode 100644 src/test/cheatsheet.txt create mode 100644 src/test/plugin_xrfragment.lua delete mode 120000 src/xrforge.lua diff --git a/README.md b/README.md index 913fae6..5c0f3e8 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,8 @@ Archive: result/bin/xrforge.com > Profit! you have aqcuired the sourcecode from the binary: run and distribute modified versions if needed ♥ +**NOTE**: if the binary does not work on your server, use [xrforge-x86_64]() from the releases section instead. + ## Adding content First you need a directory with glTF or JanusXR experiences.
@@ -167,6 +169,10 @@ Then run with debug flag to see output of `trace()` calls $ DEBUG=1 result/bin/xrforge.com ``` +> Testing: run the builtin testrunner: `cd src && ../result/bin/xrforge.com test` + +Use `ARCH=x86_64 build` to enforce x86_64 output (instead of a cosmopolitan binary) + ## Permacomputing Spirit * developed on [Dillo](https://dillo-browser.github.io/) as lowest common denominator / compatibility diff --git a/src/.init.lua b/src/.init.lua index 38138e8..d4b469c 100644 --- a/src/.init.lua +++ b/src/.init.lua @@ -1,8 +1,9 @@ -package.path = package.path .. ";.lua/?.lua" +package.path = package.path .. ";/zip/?.lua" package.path = package.path .. ";src/.lua/?.lua" -package.path = package.path .. ";middleware/?.lua" -package.path = package.path .. ";cmd/?.lua" -package.path = package.path .. ";plugin/?.lua" +package.path = package.path .. ";.lua/?.lua;/zip/.lua/?.lua" +package.path = package.path .. ";middleware/?.lua;/zip/middleware/?.lua" +package.path = package.path .. ";cmd/?.lua;/zip/cmd/?.lua" +package.path = package.path .. ";plugin/?.lua;/zip/plugin/?.lua" util = require "util" json = require "json" @@ -14,7 +15,7 @@ HidePath('/usr/share/ssl/') -- create app = require("soakbean") { bin = "./xrforge.com", - bindir = arg[-1]:gsub("xrforge.com",""), + bindir = arg[-1]:gsub("/[a-zA-Z0-9-_ ]+.com$","/"), cache = { items = {}, url = {} }, plugin = {}, opts = {}, @@ -116,7 +117,3 @@ end OnServerStart = function() app.init() -- this triggers init event end - -OnServerStop = function() - print("todo: kill threads") -end diff --git a/src/page/admin/index.lua b/src/page/admin/index.lua index 75bfdc9..94998fd 100644 --- a/src/page/admin/index.lua +++ b/src/page/admin/index.lua @@ -52,6 +52,14 @@ function pluginInput(opt) return html end +app.on('set', function(k,v) -- clear url cache + if k:match("app.opts") then -- after (admin) updates to app.opts.* + foreach( app.cache.url, function(k,v) + app.cache.url = nil + end) + end +end) + function pluginUI(seen,data) return function(name,plugin) if seen[ plugin.name ] then return end -- already processed diff --git a/src/page/janusxr.html b/src/page/janusxr.html index 5cc6deb..99f5dfc 100644 --- a/src/page/janusxr.html +++ b/src/page/janusxr.html @@ -1,3 +1,9 @@ +{if true then + showfediportals = app.opts.plugin_federation_strategy == 'always' or + (app.opts.plugin_federation_strategy == 'homepage' and urlpath == '/') +end} + + @@ -6,12 +12,14 @@ print('\t') end end} - {for i=1,5 do - local urls = app.opts[ 'plugin_federation_url_' .. i] - if #urls > 0 then - local fediurl = urls:gsub(' .*','') - local thumburl = urls:gsub('.* ','') - print('\t') + {if showfediportals then + for i=1,5 do + local urls = app.opts[ 'plugin_federation_url_' .. i] + if #urls > 0 then + local fediurl = urls:gsub(' .*','') + local thumburl = urls:gsub('.* ','') + print('\t') + end end end} @@ -49,7 +57,7 @@ addPortal('dir',center, v, url,i, -4, 'img', '0 0 0', '0.2 0.2 0.2') end end} - {if not item then + {if showfediportals and not item then local portals = {} for i=1,5 do local urls = app.opts[ 'plugin_federation_url_' .. i] diff --git a/src/plugin/janusxr.lua b/src/plugin/janusxr.lua index 3f63a73..c9250c2 100644 --- a/src/plugin/janusxr.lua +++ b/src/plugin/janusxr.lua @@ -113,15 +113,14 @@ local plugin = { getRandomRoom = function() local me = app.plugin.janusxr local room= '' + math.randomseed(os.time()) foreach( me.opts, function(k,v) - print(v.key) if v.key == 'app.opts.plugin_janusxr_portalroom' then local ordered = {} foreach( v.values, function(k,v) table.insert(ordered,v) end) room = ordered[ math.random( #ordered ) ] end end) - print("ROOM = " .. room) return room end } diff --git a/src/test/cheatsheet.txt b/src/test/cheatsheet.txt new file mode 100644 index 0000000..be53e34 --- /dev/null +++ b/src/test/cheatsheet.txt @@ -0,0 +1,10 @@ +expect(...).to.exist() +expect(...).to.be.truthy() +expect(...).to.be.falsy() +expect(...).to.be(...) +expect(...).to.equal(...) +expect(...).to.approximately.equal(...) +expect(...).to.approximately(eps).equal(...) +expect(t).to.have(val) +expect(f).to.fail(pattern?) +expect(x).to_not.* diff --git a/src/test/main.lua b/src/test/main.lua index 721debc..46c8778 100644 --- a/src/test/main.lua +++ b/src/test/main.lua @@ -3,6 +3,7 @@ local describe, it, expect = lust.describe, lust.it, lust.expect -- usage: https://github.com/bjornbytes/lust require('test/plugin_diskscan')(lust) +require('test/plugin_xrfragment')(lust) if lust.errors == 0 then print("✅ all tests passed") diff --git a/src/test/plugin_diskscan.lua b/src/test/plugin_diskscan.lua index 5a0b6f1..d1b6494 100755 --- a/src/test/plugin_diskscan.lua +++ b/src/test/plugin_diskscan.lua @@ -21,4 +21,23 @@ return function(lust) end) + describe('src/plugin/diskscan.lua (e2e)', function() + + describe('ℹ️ scan_experience', function() -- Can be nested + + local dirs = 0 + + app.on('scan_experience', function(exp) + if exp.dir then dirs = dirs +1 end + end) + + it('on init', function() + app.init() + expect(dirs > 0).to.be.truthy() + end) + + end) + + end) + end diff --git a/src/test/plugin_xrfragment.lua b/src/test/plugin_xrfragment.lua new file mode 100644 index 0000000..7917e09 --- /dev/null +++ b/src/test/plugin_xrfragment.lua @@ -0,0 +1,30 @@ +return function(lust) + + + local describe, it, expect = lust.describe, lust.it, lust.expect + + describe('src/plugin/xrfragments.lua', function() + + describe('ℹ️ detect sidecarfiles', function() -- Can be nested + + local sidecarfile = {} + + it('on init', function() + app.init() + foreach(app.cache.items, function(k,exp) + if exp.sidecarfile then + foreach( {"png","vtt","ogg","json"}, function(k,ext) + if exp.sidecarfile[k] then sidecarfile[ext] = true end + end) + end + end) + print_r(sidecarfile) + expect( (sidecarfile.png ~= nil) ).to.be.truthy() + expect( (sidecarfile.vtt ~= nil) ).to.be.truthy() + end) + + end) + + end) + +end diff --git a/src/util/xrforge.sh b/src/util/xrforge.sh index 4ebe2ec..e89da1d 100755 --- a/src/util/xrforge.sh +++ b/src/util/xrforge.sh @@ -12,11 +12,21 @@ download(){ verify(){ echo "$REDBEAN_CRC" > /tmp/checksum sha256sum -c /tmp/checksum || { echo "psuedosecurity checksum failed"; exit 1; } - chmod +x $OUTDIR/xrforge.com } - test -f /tmp/xrforge.com || wget --no-check-certificate "$REDBEAN_URL" -O /tmp/xrforge.com + test -f /tmp/xrforge.com || { + wget --no-check-certificate "$REDBEAN_URL" -O /tmp/xrforge.com + } cp /tmp/xrforge.com $OUTDIR/xrforge.com - verify + test -n "$ARCH" && { + test -f /tmp/assimilate || { + wget https://cosmo.zip/pub/cosmos/bin/assimilate-x86_64.elf -O /tmp/assimilate + chmod +x /tmp/assimilate + } + rm $OUTDIR/*.bak || true + /tmp/assimilate $OUTDIR/xrforge.com + } + chmod +x $OUTDIR/*.com + #verify } janusweb(){ diff --git a/src/xrforge.lua b/src/xrforge.lua deleted file mode 120000 index c58510a..0000000 --- a/src/xrforge.lua +++ /dev/null @@ -1 +0,0 @@ -../result/bin/xrforge.lua \ No newline at end of file