From: <ne...@us...> - 2012-06-26 18:30:44
|
Revision: 13197 http://swig.svn.sourceforge.net/swig/?rev=13197&view=rev Author: neha1 Date: 2012-06-26 18:30:38 +0000 (Tue, 26 Jun 2012) Log Message: ----------- Added JSC helper function Added JSC helper function. Modified Paths: -------------- branches/gsoc2012-javascript/Lib/javascript/jsc/javascriptcode.swg branches/gsoc2012-javascript/Lib/javascript/jsc/javascripthelpers.swg Modified: branches/gsoc2012-javascript/Lib/javascript/jsc/javascriptcode.swg =================================================================== --- branches/gsoc2012-javascript/Lib/javascript/jsc/javascriptcode.swg 2012-06-26 18:30:02 UTC (rev 13196) +++ branches/gsoc2012-javascript/Lib/javascript/jsc/javascriptcode.swg 2012-06-26 18:30:38 UTC (rev 13197) @@ -4,8 +4,21 @@ * Additional Javascript typemaps for generating code for classes, constants and variables * ----------------------------------------------------------------------------- ----------------*/ +%fragment ("jsc_initializer", "templates") %{ +int ${modulename}_initialize(JSGlobalContextRef context) { + JSObjectRef globalObject = JSContextGetGlobalObject(context); + + ${initializercode} + return SWIG_OK; +} +%} + +%fragment ("jsc_register_global_function", "templates") +%{ +jscinitfunction("${context}", "${context_object}", "${functionname}", "${functionwrapper}"); +%} /* Additional typemaps for the class code needed by the access layer. This code is copy-pasted into the wrapper header and source file */ -%fragment ("getpropertydecl", "templates") +%fragment ("getproperty", "templates") %{ JSValueRef ${getname}(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) { @@ -15,28 +28,30 @@ } %} -%fragment ("setpropertydecl", "templates") +%fragment ("setproperty", "templates") %{ -bool ${setname}(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, -JSValueRef* exception) -JSValueRef* exception); +bool ${setname}(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { ${LOCALS} ${CODE} } %} -%fragment ("functiondecl", "templates") +%fragment ("functionwrapper", "templates") %{ -JSValueRef $functionname(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception) +JSValueRef ${functionname}(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception) { ${LOCALS} ${CODE} - return jsresult; } %} +%fragment ("staticfunctiondecl", "templates") +%{ + {"${propertyname}", "${getname}", "${setname}", +kJSPropertyAttributeNone } +%} %fragment ("accessconstructordecl", "templates") %{ @@ -205,7 +220,7 @@ %{ JSStaticValue cvar_staticValues[] = { -$jsstaticvarcode +${jsstaticvarcode} { 0, 0, 0, 0 } }; @@ -238,4 +253,3 @@ %} - Modified: branches/gsoc2012-javascript/Lib/javascript/jsc/javascripthelpers.swg =================================================================== --- branches/gsoc2012-javascript/Lib/javascript/jsc/javascripthelpers.swg 2012-06-26 18:30:02 UTC (rev 13196) +++ branches/gsoc2012-javascript/Lib/javascript/jsc/javascripthelpers.swg 2012-06-26 18:30:38 UTC (rev 13197) @@ -0,0 +1,9 @@ +%insert(runtime) %{ +bool jscinitfunction(JSGlobalContextRef context, JSObjectRef object, const char* szFunctionName,JSObjectCallAsFunctionCallback cbFunction) +{ + JSStringRef functionString = JSStringCreateWithUTF8CString(szFunctionName); + JSObjectSetProperty(context, object, functionString,JSObjectMakeFunctionWithCallback(context, functionString, cbFunction),kJSPropertyAttributeNone,NULL); + JSStringRelease(functionString); + return true; +} +%} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |