1
0
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:
gnosygnu
2016-10-16 13:00:37 -04:00
parent c1d84249e1
commit d07b3e1493
21 changed files with 156 additions and 179 deletions

View File

@@ -0,0 +1,50 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.apps.scripts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.apps.*;
import gplx.core.envs.*;
import gplx.core.scripts.*;
public class Xoscript_env {
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;
}
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir;
public void load_script(String file) {
engine.Load_script(Io_url_.new_fil_(Xoscript_env.Resolve_file(Bool_.N, root_dir, file)));
}
public static String Resolve_file(boolean use_file_protocol, Io_url root_dir, String file) {
String rv = file;
// resolve relative urls; EX: "./a.js" -> "/xowa/wiki/simple.wikipedia.org/bin/script/a.js"
if (String_.Has_at_bgn(rv, "./")) {
// remove "./"
rv = String_.Mid(rv, 2);
if (use_file_protocol)
rv = root_dir.To_http_file_str() + rv;
else {
// if fsys_url && wnt, replace "\" with "/"
if (Op_sys.Cur().Tid_is_wnt())
rv = String_.Replace(rv, Op_sys.Lnx.Fsys_dir_spr_str(), Op_sys.Wnt.Fsys_dir_spr_str());
rv = root_dir.Xto_api() + Op_sys.Cur().Fsys_dir_spr_str() + rv;
}
}
return rv;
}
}

View File

@@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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.apps.scripts.apis.*; import gplx.xowa.addons.apps.scripts.xtns.*;
public class Xoscript_mgr {
private Io_url root_dir;
private Xoscript_xtn_mgr xtn_mgr;
public void Init(Xow_wiki wiki) {
// check script_dir
this.root_dir = wiki.Fsys_mgr().Root_dir().GenSubDir_nest("bin", "any", "script");
if (!Io_mgr.Instance.ExistsDir(root_dir)) return;
this.xtn_mgr = new Xoscript_xtn_mgr(root_dir);
}
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);
}
}

View File

@@ -0,0 +1,61 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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();
public Xoscript_doc(Bry_bfr bfr, Xoscript_page page_var) {
this.bfr = bfr;
this.page_var = page_var;
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");
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;
public Xoscript_doc_head head() {return head_var;} private final Xoscript_doc_head head_var;
public Xoscript_doc_tail tail() {return tail_var;} private final Xoscript_doc_tail tail_var;
public String html() {
if (html_var == null) {
html_var = bfr.To_str();
}
return html_var;
} private String html_var;
public void html(String s) {
html_var = s;
html_dirty = true;
}
public void html_by_marker(byte[] marker, byte[] marker_html) {
byte[] html_bry = Bry_.new_u8(this.html());
// find marker, and splice it in
int marker_pos = Bry_find_.Find_fwd(html_bry, marker);
if (marker_pos != Bry_find_.Not_found) {
tmp_bfr.Add_mid(html_bry, 0, marker_pos);
tmp_bfr.Add(marker_html);
tmp_bfr.Add_mid(html_bry, marker_pos, html_bry.length);
html_bry = tmp_bfr.To_bry_and_clear();
}
this.html(String_.new_u8(html_bry));
}
public boolean dirty() {
return html_dirty;
} private boolean html_dirty;
}

View File

@@ -0,0 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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);}
}

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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();
@Before public void init() {
fxt.Init__sect("head");
fxt.Exec__reg_marker("<!--top-->", "top", Xoscript_doc_head.Pos__default);
fxt.Exec__reg_marker("<!--bot-->", "bot");
fxt.Exec__doc__html("a<!--top-->b<!--bot-->c");
}
@Test public void Add_html() {
fxt.Exec__add_html("top", "<b>add_1</b>");
fxt.Exec__add_html("top", "<b>add_2</b>");
fxt.Test__html("a<b>add_1</b><b>add_2</b><!--top-->b<!--bot-->c");
}
@Test public void Add_html__default() {
fxt.Exec__add_html("<b>add_1</b>");
fxt.Test__html("a<b>add_1</b><!--top-->b<!--bot-->c");
}
@Test public void Add_tag() {
fxt.Exec__add_tag("top", "div", "div_body", "k0", "v0", "k1", "v1");
fxt.Test__html
( "a<div k0=\"v0\" k1=\"v1\">div_body</div>"
, "<!--top-->b<!--bot-->c");
}
@Test public void Add_js_file() {
fxt.Exec__add_js_file("top", "./a.js");
fxt.Test__html
( "a<script src=\"file:///mem/wiki/test_wiki/bin/script/a.js\" type=\"text/javascript\"></script>"
, "<!--top-->b<!--bot-->c");
}
}
class Xoscript_doc_head__fxt {
private final Xoscript_page spg;
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.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);
}
public void Init__sect(String sect_name) {
if (String_.Eq(sect_name, "head"))
sect = spg.doc().head();
else if (String_.Eq(sect_name, "tail"))
sect = spg.doc().tail();
}
public void Exec__doc__html(String html) {spg.doc().html(html);}
public void Exec__reg_marker(String marker, String... pos_ary) {sect.reg_marker(marker, pos_ary);}
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, 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");
}
}

View File

@@ -0,0 +1,83 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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();
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
public Xoscript_doc_sect_base(Xoscript_doc doc) {this.doc = doc;}
private byte[] get_marker_by_pos(byte[] pos_bry) {
return (byte[])marker_hash.Get_by_or_fail(pos_bry);
}
public void reg_marker(String marker_str, String... pos_ary) {
int len = pos_ary.length;
byte[] marker_bry = Bry_.new_u8(marker_str);
for (int i = 0; i < len; ++i) {
marker_hash.Add_if_dupe_use_nth(Bry_.new_u8(pos_ary[i]), marker_bry);
}
}
public void add_html(String html) {add_html(Pos__default, html);}
public void add_html(String pos_str, String html) {add_html(Pos__default, Bry_.new_u8(html));}
public void add_html(String pos_str, byte[] html) {
doc.html_by_marker(get_marker_by_pos(Bry_.new_u8(pos_str)), html);
}
// public void add_tag_by_objs(String pos_str, String tag_str, String body, params String[] head_atrs) {
public void add_tag(String pos_str, String tag_str, String body, Object... head_atrs) {
// build tag.bgn; EX: '<tag k1="v1">'
tmp_bfr.Add_byte(Byte_ascii.Angle_bgn);
tmp_bfr.Add_str_u8(tag_str);
int head_atrs_len = head_atrs.length;
for (int i = 0; i < head_atrs_len; i += 2) {
tmp_bfr.Add_byte_space();
tmp_bfr.Add_obj_strict(head_atrs[i]);
tmp_bfr.Add_byte_eq();
tmp_bfr.Add_byte_quote();
tmp_bfr.Add_obj_strict(head_atrs[i + 1]);
tmp_bfr.Add_byte_quote();
}
tmp_bfr.Add_byte(Byte_ascii.Angle_end);
// build tag.body; EX: 'some body'
tmp_bfr.Add_str_u8(body);
// build tag.end; EX: '</tag>\n'
tmp_bfr.Add_byte(Byte_ascii.Angle_bgn).Add_byte(Byte_ascii.Slash);
tmp_bfr.Add_str_u8(tag_str);
tmp_bfr.Add_byte(Byte_ascii.Angle_end);
tmp_bfr.Add_byte_nl();
add_html(pos_str, tmp_bfr.To_bry_and_clear());
}
public void add_js_file(String file_str) {add_js_file(Pos__default, file_str);}
public void add_js_file(String pos_str, String file_str) {
add_tag(pos_str, "script", Body__empty, "src", Xoscript_env.Resolve_file(Bool_.Y, doc.page().env().Root_dir(), file_str), "type", "text/javascript");
}
public void add_js_code(String code_str) {add_js_file(Pos__default, code_str);}
public void add_js_code(String pos_str, String code_str) {
add_tag(pos_str, "script", code_str, "type", "text/javascript");
}
public void add_css_file(String file_str) {add_js_file(Pos__default, file_str);}
public void add_css_file(String pos_str, String file_str) {
add_tag(pos_str, "link", Body__empty, "rel", "stylesheet", "href", Xoscript_env.Resolve_file(Bool_.Y, doc.page().env().Root_dir(), file_str), "type", "text/css");
}
public void add_css_code(String code_str) {add_css_code(Pos__default, code_str);}
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 = "", Body__empty = "";
}

View File

@@ -0,0 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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);}
}

View File

@@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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));
}
}

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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;
this.url_var = url_var;
this.doc_var = new Xoscript_doc(rv, this);
}
public Xoscript_env env() {return env_var;} private final Xoscript_env env_var;
public Xoscript_url url() {return url_var;} private final Xoscript_url url_var;
public Xoscript_doc doc() {return doc_var;} private final Xoscript_doc doc_var;
}

View File

@@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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;
public String page_name() {return page_name_var;} private final String page_name_var;
}

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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, 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 Gfo_script_engine Engine() {return engine;} private final Gfo_script_engine engine;
}

View File

@@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.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;
private final Ordered_hash hash = Ordered_hash_.New();
public Xoscript_xtn_mgr(Io_url root_dir) {
this.root_dir = root_dir;
}
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, Gfo_script_engine_.New_by_ext(url.Ext()));
hash.Add(key, itm);
}
public void Load_root() {
Io_url[] root_urls = Io_mgr.Instance.QueryDir_args(root_dir).ExecAsUrlAry();
int root_urls_len = root_urls.length;
for (int i = 0; i < root_urls_len; ++i) {
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, Gfo_script_engine_.New_by_ext(root_url.Ext()));
break;
}
}
root_itm.Engine().Load_script(root_itm.Url());
root_itm.Engine().Invoke_function("xoscript__main", this);
}
public void Run(Bry_bfr rv, Xow_wiki wiki, Xoa_page page) {
int len = hash.Len();
Xoscript_log log = new Xoscript_log();
for (int i = 0; i < len; ++i) {
Xoscript_xtn_itm itm = (Xoscript_xtn_itm)hash.Get_at(i);
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());
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()) {
rv.Clear();
rv.Add_str_u8(spg.doc().html());
}
}
}
}