Created
January 22, 2013 01:53
-
-
Save jquave/4591372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This defines the functions i want to add to the javascript engine, | |
// like "alert" is commonly used in web-based js to show a popup window with text. | |
// So I create a js function called alert and add it to the engine's gobal object (window in browsers) | |
// Then I tell it to call the C function jsc_alert() when the developer uses the alert() command in a javascript file. | |
int JSConnectDefineGlobalFunctions(JSContext *context, JSObject *global) { | |
static JSFunctionSpec global_funcs[] = { | |
JS_FS("csystem", myjs_system, 1, 0, 0), | |
JS_FS("alert", jsc_alert, 1, 0, 0), | |
JS_FS("CreateView", jsc_createview, 1, 0, 0), | |
JS_FS("include", jsc_include, 1, 0, 0), | |
JS_FS("log", jsc_log, 1, 0, 0), | |
JS_FS_END | |
}; | |
if (!JS_DefineFunctions(context, global, global_funcs)) | |
return JS_FALSE; | |
return JS_TRUE; | |
} | |
// This presents a UIAlertView. note: that's this window in iPhone dev: http://i.imgur.com/fynRleK.png | |
// It does it using native Objective-C to call the native function for iOS | |
JSBool jsc_alert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { | |
NSString *message = [JSConnectUtil stringFromParam:argv withContext:cx]; | |
UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"Alert" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; | |
[a show]; | |
[a release]; | |
return JS_TRUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment