diff options
Diffstat (limited to 'swat/scripting')
-rw-r--r-- | swat/scripting/client/call.js | 47 | ||||
-rw-r--r-- | swat/scripting/general_calls.esp | 26 |
2 files changed, 64 insertions, 9 deletions
diff --git a/swat/scripting/client/call.js b/swat/scripting/client/call.js index d1671ef70f..3af6a5a876 100644 --- a/swat/scripting/client/call.js +++ b/swat/scripting/client/call.js @@ -40,7 +40,7 @@ function __http_object() { /* usage: - server_call(url, func, callback, ...); + vserver_call(url, func, callback, args); 'func' is a function name to call on the server any additional arguments are passed to func() on the server @@ -48,17 +48,17 @@ function __http_object() { The callback() function is called with the returned object. 'callback' may be null. */ -function server_call(url, func, callback) { +function vserver_call(url, func, callback, args) { + var args2 = new Object(); + args2.length = args.length; + var i; + for (i=0;i<args.length;i++) { + args2[i] = args[i]; + } var req = __http_object(); req.open("POST", url, true); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - var args = new Object(); - var i; - for (i=3;i<arguments.length;i++) { - args[i-3] = arguments[i]; - } - args.length = i-3; - req.send("func=" + func + "&args=" + encodeObject(args)); + req.send("func=" + func + "&args=" + encodeObject(args2)); req.onreadystatechange = function() { if (4 == req.readyState && callback != null) { var o = decodeObject(req.responseText); @@ -67,3 +67,32 @@ function server_call(url, func, callback) { } } + +/* + usage: + + server_call(url, func, callback, ...); + + 'func' is a function name to call on the server + any additional arguments are passed to func() on the server + + The callback() function is called with the returned + object. 'callback' may be null. +*/ +function server_call(url, func, callback) { + var args = new Object(); + var i; + for (i=3;i<arguments.length;i++) { + args[i-3] = arguments[i]; + } + args.length = i-3; + vserver_call(url, func, callback, args); +} + + +/* + call printf on the server +*/ +function srv_printf() { + vserver_call('/scripting/general_calls.esp', 'srv_printf', null, arguments); +} diff --git a/swat/scripting/general_calls.esp b/swat/scripting/general_calls.esp new file mode 100644 index 0000000000..3a78ff6bbb --- /dev/null +++ b/swat/scripting/general_calls.esp @@ -0,0 +1,26 @@ +<% +/* + used for general purpose calls +*/ +libinclude("server_call.js"); + +/* register a call for clients to make */ +var call = servCallObj(); + +/* + a remote printf, for displaying stuff on smbd stdout +*/ +function srv_printf() +{ + println("in srv_printf"); + var s = string_init(); + print(s.vsprintf(arguments)); + return undefined; +} + +/* add some basic calls */ +call.add('srv_printf', srv_printf); + +/* run the function that was asked for */ +call.run(); +%> |