local util = require('util') return function(app) local config = { -- default name = "XRForge", baseurl="/", title="Your XR Forge", subtitle="Portable XR experiences for Phone, VRheadset & desktop.", admin_title = "XRForge Admin", admin_subtitle = "Manage your XR experiences here", } local configfile = "xrforge.lua" local savedconfig = util.readfile( app.bindir .. configfile, 'r', true) -- check local config or LoadAsset(configfile) -- then internal saved config if savedconfig then local eval = function(str) return load(str)() end local status, result = pcall(eval, savedconfig ) -- Pass "string" as the first argument if not status then print("error: xrforge.lua contains errors:") else config = result -- overrule default config end end app.on('set', function(k,v) if k == 'app.opts' then app.opts = v app.opts.updated = os.time() local newconfig = [[ -- TIP: run 'xrforge.com createplugin' to start writing plugins app.on('init', function() print('config loaded') local scan = app.scan app.scan = function() os.execute("echo scan before-hook") scan() os.execute("echo scan after-hook") end end) ]] .. "\n\nreturn " .. util.dump(app.opts) newconfig = newconfig:gsub("^}$"," init = function() print('xrforge.lua config loaded') end\n}") util.writefile( app.bindir .. configfile, newconfig ) print("stored xrforge.lua") end end) -- store local config if not exist if not util.readfile( app.bindir .. configfile, 'r', true) then app.set('app.opts', config ) end return config end