mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-05 17:29:43 +08:00
mujs shell: Add compile function.
The new compile function compiles a source code string as a script and returns a callable object. The optional 'filename' argument is used to format error messages and stack traces.
This commit is contained in:
committed by
Tor Andersson
parent
84858c335e
commit
924649a69e
10
main.c
10
main.c
@@ -103,6 +103,13 @@ static void jsB_load(js_State *J)
|
||||
js_pushundefined(J);
|
||||
}
|
||||
|
||||
static void jsB_compile(js_State *J)
|
||||
{
|
||||
const char *source = js_tostring(J, 1);
|
||||
const char *filename = js_isdefined(J, 2) ? js_tostring(J, 2) : "[string]";
|
||||
js_loadstring(J, filename, source);
|
||||
}
|
||||
|
||||
static void jsB_print(js_State *J)
|
||||
{
|
||||
int i, top = js_gettop(J);
|
||||
@@ -293,6 +300,9 @@ main(int argc, char **argv)
|
||||
js_newcfunction(J, jsB_load, "load", 1);
|
||||
js_setglobal(J, "load");
|
||||
|
||||
js_newcfunction(J, jsB_compile, "compile", 2);
|
||||
js_setglobal(J, "compile");
|
||||
|
||||
js_newcfunction(J, jsB_print, "print", 0);
|
||||
js_setglobal(J, "print");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user