Add support for PackedData to Javascript generator.
This commit is contained in:
parent
e5ad9cdc05
commit
be35d94fdb
7 changed files with 718 additions and 501 deletions
|
|
@ -107,7 +107,7 @@ JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc
|
|||
%{
|
||||
void $jswrapper(JSObjectRef thisObject)
|
||||
{
|
||||
SWIG_PRV_DATA* t = (SWIG_PRV_DATA*) JSObjectGetPrivate(thisObject);
|
||||
SwigPrivData* t = (SwigPrivData*) JSObjectGetPrivate(thisObject);
|
||||
if(t && t->swigCMemOwn) free (($jstype)t->swigCObject);
|
||||
if(t) free(t);
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ void $jswrapper(JSObjectRef thisObject)
|
|||
%{
|
||||
void $jswrapper(JSObjectRef thisObject)
|
||||
{
|
||||
SWIG_PRV_DATA* t = (SWIG_PRV_DATA*) JSObjectGetPrivate(thisObject);
|
||||
SwigPrivData* t = (SwigPrivData*) JSObjectGetPrivate(thisObject);
|
||||
if(t && t->swigCMemOwn) {
|
||||
$jstype arg1 = ($jstype)t->swigCObject;
|
||||
${destructor_action}
|
||||
|
|
@ -287,6 +287,12 @@ bool SWIGJSC_INIT (JSGlobalContextRef context, JSObjectRef *exports) {
|
|||
_SwigObject_objectDefinition.staticValues = _SwigObject_values;
|
||||
_SwigObject_classRef = JSClassCreate(&_SwigObject_objectDefinition);
|
||||
|
||||
/* Initialize the PackedData class */
|
||||
_SwigPackedData_objectDefinition.staticFunctions = _SwigPackedData_functions;
|
||||
_SwigPackedData_objectDefinition.staticValues = _SwigPackedData_values;
|
||||
_SwigPackedData_objectDefinition.finalize = _wrap_SwigPackedData_delete;
|
||||
_SwigPackedData_classRef = JSClassCreate(&_SwigPackedData_objectDefinition);
|
||||
|
||||
/* Create objects for namespaces */
|
||||
$jscreatenamespaces
|
||||
|
||||
|
|
|
|||
255
Lib/javascript/jsc/javascriptrun.swg
Normal file
255
Lib/javascript/jsc/javascriptrun.swg
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
/*****************************************************************************/
|
||||
/* Errors and exceptions
|
||||
/*
|
||||
/*****************************************************************************/
|
||||
|
||||
#define SWIG_Error(code, msg) SWIG_JSC_exception(context, exception, code, msg)
|
||||
#define SWIG_exception(code, msg) SWIG_JSC_exception(context, exception, code, msg)
|
||||
#define SWIG_fail goto fail
|
||||
|
||||
void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) {
|
||||
JSStringRef message = JSStringCreateWithUTF8CString(type);
|
||||
*exception = JSValueMakeString(context, message);
|
||||
JSStringRelease(message);
|
||||
}
|
||||
|
||||
void SWIG_JSC_exception(JSContextRef context, JSValueRef *exception, int code, const char* msg) {
|
||||
SWIG_Javascript_Raise(context, exception, msg);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* The parent class of all Proxies
|
||||
/*
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
bool swigCMemOwn;
|
||||
void *swigCObject;
|
||||
swig_type_info *info;
|
||||
} SwigPrivData;
|
||||
|
||||
JSValueRef _wrap_SwigObject_disown(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
JSValueRef jsresult;
|
||||
|
||||
JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
|
||||
SwigPrivData *cdata = (SwigPrivData *) JSObjectGetPrivate(obj);
|
||||
|
||||
cdata->swigCMemOwn = false;
|
||||
|
||||
jsresult = JSValueMakeUndefined(context);
|
||||
return jsresult;
|
||||
}
|
||||
|
||||
JSValueRef _wrap_SwigObject_getCPtr(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
JSValueRef jsresult;
|
||||
long result;
|
||||
|
||||
JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
|
||||
SwigPrivData *cdata = (SwigPrivData*) JSObjectGetPrivate(obj);
|
||||
|
||||
result = (long) cdata->swigCObject;
|
||||
jsresult = JSValueMakeNumber(context, result);
|
||||
|
||||
return jsresult;
|
||||
}
|
||||
|
||||
JSValueRef _wrap_SwigObject_equals(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
JSValueRef jsresult;
|
||||
bool result;
|
||||
|
||||
JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
|
||||
SwigPrivData *cdata = (SwigPrivData*) JSObjectGetPrivate(obj);
|
||||
|
||||
JSObjectRef obj2 = JSValueToObject(context, argv[0], NULL);
|
||||
SwigPrivData *cdata2 = (SwigPrivData*) JSObjectGetPrivate(obj2);
|
||||
|
||||
result = (cdata->swigCObject == cdata2->swigCObject);
|
||||
jsresult = JSValueMakeBoolean(context, result);
|
||||
|
||||
return jsresult;
|
||||
}
|
||||
|
||||
JSStaticValue _SwigObject_values[] = {
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
};
|
||||
|
||||
JSStaticFunction _SwigObject_functions[] = {
|
||||
{
|
||||
"disown",_wrap_SwigObject_disown, kJSPropertyAttributeNone
|
||||
},
|
||||
{
|
||||
"equals",_wrap_SwigObject_equals, kJSPropertyAttributeNone
|
||||
},
|
||||
{
|
||||
"getCPtr",_wrap_SwigObject_getCPtr, kJSPropertyAttributeNone
|
||||
},
|
||||
{
|
||||
0, 0, 0
|
||||
}
|
||||
};
|
||||
|
||||
JSClassDefinition _SwigObject_objectDefinition;
|
||||
|
||||
JSClassRef _SwigObject_classRef;
|
||||
|
||||
|
||||
int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef objRef, void** ptr, swig_type_info *info, int flags) {
|
||||
SwigPrivData *cdata = (SwigPrivData *) JSObjectGetPrivate(objRef);
|
||||
if(cdata == NULL) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
if(cdata->info != info) {
|
||||
bool type_valid = false;
|
||||
swig_cast_info *t = info->cast;
|
||||
while(t != NULL) {
|
||||
if(t->type == cdata->info) {
|
||||
type_valid = true;
|
||||
break;
|
||||
}
|
||||
t = t->next;
|
||||
}
|
||||
if(!type_valid) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
*ptr = cdata->swigCObject;
|
||||
|
||||
if(flags & SWIG_POINTER_DISOWN) {
|
||||
cdata->swigCMemOwn = false;
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int SWIG_JSC_ConvertPtr(JSContextRef context, JSValueRef valRef, void** ptr, swig_type_info *info, int flags) {
|
||||
if(!JSValueIsObject(context, valRef)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
JSObjectRef objRef = JSValueToObject(context, valRef, NULL);
|
||||
if(objRef == NULL) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
return SWIG_JSC_ConvertInstancePtr(context, objRef, ptr, info, flags);
|
||||
}
|
||||
|
||||
JSObjectRef SWIG_JSC_NewPointerObj(JSContextRef context, void *ptr, swig_type_info *info, int flags) {
|
||||
|
||||
JSClassRef classRef;
|
||||
if(info->clientdata == NULL) {
|
||||
classRef = _SwigObject_classRef;
|
||||
} else {
|
||||
classRef = (JSClassRef) info->clientdata;
|
||||
}
|
||||
|
||||
JSObjectRef result = JSObjectMake(context, classRef, NULL);
|
||||
|
||||
SwigPrivData* cdata = (SwigPrivData*) malloc(sizeof(SwigPrivData));
|
||||
cdata->swigCObject = ptr;
|
||||
cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0;
|
||||
cdata->info = info;
|
||||
|
||||
JSObjectSetPrivate(result, cdata);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define SWIG_ConvertPtr(obj, ptr, info, flags) SWIG_JSC_ConvertPtr(context, obj, ptr, info, flags)
|
||||
#define SWIG_NewPointerObj(ptr, info, flags) SWIG_JSC_NewPointerObj(context, ptr, info, flags)
|
||||
|
||||
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_JSC_ConvertInstancePtr(context, obj, pptr, type, flags)
|
||||
#define SWIG_NewInstanceObj(thisvalue, type, flags) SWIG_JSC_NewPointerObj(context, thisvalue, type, flags)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* A class for packed data
|
||||
/*
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
void *data;
|
||||
size_t size;
|
||||
swig_type_info *type;
|
||||
} SwigPackedData;
|
||||
|
||||
JSStaticValue _SwigPackedData_values[] = {
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
};
|
||||
JSStaticFunction _SwigPackedData_functions[] = {
|
||||
{
|
||||
0, 0, 0
|
||||
}
|
||||
};
|
||||
JSClassDefinition _SwigPackedData_objectDefinition;
|
||||
JSClassRef _SwigPackedData_classRef;
|
||||
|
||||
SWIGRUNTIMEINLINE
|
||||
int SwigJSCPacked_Check(JSContextRef context, JSValueRef valRef) {
|
||||
return JSValueIsObjectOfClass(context, valRef, _SwigPackedData_classRef);
|
||||
}
|
||||
|
||||
SWIGRUNTIME
|
||||
swig_type_info* SwigJSCPacked_UnpackData(JSContextRef context, JSValueRef valRef, void *ptr, size_t size) {
|
||||
if (SwigJSCPacked_Check(context, valRef)) {
|
||||
JSObjectRef objRef = JSValueToObject(context, valRef, NULL);
|
||||
SwigPackedData *sobj = (SwigPackedData *) JSObjectGetPrivate(objRef);
|
||||
if (sobj->size != size) return 0;
|
||||
memcpy(ptr, sobj->data, size);
|
||||
return sobj->type;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
SWIGRUNTIME
|
||||
int SWIG_JSC_ConvertPacked(JSContextRef context, JSValueRef valRef, void *ptr, size_t sz, swig_type_info *ty) {
|
||||
swig_type_info *to = SwigJSCPacked_UnpackData(context, valRef, ptr, sz);
|
||||
if (!to) return SWIG_ERROR;
|
||||
if (ty) {
|
||||
if (to != ty) {
|
||||
/* check type cast? */
|
||||
swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
|
||||
if (!tc) return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
SWIGRUNTIME
|
||||
JSValueRef SWIG_JSC_NewPackedObj(JSContextRef context, void *data, size_t size, swig_type_info *type) {
|
||||
|
||||
JSClassRef classRef = _SwigObject_classRef;
|
||||
JSObjectRef result = JSObjectMake(context, classRef, NULL);
|
||||
|
||||
SwigPackedData* cdata = (SwigPackedData*) malloc(sizeof(SwigPackedData));
|
||||
cdata->data = data;
|
||||
cdata->size = size;
|
||||
cdata->type = type;
|
||||
|
||||
JSObjectSetPrivate(result, cdata);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* SwigPackedData wrappers */
|
||||
|
||||
void _wrap_SwigPackedData_delete(JSObjectRef obj)
|
||||
{
|
||||
SwigPackedData* cdata = (SwigPackedData*) JSObjectGetPrivate(obj);
|
||||
if (cdata) {
|
||||
free(cdata->data);
|
||||
}
|
||||
}
|
||||
|
||||
/* for C++ member pointers, ie, member methods */
|
||||
|
||||
#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_JSC_ConvertPacked(context, obj, ptr, sz, ty)
|
||||
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_JSC_NewPackedObj(context, ptr, sz, type)
|
||||
|
|
@ -14,183 +14,6 @@
|
|||
%}
|
||||
|
||||
%insert(runtime) "swigrun.swg"; /* SWIG API */
|
||||
%insert(runtime) "swigerrors.swg"; /* SWIG errors */
|
||||
%insert(runtime) "swigerrors.swg"; /* SWIG errors */
|
||||
|
||||
%insert(runtime) %{
|
||||
#define SWIG_Error(code, msg) SWIG_JSC_exception(context, exception, code, msg)
|
||||
#define SWIG_exception(code, msg) SWIG_JSC_exception(context, exception, code, msg)
|
||||
#define SWIG_fail goto fail
|
||||
|
||||
#define SWIG_JSC_FROM_DECL_ARGS(arg1) (JSContextRef context, arg1)
|
||||
#define SWIG_JSC_FROM_CALL_ARGS(arg1) (context, arg1)
|
||||
#define SWIG_JSC_AS_DECL_ARGS(arg1, arg2) (JSContextRef context, arg1, arg2)
|
||||
#define SWIG_JSC_AS_CALL_ARGS(arg1, arg2) (context, arg1, arg2)
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
typedef struct {
|
||||
bool swigCMemOwn;
|
||||
void *swigCObject;
|
||||
swig_type_info *info;
|
||||
}SWIG_PRV_DATA;
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
|
||||
void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) {
|
||||
JSStringRef message = JSStringCreateWithUTF8CString(type);
|
||||
*exception = JSValueMakeString(context, message);
|
||||
JSStringRelease(message);
|
||||
}
|
||||
|
||||
void SWIG_JSC_exception(JSContextRef context, JSValueRef *exception, int code, const char* msg) {
|
||||
SWIG_Javascript_Raise(context, exception, msg);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
|
||||
JSValueRef _wrap_SwigObject_disown(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
JSValueRef jsresult;
|
||||
|
||||
JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
|
||||
SWIG_PRV_DATA *cdata = (SWIG_PRV_DATA *) JSObjectGetPrivate(obj);
|
||||
|
||||
cdata->swigCMemOwn = false;
|
||||
|
||||
jsresult = JSValueMakeUndefined(context);
|
||||
return jsresult;
|
||||
}
|
||||
|
||||
JSValueRef _wrap_SwigObject_getCPtr(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
JSValueRef jsresult;
|
||||
long result;
|
||||
|
||||
JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
|
||||
SWIG_PRV_DATA *cdata = (SWIG_PRV_DATA*) JSObjectGetPrivate(obj);
|
||||
|
||||
result = (long) cdata->swigCObject;
|
||||
jsresult = JSValueMakeNumber(context, result);
|
||||
|
||||
return jsresult;
|
||||
}
|
||||
|
||||
JSValueRef _wrap_SwigObject_equals(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
JSValueRef jsresult;
|
||||
bool result;
|
||||
|
||||
JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
|
||||
SWIG_PRV_DATA *cdata = (SWIG_PRV_DATA*) JSObjectGetPrivate(obj);
|
||||
|
||||
JSObjectRef obj2 = JSValueToObject(context, argv[0], NULL);
|
||||
SWIG_PRV_DATA *cdata2 = (SWIG_PRV_DATA*) JSObjectGetPrivate(obj2);
|
||||
|
||||
result = (cdata->swigCObject == cdata2->swigCObject);
|
||||
jsresult = JSValueMakeBoolean(context, result);
|
||||
|
||||
return jsresult;
|
||||
}
|
||||
|
||||
JSStaticValue _SwigObject_values[] = {
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
};
|
||||
|
||||
JSStaticFunction _SwigObject_functions[] = {
|
||||
{
|
||||
"disown",_wrap_SwigObject_disown, kJSPropertyAttributeNone
|
||||
},
|
||||
{
|
||||
"equals",_wrap_SwigObject_equals, kJSPropertyAttributeNone
|
||||
},
|
||||
{
|
||||
"getCPtr",_wrap_SwigObject_getCPtr, kJSPropertyAttributeNone
|
||||
},
|
||||
{
|
||||
0, 0, 0
|
||||
}
|
||||
};
|
||||
|
||||
JSClassDefinition _SwigObject_objectDefinition;
|
||||
|
||||
JSClassRef _SwigObject_classRef;
|
||||
|
||||
%}
|
||||
|
||||
|
||||
%insert(runtime) %{
|
||||
int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef objRef, void** ptr, swig_type_info *info, int flags) {
|
||||
SWIG_PRV_DATA *cdata = (SWIG_PRV_DATA *) JSObjectGetPrivate(objRef);
|
||||
if(cdata == NULL) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
if(cdata->info != info) {
|
||||
bool type_valid = false;
|
||||
swig_cast_info *t = info->cast;
|
||||
while(t != NULL) {
|
||||
if(t->type == cdata->info) {
|
||||
type_valid = true;
|
||||
break;
|
||||
}
|
||||
t = t->next;
|
||||
}
|
||||
if(!type_valid) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
*ptr = cdata->swigCObject;
|
||||
|
||||
if(flags & SWIG_POINTER_DISOWN) {
|
||||
cdata->swigCMemOwn = false;
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int SWIG_JSC_ConvertPtr(JSContextRef context, JSValueRef valRef, void** ptr, swig_type_info *info, int flags) {
|
||||
if(!JSValueIsObject(context, valRef)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
JSObjectRef objRef = JSValueToObject(context, valRef, NULL);
|
||||
if(objRef == NULL) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
return SWIG_JSC_ConvertInstancePtr(context, objRef, ptr, info, flags);
|
||||
}
|
||||
|
||||
JSObjectRef SWIG_JSC_NewPointerObj(JSContextRef context, void *ptr, swig_type_info *info, int flags) {
|
||||
|
||||
JSClassRef classRef;
|
||||
if(info->clientdata == NULL) {
|
||||
classRef = _SwigObject_classRef;
|
||||
} else {
|
||||
classRef = (JSClassRef) info->clientdata;
|
||||
}
|
||||
|
||||
JSObjectRef result = JSObjectMake(context, classRef, NULL);
|
||||
|
||||
SWIG_PRV_DATA* cdata = (SWIG_PRV_DATA*) malloc(sizeof(SWIG_PRV_DATA));
|
||||
cdata->swigCObject = ptr;
|
||||
cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0;
|
||||
cdata->info = info;
|
||||
|
||||
JSObjectSetPrivate(result, cdata);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define SWIG_ConvertPtr(obj, ptr, info, flags) SWIG_JSC_ConvertPtr(context, obj, ptr, info, flags)
|
||||
#define SWIG_NewPointerObj(ptr, info, flags) SWIG_JSC_NewPointerObj(context, ptr, info, flags)
|
||||
|
||||
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_JSC_ConvertInstancePtr(context, obj, pptr, type, flags)
|
||||
#define SWIG_NewInstanceObj(thisvalue, type, flags) SWIG_JSC_NewPointerObj(context, thisvalue, type, flags)
|
||||
|
||||
%}
|
||||
%insert(runtime) "javascriptrun.swg"; /* SWIG errors */
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
/* These macros are necessary to provide an extra parameter
|
||||
to SWIG_AsVal_dec functions (JSContextRef context).
|
||||
They must be defined before including `typemaps/fragments.swg`
|
||||
*/
|
||||
#define SWIG_FROM_DECL_ARGS SWIG_JSC_FROM_DECL_ARGS
|
||||
#define SWIG_FROM_CALL_ARGS SWIG_JSC_FROM_CALL_ARGS
|
||||
|
|
@ -42,5 +43,12 @@
|
|||
/* raise */
|
||||
#define SWIG_Raise(obj, type, desc) SWIG_Javascript_Raise(context, exception, type)
|
||||
|
||||
%insert("runtime") %{
|
||||
#define SWIG_JSC_FROM_DECL_ARGS(arg1) (JSContextRef context, arg1)
|
||||
#define SWIG_JSC_FROM_CALL_ARGS(arg1) (context, arg1)
|
||||
#define SWIG_JSC_AS_DECL_ARGS(arg1, arg2) (JSContextRef context, arg1, arg2)
|
||||
#define SWIG_JSC_AS_CALL_ARGS(arg1, arg2) (context, arg1, arg2)
|
||||
%}
|
||||
|
||||
/* Include the unified typemap library */
|
||||
%include <typemaps/swigtypemaps.swg>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue