< Day Day Up > |
The C-level extensibility API consists of the JSBool (*JSNative) function signature and the following functions:
typedef JSBool (*JSNative)(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval)Description Method; describes C-level implementations of JavaScript functions in the following situations:
The function returns JS_TRUE if successful; JS_FALSE otherwise. If the function returns JS_FALSE, the current script stops executing and an error message appears. JSBool JS_DefineFunction()Usage JSBool JS_DefineFunction(unsigned short *name, JSNative call, unsigned int nargs) Description Method; registers a C-level function with the JavaScript interpreter in Flash. After the JS_DefineFunction() function registers the C-level function that you specify in the call argument, you can invoke it in a JavaScript script by referring to it with the name that you specify in the name argument. The name argument is case-sensitive. Typically, this function is called from the MM_Init() function, which Flash calls during startup. Arguments unsigned short *name, JSNative call, unsigned int nargs
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. unsigned short *JS_ValueToString()Usage unsigned short *JS_ValueToString(JSContext *cx, jsval v, unsigned int *pLength) Description Method; extracts a function argument from a jsval structure, converts it to a string, if possible, and passes the converted value back to the caller. NOTE Do not modify the returned buffer pointer or you might corrupt the data structures of the JavaScript interpreter. To change the string, you must copy the characters into another buffer and create a new JavaScript string. Arguments JSContext *cx, jsval v, unsigned int *pLength
Returns A pointer that points to a null-terminated string if successful or to a null value on failure. The calling routine must not free this string when it finishes. JSBool JS_ValueToInteger()Usage JSBool JS_ValueToInteger(JSContext *cx, jsval v, long *lp); Description Method; extracts a function argument from a jsval structure, converts it to an integer (if possible), and passes the converted value back to the caller. Arguments JSContext *cx, jsval v, long *lp
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSBool JS_ValueToDouble()Usage JSBool JS_ValueToDouble(JSContext *cx, jsval v, double *dp); Description Method; extracts a function argument from a jsval structure, converts it to a double (if possible), and passes the converted value back to the caller. Arguments JSContext *cx, jsval v, double *dp
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSBool JS_ValueToBoolean()Usage JSBool JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp); Description Method; extracts a function argument from a jsval structure, converts it to a Boolean value (if possible), and passes the converted value back to the caller. Arguments JSContext *cx, jsval v, JSBool *bp
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSBool JS_ValueToObject()Usage JSBool JS_ValueToObject(JSContext *cx, jsval v, JSObject **op); Description Method; extracts a function argument from a jsval structure, converts it to an object (if possible), and passes the converted value back to the caller. If the object is an array, use JS_GetArrayLength() and JS_GetElement() to read its contents. Arguments JSContext *cx, jsval v, JSObject **op
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSBool JS_StringToValue()Usage JSBool JS_StringToValue(JSContext *cx, unsigned short *bytes, uint sz, jsval *vp); Description Method; stores a string return value in a jsval structure. It allocates a new JavaScript string object. Arguments JSContext *cx, unsigned short *bytes, size_t sz, jsval *vp
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSBool JS_DoubleToValue()Usage JSBool JS_DoubleToValue(JSContext *cx, double dv, jsval *vp); Description Method; stores a floating-point number return value in a jsval structure. Arguments JSContext *cx, double dv, jsval *vp
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSVal JS_BooleanToValue()Usage jsval JS_BooleanToValue(JSBool bv); Description Method; stores a Boolean return value in a jsval structure. Arguments JSBool bv
Returns A JSVal structure that contains the Boolean value that passes to the function as an argument. JSVal JS_BytesToValue()Usage JSBool JS_BytesToValue(JSContext *cx, unsigned short *bytes, uint sz, jsval *vp); Description Method; converts bytes to a JavaScript value. Arguments JSContext *cx, unsigned short bytes, uint sz, jsval *vp
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSVal JS_IntegerToValue()Usage jsval JS_IntegerToValue(long lv); Description Method; converts a long integer value to JSVal structure. Arguments lv
Returns A JSVal structure that contains the integer that passed to the function as an argument. JSVal JS_ObjectToValue()Usage jsval JS_ObjectToValue(JSObject *obj); Description Method; stores an object return value in a JSVal. Use JS_ NewArrayObject() to create an array object; use JS_SetElement() to define its contents. Arguments JSObject *obj
Returns A JSVal structure that contains the object that you passed to the function as an argument. unsigned short *JS_ObjectType()Usage unsigned short *JS_ObjectType(JSObject *obj); Description Method; given an object reference, returns the class name of the object. For example, if the object is a DOM object, the function returns "Document". If the object is a node in the document, the function returns "Element". For an array object, the function returns "Array". NOTE Do not modify the returned buffer pointer, or you might corrupt the data structures of the JavaScript interpreter. Arguments JSObject *obj
Returns A pointer to a null-terminated string. The caller should not free this string when it finishes. JSObject *JS_NewArrayObject()Usage JSObject *JS_NewArrayObject( JSContext *cx, unsigned int length [, jsval *v ] ) Description Method; creates a new object that contains an array of JSVals. Arguments JSContext *cx, unsigned int length, jsval *v
Returns A pointer to a new array object or the value null upon failure. long JS_GetArrayLength()Usage long JS_GetArrayLength(JSContext *cx, JSObject *obj) Description Method; given a pointer to an array object, gets the number of elements in the array. Arguments JSContext *cx, JSObject *obj
Returns The number of elements in the array or -1 upon failure. JSBool JS_GetElement()Usage JSBool JS_GetElement(JSContext *cx, JSObject *obj, jsint idx, jsval *vp) Description Method; reads a single element of an array object. Arguments JSContext *cx, JSObject *obj, unsigned int index, jsval *v
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSBool JS_SetElement()Usage JSBool JS_SetElement(JSContext *cx, JSObject *obj, jsint idx, jsval *vp) Description Method; writes a single element of an array object. Arguments JSContext *cx, JSObject *obj, unsigned int index, jsval *v
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. JSBool JS_ExecuteScript()Usage JS_ExecuteScript (JSContext *cx, JSObject *obj, unsigned short *script, unsigned int sz, jsval *rval) Description Method; compiles and executes a JavaScript string. If the script generates a return value, it returns in *rval. Arguments JSContext *cx, JSObject *obj, unsigned short *script, unsigned int sz, jsval *rval
Returns A Boolean value: JS_TRUE indicates success; JS_FALSE indicates failure. |
< Day Day Up > |