Skip to content

Commit 0a60050

Browse files
committed
[cppia] Infer overrides from matching method name
For haxe versions that do not tag overridden methods in __scriptableFunctions tables, we can infer overrides at runtime by comparing method names.
1 parent e109b08 commit 0a60050

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/hx/cppia/Cppia.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,9 @@ struct CppiaVar
575575

576576

577577

578+
#if (HXCPP_API_LEVEL >= 500)
579+
# define NATIVE_CLASS_OVERRIDES_MARKED
580+
#endif
578581

579582
class HaxeNativeClass
580583
{
@@ -596,6 +599,10 @@ class HaxeNativeClass
596599
static HaxeNativeClass *findClass(const std::string &inName);
597600
static HaxeNativeClass *hxObject();
598601
static void link();
602+
#ifndef NATIVE_CLASS_OVERRIDES_MARKED
603+
private:
604+
void addVtableEntries( std::vector<std::string> &outVtable, hx::UnorderedSet<std::string> &outMethodsSet);
605+
#endif
599606
};
600607

601608
class HaxeNativeInterface

src/hx/cppia/HaxeNative.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,36 @@ HaxeNativeClass::HaxeNativeClass(const std::string &inName, int inDataOffset, Sc
3030
haxeSuper = 0;
3131
}
3232

33+
#ifdef NATIVE_CLASS_OVERRIDES_MARKED
3334
void HaxeNativeClass::addVtableEntries( std::vector<std::string> &outVtable)
3435
{
3536
if (haxeSuper)
3637
haxeSuper->addVtableEntries(outVtable);
3738

3839
if (functions)
3940
for(ScriptNamedFunction *func = functions; func->name; func++)
40-
#if (HXCPP_API_LEVEL >= 500)
4141
if (!func->isStatic && !func->isOverride)
42-
#else
43-
if (!func->isStatic)
44-
#endif
4542
outVtable.push_back( func->name );
4643
}
44+
#else
45+
void HaxeNativeClass::addVtableEntries(std::vector<std::string>& outVtable) {
46+
hx::UnorderedSet<std::string> methodsSet;
47+
addVtableEntries(outVtable, methodsSet);
48+
}
49+
50+
void HaxeNativeClass::addVtableEntries( std::vector<std::string> &outVtable, hx::UnorderedSet<std::string>& outMethodsSet)
51+
{
52+
if (haxeSuper)
53+
haxeSuper->addVtableEntries(outVtable, outMethodsSet);
54+
55+
if (functions)
56+
for (ScriptNamedFunction* func = functions; func->name; func++)
57+
if (!func->isStatic && outMethodsSet.find(func->name) == outMethodsSet.end()) {
58+
outVtable.push_back(func->name);
59+
outMethodsSet.emplace(func->name);
60+
}
61+
}
62+
#endif
4763

4864
void HaxeNativeClass::dump()
4965
{

0 commit comments

Comments
 (0)