Luaj: Check for error in LoadString [#759]

staging
gnosygnu 4 years ago
parent 6b2e120fc1
commit 45adc036a2

@ -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;} if (!core.Enabled()) {bfr.Add_mid(src, self.Src_bgn(), self.Src_end()); return;}
try { try {
if (String_.Eq(String_.new_u8(mod_name), "Authority control")) { // DBG: test code; ISSUE#:737
Tfds.Write(String_.new_u8(ctx.Page().Ttl().Page_db()), String_.new_u8(mod_name), String_.new_u8(fnc_name)); // 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 // check if configured for threaded execution
boolean exec = true; boolean exec = true;
ScribCfgResolver resolver = wiki.Parser_mgr().Scrib().CfgResolver(); ScribCfgResolver resolver = wiki.Parser_mgr().Scrib().CfgResolver();

@ -1,22 +1,38 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, 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. 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 You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis. for your project on a case-by-case basis.
The terms of each license can be found in the source code repository: 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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.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.*; package gplx.xowa.xtns.scribunto.engines.luaj;
import gplx.xowa.xtns.scribunto.procs.*;
import org.luaj.vm2.*; import org.luaj.vm2.lib.*; import org.luaj.vm2.lib.jse.*; import gplx.Keyval;
import gplx.xowa.xtns.scribunto.engines.process.*; 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 { public class Luaj_engine implements Scrib_engine {
private final Luaj_server_func_recv func_recv; private final Luaj_server_func_recv func_recv;
private final Luaj_server_func_dbg func_dbg; 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("text", LuaValue.valueOf(text));
msg.set("chunkName", LuaValue.valueOf(name)); msg.set("chunkName", LuaValue.valueOf(name));
LuaTable rsp = server.Dispatch(msg); 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"); LuaTable values_tbl = Luaj_value_.Get_val_as_lua_table(rsp, "values");
LuaInteger proc_id = (LuaInteger)values_tbl.rawget(1); LuaInteger proc_id = (LuaInteger)values_tbl.rawget(1);
return new Scrib_lua_proc(name, proc_id.v); return new Scrib_lua_proc(name, proc_id.v);

Loading…
Cancel
Save