r8638: continue the trend of maknig our C functions true ejs objects by making the...
authorAndrew Tridgell <tridge@samba.org>
Wed, 20 Jul 2005 07:04:07 +0000 (07:04 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:29:48 +0000 (13:29 -0500)
into an object. To keep existing code working I have added:

  string_init(global);

into base.js. That brings the functions into the global scope for our
existing scripts
(This used to be commit a978484738168b82441c4dc4f5f803d349769a4b)

source4/scripting/ejs/smbcalls_string.c
source4/scripting/libjs/base.js
swat/scripting/common.js
testprogs/ejs/sprintf.js

index 657c8efc614560906c6c29223fa7bd60964bc372..3d386abe2eac51d31d843b2cd1165db185672ce6 100644 (file)
@@ -320,16 +320,28 @@ static int ejs_vsprintf(MprVarHandle eid, int argc, struct MprVar **argv)
        return ret;
 }
 
+/*
+  initialise string ejs subsystem
+*/
+static int ejs_string_init(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+       struct MprVar *obj = mprInitObject(eid, "string", argc, argv);
+
+       mprSetStringCFunction(obj, "strlen", ejs_strlen);
+       mprSetStringCFunction(obj, "strlower", ejs_strlower);
+       mprSetStringCFunction(obj, "strupper", ejs_strupper);
+       mprSetStringCFunction(obj, "split", ejs_split);
+       mprSetCFunction(obj, "join", ejs_join);
+       mprSetCFunction(obj, "sprintf", ejs_sprintf);
+       mprSetCFunction(obj, "vsprintf", ejs_vsprintf);
+
+       return 0;
+}
+
 /*
   setup C functions that be called from ejs
 */
 void smb_setup_ejs_string(void)
 {
-       ejsDefineStringCFunction(-1, "strlen", ejs_strlen, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineStringCFunction(-1, "strlower", ejs_strlower, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineStringCFunction(-1, "strupper", ejs_strupper, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineStringCFunction(-1, "split", ejs_split, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineCFunction(-1, "join", ejs_join, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineCFunction(-1, "sprintf", ejs_sprintf, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineCFunction(-1, "vsprintf", ejs_vsprintf, NULL, MPR_VAR_SCRIPT_HANDLE);
+       ejsDefineCFunction(-1, "string_init", ejs_string_init, NULL, MPR_VAR_SCRIPT_HANDLE);
 }
index 39b62b133e8b21363c67921eff8aee718813c0ec..8a07f4e3831d5ff0ee64ed85991ab39663931c7f 100644 (file)
@@ -9,6 +9,9 @@ if (global["HAVE_BASE_JS"] != undefined) {
 }
 HAVE_BASE_JS=1
 
+/* bring the string functions into the global frame */
+string_init(global);
+
 /*
   an essential function!
 */
index baebe8af82380b514d0ec2d4f7dde1d35f570170..f868040f03d538325f03bed71b40e226682e9bd7 100644 (file)
@@ -8,6 +8,8 @@ global.page = new Object();
 /* fill in some defaults */
 global.page.title = "Samba Web Administration Tool";
 
+libinclude("base.js");
+
 /* to cope with browsers that don't support cookies we append the sessionid
    to the URI */
 global.SESSIONURI = "";
index 4d3d9a7555499d7abfb74eea00b4ccc8279dd74d..6ae8605718767f192b43cd88e7686539b925fe79 100755 (executable)
@@ -3,6 +3,8 @@
        test sprintf function
 */
 
+string_init(local);
+
 function check_result(s, v)
 {
        if (s != v) {