Mercurial Hosting > luan
changeset 1692:d6ec67fa4a61
tools for config files
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 14 Jun 2022 21:59:39 -0600 |
parents | 8d4152398825 |
children | 45eaaf5146f3 |
files | src/luan/modules/http/LuanHandler.java src/luan/modules/http/tools/Run.luan |
diffstat | 2 files changed, 31 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/http/LuanHandler.java Mon Jun 13 18:01:51 2022 -0600 +++ b/src/luan/modules/http/LuanHandler.java Tue Jun 14 21:59:39 2022 -0600 @@ -49,12 +49,14 @@ private static final Method evalInRootMethod; private static final Method disableLuanMethod; private static final Method dontGcMethod; + private static final Method testAsInitMethod; static { try { resetLuanMethod = LuanHandler.Fns.class.getMethod( "reset_luan" ); evalInRootMethod = LuanHandler.Fns.class.getMethod( "eval_in_root", String.class ); disableLuanMethod = LuanHandler.Fns.class.getMethod( "disable_luan" ); dontGcMethod = LuanHandler.Fns.class.getMethod( "dont_gc" ); + testAsInitMethod = LuanHandler.Fns.class.getMethod( "test_as_init", String.class, String.class ); } catch(NoSuchMethodException e) { throw new RuntimeException(e); } @@ -71,6 +73,7 @@ Http.put( luanInit, "eval_in_root", new LuanJavaFunction(evalInRootMethod,fns) ); Http.put( luanInit, "disable_luan", new LuanJavaFunction(disableLuanMethod,fns) ); Http.put( luanInit, "dont_gc", new LuanJavaFunction(dontGcMethod,fns) ); + Http.put( luanInit, "test_as_init", new LuanJavaFunction(testAsInitMethod,fns) ); } catch(LuanException e) { throw new RuntimeException(e); } @@ -169,6 +172,19 @@ } } + private void test_as_init(String text,String sourceName) throws LuanException { + Luan luan; + synchronized(luanInit) { + luan = new Luan(luanInit); + } + LuanLogger.startThreadLogging(luan); + try { + luan.load(text,sourceName,false,null).call(luan); + } finally { + LuanLogger.endThreadLogging(); + } + } + public static void start(Server server) throws Exception { try { server.start(); @@ -233,6 +249,10 @@ public void dont_gc() throws LuanException { lh().dont_gc(); } + + public void test_as_init(String text,String sourceName) throws LuanException { + lh().test_as_init(text,sourceName); + } }
--- a/src/luan/modules/http/tools/Run.luan Mon Jun 13 18:01:51 2022 -0600 +++ b/src/luan/modules/http/tools/Run.luan Tue Jun 14 21:59:39 2022 -0600 @@ -68,6 +68,16 @@ <% end +function Run.print_error(e,code) + Http.response.reset() + Http.response.headers["Content-Type"] = "text/plain; charset=utf-8" + Io.stdout = Http.response.text_writer() + print(e) + print() + print() + print_with_line_numbers(code) +end + function Run.run(code,source_name) try Http.response.headers["Content-Type"] = "text/plain; charset=utf-8" @@ -75,13 +85,7 @@ run() return true catch e - Http.response.reset() - Http.response.headers["Content-Type"] = "text/plain; charset=utf-8" - Io.stdout = Http.response.text_writer() - print(e) - print() - print() - print_with_line_numbers(code) + Run.print_error(e,code) return false end end