Skip to content

Commit

Permalink
Update swig, supports virtual inheritance (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar authored Aug 9, 2023
1 parent 9b5264d commit edc75f8
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 25 deletions.
Binary file modified linux/bin/swig/bin/swig
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@
%include <javascriptinit.swg>

#define %module_macro(m) %feature("module_macro","m")
#define %release_returned_cpp_object_in_gc(method) %feature("release_returned_cpp_object_in_gc", "1") method
#define %release_returned_cpp_object_in_gc(method) %feature("release_returned_cpp_object_in_gc", "1") method

%define %virtual_inherit(klass)
%feature("virtual_inherit", "1") klass;
%typemap(in) klass *self
%{ $1 = SE_THIS_OBJECT_VIRTUAL<$*ltype, cc::VirtualInheritBase>(s);
if (nullptr == $1) return true;%}
%enddef
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
$js_check_arg_count
$jslocals
$jscode
auto *ptr = JSB_MAKE_PRIVATE_OBJECT_WITH_INSTANCE(result);
s.thisObject()->setPrivateObject(ptr);
$js_set_private_object
return true;
}
SE_BIND_CTOR($jswrapper, __jsb_$jsmangledname_class, js_delete_$jsdtor)%}
Expand Down Expand Up @@ -62,8 +61,7 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
CC_UNUSED bool ok = true;
$jslocals
$jscode
auto *ptr = JSB_MAKE_PRIVATE_OBJECT_WITH_INSTANCE(result);
s.thisObject()->setPrivateObject(ptr);
$js_set_private_object
return true;
}
%}
Expand All @@ -86,26 +84,28 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)

/* -----------------------------------------------------------------------------
* js_dtor: template for a destructor wrapper
* - $jsmangledname: mangled class name
* - $classname_mangled: mangled class name
* - $jstype: class type
* ----------------------------------------------------------------------------- */
%fragment ("js_dtor", "templates")
%{
static bool $jswrapper(se::State& s) {
cc::invokeOnGarbageCollectMethod<$jsclass_type>(s);
return true;
}
SE_BIND_FINALIZE_FUNC($jswrapper) %}

/* -----------------------------------------------------------------------------
* js_dtor: template for a destructor wrapper
* - $jsmangledname: mangled class name
* - $classname_mangled: mangled class name
* - $jstype: class type
* - ${destructor_action}: The custom destructor action to invoke.
* ----------------------------------------------------------------------------- */
%fragment ("js_dtoroverride", "templates")
%{
static bool $jswrapper(se::State& s)
{
cc::invokeOnGarbageCollectMethod<$jsclass_type>(s);
return true;
}
SE_BIND_FINALIZE_FUNC($jswrapper) %}
Expand Down
Binary file modified mac/bin/swig/bin/swig
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@
%include <javascriptinit.swg>

#define %module_macro(m) %feature("module_macro","m")
#define %release_returned_cpp_object_in_gc(method) %feature("release_returned_cpp_object_in_gc", "1") method
#define %release_returned_cpp_object_in_gc(method) %feature("release_returned_cpp_object_in_gc", "1") method

%define %virtual_inherit(klass)
%feature("virtual_inherit", "1") klass;
%typemap(in) klass *self
%{ $1 = SE_THIS_OBJECT_VIRTUAL<$*ltype, cc::VirtualInheritBase>(s);
if (nullptr == $1) return true;%}
%enddef
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
$js_check_arg_count
$jslocals
$jscode
auto *ptr = JSB_MAKE_PRIVATE_OBJECT_WITH_INSTANCE(result);
s.thisObject()->setPrivateObject(ptr);
$js_set_private_object
return true;
}
SE_BIND_CTOR($jswrapper, __jsb_$jsmangledname_class, js_delete_$jsdtor)%}
Expand Down Expand Up @@ -62,8 +61,7 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
CC_UNUSED bool ok = true;
$jslocals
$jscode
auto *ptr = JSB_MAKE_PRIVATE_OBJECT_WITH_INSTANCE(result);
s.thisObject()->setPrivateObject(ptr);
$js_set_private_object
return true;
}
%}
Expand All @@ -86,26 +84,28 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)

/* -----------------------------------------------------------------------------
* js_dtor: template for a destructor wrapper
* - $jsmangledname: mangled class name
* - $classname_mangled: mangled class name
* - $jstype: class type
* ----------------------------------------------------------------------------- */
%fragment ("js_dtor", "templates")
%{
static bool $jswrapper(se::State& s) {
cc::invokeOnGarbageCollectMethod<$jsclass_type>(s);
return true;
}
SE_BIND_FINALIZE_FUNC($jswrapper) %}

/* -----------------------------------------------------------------------------
* js_dtor: template for a destructor wrapper
* - $jsmangledname: mangled class name
* - $classname_mangled: mangled class name
* - $jstype: class type
* - ${destructor_action}: The custom destructor action to invoke.
* ----------------------------------------------------------------------------- */
%fragment ("js_dtoroverride", "templates")
%{
static bool $jswrapper(se::State& s)
{
cc::invokeOnGarbageCollectMethod<$jsclass_type>(s);
return true;
}
SE_BIND_FINALIZE_FUNC($jswrapper) %}
Expand Down
6 changes: 2 additions & 4 deletions versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,5 @@ glslang (Built using https://github.com/YunHsiao/glslang/tree/build)
linux: 11.5.0
openharmony:11.5.0 (commit: 1978c76)

swig ( Built using https://github.com/cocos/swig/tree/cocos-se, executable files are downloaded from https://github.com/cocos/swig/releases/tag/cocos-v1.1.6 )
win64: cocos-v1.1.6 (commit: f52be17)
mac: cocos-v1.1.6 (commit: f52be17)
linux: cocos-v1.1.6 (commit: f52be17)
swig ( Built using https://github.com/cocos/swig/tree/cocos-se, executable files are downloaded from https://github.com/cocos/swig/releases/tag/cocos-v1.1.7 )
all: cocos-v1.1.7 (commit: 7969da2)
Binary file modified win64/bin/swig/bin/swig.exe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@
%include <javascriptinit.swg>

#define %module_macro(m) %feature("module_macro","m")
#define %release_returned_cpp_object_in_gc(method) %feature("release_returned_cpp_object_in_gc", "1") method
#define %release_returned_cpp_object_in_gc(method) %feature("release_returned_cpp_object_in_gc", "1") method

%define %virtual_inherit(klass)
%feature("virtual_inherit", "1") klass;
%typemap(in) klass *self
%{ $1 = SE_THIS_OBJECT_VIRTUAL<$*ltype, cc::VirtualInheritBase>(s);
if (nullptr == $1) return true;%}
%enddef
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
$js_check_arg_count
$jslocals
$jscode
auto *ptr = JSB_MAKE_PRIVATE_OBJECT_WITH_INSTANCE(result);
s.thisObject()->setPrivateObject(ptr);
$js_set_private_object
return true;
}
SE_BIND_CTOR($jswrapper, __jsb_$jsmangledname_class, js_delete_$jsdtor)%}
Expand Down Expand Up @@ -62,8 +61,7 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
CC_UNUSED bool ok = true;
$jslocals
$jscode
auto *ptr = JSB_MAKE_PRIVATE_OBJECT_WITH_INSTANCE(result);
s.thisObject()->setPrivateObject(ptr);
$js_set_private_object
return true;
}
%}
Expand All @@ -86,26 +84,28 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)

/* -----------------------------------------------------------------------------
* js_dtor: template for a destructor wrapper
* - $jsmangledname: mangled class name
* - $classname_mangled: mangled class name
* - $jstype: class type
* ----------------------------------------------------------------------------- */
%fragment ("js_dtor", "templates")
%{
static bool $jswrapper(se::State& s) {
cc::invokeOnGarbageCollectMethod<$jsclass_type>(s);
return true;
}
SE_BIND_FINALIZE_FUNC($jswrapper) %}

/* -----------------------------------------------------------------------------
* js_dtor: template for a destructor wrapper
* - $jsmangledname: mangled class name
* - $classname_mangled: mangled class name
* - $jstype: class type
* - ${destructor_action}: The custom destructor action to invoke.
* ----------------------------------------------------------------------------- */
%fragment ("js_dtoroverride", "templates")
%{
static bool $jswrapper(se::State& s)
{
cc::invokeOnGarbageCollectMethod<$jsclass_type>(s);
return true;
}
SE_BIND_FINALIZE_FUNC($jswrapper) %}
Expand Down

0 comments on commit edc75f8

Please sign in to comment.