mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Clean up luaj scripting engine; allow multiple lua library files
This commit is contained in:
@@ -15,12 +15,12 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
package gplx.xowa.addons.apps.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.langs.htmls.scripts.*;
|
||||
import gplx.core.scripts.*;
|
||||
public class Xoscript_env {
|
||||
private final Gfh_script_engine engine;
|
||||
public Xoscript_env(Gfh_script_engine engine, Io_url root_dir) {
|
||||
private final Gfo_script_engine engine;
|
||||
public Xoscript_env(Gfo_script_engine engine, Io_url root_dir) {
|
||||
this.root_dir = root_dir;
|
||||
this.engine = engine;
|
||||
}
|
||||
@@ -15,13 +15,12 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import gplx.langs.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
|
||||
import gplx.core.scripts.*;
|
||||
import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.xowa.addons.htmls.scripts.apis.*; import gplx.xowa.addons.htmls.scripts.xtns.*;
|
||||
import gplx.xowa.addons.apps.scripts.apis.*; import gplx.xowa.addons.apps.scripts.xtns.*;
|
||||
public class Xoscript_mgr {
|
||||
private Io_url root_dir;
|
||||
// private Io_url[] script_urls; private int script_urls_len;
|
||||
private Xoscript_xtn_mgr xtn_mgr;
|
||||
public void Init(Xow_wiki wiki) {
|
||||
// check script_dir
|
||||
@@ -31,30 +30,11 @@ public class Xoscript_mgr {
|
||||
}
|
||||
public void Write(Bry_bfr rv, Xow_wiki wiki, Xoa_page page) {
|
||||
// init
|
||||
if (!wiki.App().Api_root().Addon().App__scripting__enabled()) return;
|
||||
this.Init(wiki);
|
||||
if (xtn_mgr == null) return;
|
||||
|
||||
xtn_mgr.Load_root();
|
||||
xtn_mgr.Run(rv, wiki, page);
|
||||
|
||||
// // create engine and load scripts
|
||||
// Gfh_script_engine engine = new Gfh_script_engine__luaj();
|
||||
// engine.Put_object("xolog", new Xoscript_log());
|
||||
// for (int i = 0; i < script_urls_len; ++i) {
|
||||
// engine.Load_script(script_urls[i]);
|
||||
// }
|
||||
//
|
||||
// // call script
|
||||
// Xoscript_env env = new Xoscript_env(engine, root_dir);
|
||||
// engine.Invoke_function("xoscript__init", env);
|
||||
//
|
||||
// Xoscript_page spg = new Xoscript_page(rv, env, new Xoscript_url(page.Wiki().Domain_str(), String_.new_u8(page.Url().Page_bry())));
|
||||
// engine.Invoke_function("xoscript__page_write_end", spg);
|
||||
//
|
||||
// // overwrite html
|
||||
// if (spg.doc().dirty()) {
|
||||
// rv.Clear();
|
||||
// rv.Add_str_u8(spg.doc().html());
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_doc {
|
||||
private final Bry_bfr bfr;
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
@@ -25,8 +25,8 @@ public class Xoscript_doc {
|
||||
this.head_var = new Xoscript_doc_head(this);
|
||||
this.tail_var = new Xoscript_doc_tail(this);
|
||||
|
||||
head_var.reg_marker("<!--XOWA.SCRIPT.HEAD.TOP-->", "top", Xoscript_doc_sect_base.Pos__default);
|
||||
head_var.reg_marker("<!--XOWA.SCRIPT.HEAD.BOT-->", "bot");
|
||||
head_var.reg_marker("<!--XOWA.SCRIPT.HEAD.TOP-->", "top");
|
||||
head_var.reg_marker("<!--XOWA.SCRIPT.HEAD.BOT-->", "bot", Xoscript_doc_sect_base.Pos__default);
|
||||
tail_var.reg_marker("<!--XOWA.SCRIPT.TAIL.TOP-->", "top", Xoscript_doc_sect_base.Pos__default);
|
||||
}
|
||||
public Xoscript_page page() {return page_var;} private final Xoscript_page page_var;
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_doc_head extends Xoscript_doc_sect_base {
|
||||
public Xoscript_doc_head(Xoscript_doc doc) {super(doc);}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xoscript_doc_head__tst {
|
||||
private final Xoscript_doc_head__fxt fxt = new Xoscript_doc_head__fxt();
|
||||
@@ -52,7 +52,7 @@ class Xoscript_doc_head__fxt {
|
||||
private Xoscript_doc_sect_base sect;
|
||||
public Xoscript_doc_head__fxt() {
|
||||
Bry_bfr rv = Bry_bfr_.New();
|
||||
Xoscript_env env = new Xoscript_env(new gplx.langs.htmls.scripts.Gfh_script_engine__noop(), Io_url_.new_any_("mem/wiki/test_wiki/bin/script/"));
|
||||
Xoscript_env env = new Xoscript_env(new gplx.core.scripts.Gfo_script_engine__noop(), Io_url_.new_any_("mem/wiki/test_wiki/bin/script/"));
|
||||
Xoscript_url url = new Xoscript_url("test_wiki", "test_page");
|
||||
spg = new Xoscript_page(rv, env, url);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ class Xoscript_doc_head__fxt {
|
||||
public void Exec__add_js_file(String pos, String file) {sect.add_js_file(pos, file);}
|
||||
public void Exec__add_html(String html) {sect.add_html(html);}
|
||||
public void Exec__add_html(String pos, String html) {sect.add_html(pos, html);}
|
||||
public void Exec__add_tag(String pos, String tag, String body, String... head_atrs) {sect.add_tag(pos, tag, body, head_atrs);}
|
||||
public void Exec__add_tag(String pos, String tag, String body, Object... head_atrs) {sect.add_tag(pos, tag, body, head_atrs);}
|
||||
public void Test__html(String... expd) {
|
||||
Gftest.Eq__ary__lines(String_.Concat_lines_nl_skip_last(expd), spg.doc().html(), "html");
|
||||
}
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public abstract class Xoscript_doc_sect_base {
|
||||
protected final Xoscript_doc doc;
|
||||
private final Hash_adp_bry marker_hash = Hash_adp_bry.cs();
|
||||
@@ -79,5 +79,5 @@ public abstract class Xoscript_doc_sect_base {
|
||||
public void add_css_code(String pos_str, String code_str) {
|
||||
add_tag(pos_str, "style", code_str, "type", "text/css");
|
||||
}
|
||||
public static final String Pos__default = "default", Body__empty = "";
|
||||
public static final String Pos__default = "", Body__empty = "";
|
||||
}
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_doc_tail extends Xoscript_doc_sect_base {
|
||||
public Xoscript_doc_tail(Xoscript_doc doc) {super(doc);}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_log {
|
||||
public void log(String... v) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", String_.Concat_with_str(" ", v));
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_page {
|
||||
public Xoscript_page(Bry_bfr rv, Xoscript_env env_var, Xoscript_url url_var) {
|
||||
this.env_var = env_var;
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
public class Xoscript_url {
|
||||
public Xoscript_url(String wiki_name_var, String page_name_var) {this.wiki_name_var = wiki_name_var; this.page_name_var = page_name_var;}
|
||||
public String wiki_name() {return wiki_name_var;} private final String wiki_name_var;
|
||||
@@ -15,15 +15,15 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
import gplx.langs.htmls.scripts.*;
|
||||
package gplx.xowa.addons.apps.scripts.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
import gplx.core.scripts.*;
|
||||
public class Xoscript_xtn_itm {
|
||||
public Xoscript_xtn_itm(String key, Io_url url, Gfh_script_engine engine) {
|
||||
public Xoscript_xtn_itm(String key, Io_url url, Gfo_script_engine engine) {
|
||||
this.key = key;
|
||||
this.url = url;
|
||||
this.engine = engine;
|
||||
}
|
||||
public String Key() {return key;} private final String key;
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public Gfh_script_engine Engine() {return engine;} private final Gfh_script_engine engine;
|
||||
public Gfo_script_engine Engine() {return engine;} private final Gfo_script_engine engine;
|
||||
}
|
||||
@@ -15,9 +15,9 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.htmls.scripts.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*; import gplx.xowa.addons.htmls.scripts.*;
|
||||
import gplx.langs.htmls.scripts.*;
|
||||
import gplx.xowa.addons.htmls.scripts.apis.*;
|
||||
package gplx.xowa.addons.apps.scripts.xtns; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*; import gplx.xowa.addons.apps.scripts.*;
|
||||
import gplx.core.scripts.*;
|
||||
import gplx.xowa.addons.apps.scripts.apis.*;
|
||||
public class Xoscript_xtn_mgr {
|
||||
private Xoscript_xtn_itm root_itm;
|
||||
private final Io_url root_dir;
|
||||
@@ -27,7 +27,7 @@ public class Xoscript_xtn_mgr {
|
||||
}
|
||||
public void reg_xtn(String key, String file) {
|
||||
Io_url url = Io_url_.new_fil_(Xoscript_env.Resolve_file(Bool_.N, root_dir, file));
|
||||
Xoscript_xtn_itm itm = new Xoscript_xtn_itm(key, url, Gfh_script_engine_.New_by_ext(url.Ext()));
|
||||
Xoscript_xtn_itm itm = new Xoscript_xtn_itm(key, url, Gfo_script_engine_.New_by_ext(url.Ext()));
|
||||
hash.Add(key, itm);
|
||||
}
|
||||
public void Load_root() {
|
||||
@@ -37,7 +37,7 @@ public class Xoscript_xtn_mgr {
|
||||
Io_url root_url = root_urls[0];
|
||||
String root_name_and_ext = root_url.NameAndExt();
|
||||
if (String_.EqAny(root_name_and_ext, "xowa.script.main.js", "xowa.script.main.lua")) {
|
||||
this.root_itm = new Xoscript_xtn_itm("xowa.root", root_url, Gfh_script_engine_.New_by_ext(root_url.Ext()));
|
||||
this.root_itm = new Xoscript_xtn_itm("xowa.root", root_url, Gfo_script_engine_.New_by_ext(root_url.Ext()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -49,13 +49,15 @@ public class Xoscript_xtn_mgr {
|
||||
Xoscript_log log = new Xoscript_log();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoscript_xtn_itm itm = (Xoscript_xtn_itm)hash.Get_at(i);
|
||||
Gfh_script_engine engine = (Gfh_script_engine)itm.Engine();
|
||||
Gfo_script_engine engine = (Gfo_script_engine)itm.Engine();
|
||||
Xoscript_env env = new Xoscript_env(engine, itm.Url().OwnerDir());
|
||||
Xoscript_page spg = new Xoscript_page(rv, env, new Xoscript_url(page.Wiki().Domain_str(), String_.new_u8(page.Url().Page_bry())));
|
||||
engine.Put_object("xolog", log);
|
||||
engine.Load_script(itm.Url());
|
||||
engine.Invoke_function("xoscript__init", env);
|
||||
engine.Invoke_function("xoscript__page_write_end", spg);
|
||||
try {engine.Invoke_function("xoscript__init", env);}
|
||||
catch (Exception e) {Gfo_usr_dlg_.Instance.Note_many("", "", "xoscript__init failed; url=~{0} err=~{1}", itm.Url(), Err_.Message_lang(e));}
|
||||
try {engine.Invoke_function("xoscript__page_write_end", spg);}
|
||||
catch (Exception e) {Gfo_usr_dlg_.Instance.Note_many("", "", "xoscript__page_write_end failed; url=~{0} err=~{1}", itm.Url(), Err_.Message_lang(e));}
|
||||
|
||||
// overwrite html
|
||||
if (spg.doc().dirty()) {
|
||||
Reference in New Issue
Block a user