shithub: libmujs

Download patch

ref: 241905d43c0cf8f81c2b10ea18ebfdc17e9222cb
parent: e645f5989c9fcae6fc621423e0479f72a2c76226
author: Tor Andersson <[email protected]>
date: Tue Feb 4 10:30:16 EST 2014

Add load() function to main.c

--- a/main.c
+++ b/main.c
@@ -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 @@
 	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)
 {
@@ -34,6 +42,9 @@
 
 	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");