From 45adc036a2decd4eb7e5c0b644b550c57954efb5 Mon Sep 17 00:00:00 2001 From: gnosygnu Date: Wed, 15 Jul 2020 08:06:21 -0400 Subject: [PATCH] Luaj: Check for error in LoadString [#759] --- .../xtns/scribunto/Scrib_invoke_func.java | 8 ++- .../scribunto/engines/luaj/Luaj_engine.java | 62 +++++++++++++------ 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func.java b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func.java index addc80578..86fffa62a 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_invoke_func.java @@ -65,9 +65,11 @@ public class Scrib_invoke_func extends Pf_func_base { if (!core.Enabled()) {bfr.Add_mid(src, self.Src_bgn(), self.Src_end()); return;} try { - if (String_.Eq(String_.new_u8(mod_name), "Authority control")) { - Tfds.Write(String_.new_u8(ctx.Page().Ttl().Page_db()), String_.new_u8(mod_name), String_.new_u8(fnc_name)); - } + // DBG: test code; ISSUE#:737 + // if (String_.Eq(String_.new_u8(mod_name), "Authority control")) { + // Tfds.Write(String_.new_u8(ctx.Page().Ttl().Page_db()), String_.new_u8(mod_name), String_.new_u8(fnc_name)); + // } + // check if configured for threaded execution boolean exec = true; ScribCfgResolver resolver = wiki.Parser_mgr().Scrib().CfgResolver(); diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/engines/luaj/Luaj_engine.java b/400_xowa/src/gplx/xowa/xtns/scribunto/engines/luaj/Luaj_engine.java index 1c2f4a9e1..ec8c8838e 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/engines/luaj/Luaj_engine.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/engines/luaj/Luaj_engine.java @@ -1,22 +1,38 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012-2017 gnosygnu@gmail.com - -XOWA is licensed under the terms of the General Public License (GPL) Version 3, -or alternatively under the terms of the Apache License Version 2.0. - -You may use XOWA according to either of these licenses as is most appropriate -for your project on a case-by-case basis. - -The terms of each license can be found in the source code repository: - -GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt -Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt -*/ -package gplx.xowa.xtns.scribunto.engines.luaj; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.engines.*; -import gplx.xowa.xtns.scribunto.procs.*; -import org.luaj.vm2.*; import org.luaj.vm2.lib.*; import org.luaj.vm2.lib.jse.*; -import gplx.xowa.xtns.scribunto.engines.process.*; +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.xtns.scribunto.engines.luaj; + +import gplx.Keyval; +import gplx.Keyval_; +import gplx.String_; +import gplx.xowa.Xoae_app; +import gplx.xowa.xtns.scribunto.Scrib_core; +import gplx.xowa.xtns.scribunto.Scrib_kv_utl_; +import gplx.xowa.xtns.scribunto.Scrib_lua_proc; +import gplx.xowa.xtns.scribunto.Scrib_xtn_mgr; +import gplx.xowa.xtns.scribunto.engines.Scrib_engine; +import gplx.xowa.xtns.scribunto.engines.Scrib_server; +import gplx.xowa.xtns.scribunto.procs.Scrib_proc; +import gplx.xowa.xtns.scribunto.procs.Scrib_proc_args; +import gplx.xowa.xtns.scribunto.procs.Scrib_proc_mgr; +import gplx.xowa.xtns.scribunto.procs.Scrib_proc_rslt; +import org.luaj.vm2.LuaInteger; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; + public class Luaj_engine implements Scrib_engine { private final Luaj_server_func_recv func_recv; private final Luaj_server_func_dbg func_dbg; @@ -38,6 +54,14 @@ public class Luaj_engine implements Scrib_engine { msg.set("text", LuaValue.valueOf(text)); msg.set("chunkName", LuaValue.valueOf(name)); LuaTable rsp = server.Dispatch(msg); + + // check for error such as mistyping `dbg('a)`; ISSUE#:759 DATE:2020-07-15 + String op = Luaj_value_.Get_val_as_str(rsp, "op"); + if (String_.Eq(op, "error")) { + String err = Luaj_value_.Get_val_as_str(rsp, "value"); + throw Scrib_xtn_mgr.err_(err); + } + LuaTable values_tbl = Luaj_value_.Get_val_as_lua_table(rsp, "values"); LuaInteger proc_id = (LuaInteger)values_tbl.rawget(1); return new Scrib_lua_proc(name, proc_id.v);