ref: 4595872bb39a7216df82425b148bd1914520e1de
parent: 3cef8607dca6efac918085f0a1d9aebbbc7da2a8
author: Tor Andersson <tor@ccxvii.net>
date: Fri Jan 24 11:18:55 EST 2014
Move non-standard 'gc' and 'print' global functions into main.c example.
--- a/jsbuiltin.c
+++ b/jsbuiltin.c
@@ -66,25 +66,6 @@
return 1;
}
-static int jsB_print(js_State *J, int argc)
-{
- int i;
- for (i = 1; i <= argc; ++i) {
- const char *s = js_tostring(J, i);
- if (i > 1) putchar(' ');
- fputs(s, stdout);
- }
- putchar('\n');
- return 0;
-}
-
-static int jsB_gc(js_State *J, int argc)
-{
- int report = js_toboolean(J, 1);
- js_gc(J, report);
- return 0;
-}
-
void jsB_init(js_State *J)
{
/* Create the prototype objects here, before the constructors */
@@ -129,10 +110,4 @@
jsB_globalf(J, "parseFloat", jsB_parseFloat, 1);
jsB_globalf(J, "isNaN", jsB_isNaN, 1);
jsB_globalf(J, "isFinite", jsB_isFinite, 1);
-
- /* Non-standard */
- js_newcfunction(J, jsB_gc, 0);
- js_setglobal(J, "gc");
- js_newcfunction(J, jsB_print, 1);
- js_setglobal(J, "print");
}
--- a/main.c
+++ b/main.c
@@ -4,6 +4,25 @@
#define PS1 "> "
+static int jsB_print(js_State *J, int argc)
+{
+ int i;
+ for (i = 1; i <= argc; ++i) {
+ const char *s = js_tostring(J, i);
+ if (i > 1) putchar(' ');
+ fputs(s, stdout);
+ }
+ putchar('\n');
+ 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)
{
@@ -12,6 +31,12 @@
int i;
J = js_newstate();
+
+ js_newcfunction(J, jsB_gc, 0);
+ js_setglobal(J, "gc");
+
+ js_newcfunction(J, jsB_print, 1);
+ js_setglobal(J, "print");
if (argc > 1) {
for (i = 1; i < argc; ++i) {