[mw-devel] MW3 r916 - branches/jscript/src
arthur at sucs.org
arthur at sucs.org
Thu Mar 15 21:28:56 GMT 2007
Author: arthur
Date: 2007-03-15 21:28:56 +0000 (Thu, 15 Mar 2007)
New Revision: 916
Modified:
branches/jscript/src/js.c
Log:
add a few feature bindings to js, refs #13
Modified: branches/jscript/src/js.c
===================================================================
--- branches/jscript/src/js.c 2007-03-14 21:55:30 UTC (rev 915)
+++ branches/jscript/src/js.c 2007-03-15 21:28:56 UTC (rev 916)
@@ -12,7 +12,15 @@
#include "bb.h"
#include "proto.h"
#include "sqlite.h"
+#include "chattable.h"
+#include "script.h"
+extern struct person *user;
+extern long userposn;
+extern unsigned long rights;
+extern int busy;
+extern int current_rights;
+
/* The master runtime, context, and root object */
static JSRuntime *jsrt = NULL;
static JSContext *jscx = NULL;
@@ -103,7 +111,7 @@
size_t len;
uintN i;
- jschar * ucmsg;
+// jschar * ucmsg;
char * msg;
if (argc < 1) {
return JS_TRUE;
@@ -132,6 +140,48 @@
return JS_TRUE;
}
+/* execute a talker command */
+static JSBool
+js_mwexec(JSContext *cx, JSObject __attribute__((unused)) *obj, uintN argc, jsval *argv, jsval __attribute__((unused)) *rval) {
+ JSString *jsmsg;
+ char * msg;
+ if (argc < 1) {
+ return JS_FALSE;
+ }
+
+ if (JSVAL_IS_STRING(argv[0])) {
+ jsmsg = JS_ValueToString(cx,argv[0]);
+ msg = JS_GetStringBytes(jsmsg);
+ DoCommand(msg, chattable);
+ return JS_TRUE;
+ }
+ return JS_FALSE;
+}
+
+/* say to the talker */
+static JSBool
+js_say(JSContext *cx, JSObject __attribute__((unused)) *obj, uintN argc, jsval *argv, jsval __attribute__((unused)) *rval) {
+ JSString *jsmsg;
+ char * msg;
+ if (argc < 1) {
+ return JS_FALSE;
+ }
+
+ flood++;
+ if (flood > flood_limit) {
+ printf("FLOOD: This script has flooded the room.\n");
+ return JS_FALSE;
+ }
+
+ if (JSVAL_IS_STRING(argv[0])) {
+ jsmsg = JS_ValueToString(cx,argv[0]);
+ msg = JS_GetStringBytes(jsmsg);
+ chat_say(msg);
+ return JS_TRUE;
+ }
+ return JS_FALSE;
+}
+
// Create a javascript array of strings from a struct db_data
JSObject *
dbdata_to_jsarray(JSContext *cx, struct db_data *data, int ncols) {
@@ -456,7 +506,11 @@
ok = JS_DefineFunction(jscx, jsroot, "print", js_print, 1, 0);
ok = JS_DefineFunction(jscx, jsroot, "dbquery", js_doquery, 2, 1);
+ ok = JS_DefineFunction(jscx, jsroot, "exec", js_mwexec, 1, 0);
+ ok = JS_DefineFunction(jscx, jsroot, "say", js_say, 1, 0);
+ ok = JS_DefineProperty(jscx, jsroot, "whoami", STRING_TO_JSVAL(user->name), NULL, NULL, JSPROP_READONLY|JSPROP_PERMANENT);
+
/* need additional functions :
* - one to bind functions to events (bind?)
* - one to load another script (include?)
More information about the mw-devel
mailing list