Add load() function to main.c

This commit is contained in:
Tor Andersson
2014-02-04 15:30:16 +01:00
parent e645f5989c
commit 241905d43c
+18 -7
View File
@@ -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");