diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-11-02 12:17:48 +0300 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-11-02 12:21:05 +0300 |
commit | 815028ef93480d58f93a1b76289c77fd34714bdc (patch) | |
tree | 70541f975fda68bd87d58bd98f217a7bf486cbcb /modules | |
parent | c99602e4ac72f4f6410449dd7175d52b974de9cc (diff) |
luci-base: runtime.uc: avoid Lua not installed exeption from trycompile()
Make sure to request loading the Lua bridge as optional when initializing
the Lua VM context from trycompile() in order to not raise a fatal exception
in case the Lua runtime support is not present.
Ref: https://forum.openwrt.org/t/x/141426
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/luci-base/ucode/runtime.uc | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/modules/luci-base/ucode/runtime.uc b/modules/luci-base/ucode/runtime.uc index d02d8dd667..ed330abcc1 100644 --- a/modules/luci-base/ucode/runtime.uc +++ b/modules/luci-base/ucode/runtime.uc @@ -43,13 +43,17 @@ function format_lua_exception(ex) { } const Class = { - init_lua: function() { + init_lua: function(optional) { if (!this.L) { - this.L = this.env.dispatcher.load_luabridge().create(); - this.L.set('L', proto({ write: print }, this.env)); - this.L.invoke('require', 'luci.ucodebridge'); + let bridge = this.env.dispatcher.load_luabridge(optional); - this.env.lua_active = true; + if (bridge) { + this.L = bridge.create(); + this.L.set('L', proto({ write: print }, this.env)); + this.L.invoke('require', 'luci.ucodebridge'); + + this.env.lua_active = true; + } } return this.L; @@ -80,10 +84,12 @@ const Class = { } else { try { - let vm = this.init_lua(); - let compile = vm.get('_G', 'luci', 'ucodebridge', 'compile'); + let vm = this.init_lua(true); - compile.call(path); + if (vm) + vm.get('_G', 'luci', 'ucodebridge', 'compile').call(path); + else + return `Unable to compile '${path}' as Lua template: Unable to load Lua runtime`; } catch (lua_err) { return `Unable to compile '${path}' as Lua template: ${format_lua_exception(lua_err)}`; |