mirror of
https://github.com/ccxvii/mujs.git
synced 2026-09-21 06:33:35 +08:00
Add load() function to main.c
This commit is contained in:
@@ -4,6 +4,21 @@
|
||||
|
||||
#define PS1 "> "
|
||||
|
||||
static int jsB_gc(js_State *J, int argc)
|
||||
{
|
||||
int report = js_toboolean(J, 1);
|
||||
js_gc(J, report);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jsB_load(js_State *J, int argc)
|
||||
{
|
||||
const char *filename = js_tostring(J, 1);
|
||||
int rv = js_dofile(J, filename);
|
||||
js_pushboolean(J, !rv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int jsB_print(js_State *J, int argc)
|
||||
{
|
||||
int i;
|
||||
@@ -16,13 +31,6 @@ static int jsB_print(js_State *J, int argc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jsB_gc(js_State *J, int argc)
|
||||
{
|
||||
int report = js_toboolean(J, 1);
|
||||
js_gc(J, report);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@@ -35,6 +43,9 @@ main(int argc, char **argv)
|
||||
js_newcfunction(J, jsB_gc, 0);
|
||||
js_setglobal(J, "gc");
|
||||
|
||||
js_newcfunction(J, jsB_load, 1);
|
||||
js_setglobal(J, "load");
|
||||
|
||||
js_newcfunction(J, jsB_print, 1);
|
||||
js_setglobal(J, "print");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user