@@ -53,11 +53,6 @@ Result<InitData> RustLanguageModule::Initialize(const Provider& provider, [[mayb
5353}
5454
5555void RustLanguageModule::Shutdown () {
56- for (MemAddr* addr : _addresses) {
57- *addr = nullptr ;
58- }
59- _nativesMap.clear ();
60- _addresses.clear ();
6156 _assemblies.clear ();
6257 _provider.reset ();
6358}
@@ -70,10 +65,13 @@ bool RustLanguageModule::IsDebugBuild() {
7065}
7166
7267void RustLanguageModule::OnMethodExport (const Extension& plugin) {
73- const auto & methods = plugin.GetMethodsData ();
74- _nativesMap.reserve (_nativesMap.size () + methods.size ());
75- for (const auto & [method, addr] :methods) {
76- _nativesMap.try_emplace (std::format (" {}.{}" , plugin.GetName (), method.GetName ()), addr);
68+ for (const auto & [method, addr] : plugin.GetMethodsData ()) {
69+ auto variableName = std::format (" __{}_{}" , plugin.GetName (), method.GetName ());
70+ for (const auto & assembly : _assemblies) {
71+ if (auto function = assembly->assembly ->GetSymbol (variableName)) {
72+ *function->RCast <MemAddr*>() = addr;
73+ }
74+ }
7775 }
7876}
7977
@@ -168,32 +166,10 @@ void RustLanguageModule::OnPluginEnd(const Extension& plugin) {
168166 plugin.GetUserData ().RCast <AssemblyHolder*>()->endFunc ();
169167}
170168
171- MemAddr RustLanguageModule::GetNativeMethod (std::string_view methodName) const {
172- if (const auto it = _nativesMap.find (methodName); it != _nativesMap.end ()) {
173- return std::get<MemAddr>(*it);
174- }
175- _provider->Log (std::format (LOG_PREFIX " GetNativeMethod failed to find: '{}'" , methodName), Severity::Fatal);
176- return nullptr ;
177- }
178-
179- void RustLanguageModule::GetNativeMethod (std::string_view methodName, MemAddr* addressDest) {
180- if (const auto it = _nativesMap.find (methodName); it != _nativesMap.end ()) {
181- *addressDest = std::get<MemAddr>(*it);
182- _addresses.emplace_back (addressDest);
183- return ;
184- }
185- _provider->Log (std::format (LOG_PREFIX " GetNativeMethod failed to find: '{}'" , methodName), Severity::Fatal);
186- }
187-
188169namespace rustlm {
189170 RustLanguageModule g_rustlm;
190171}
191172
192-
193- void * GetMethodPtr (const char * mstr, size_t mlen) {
194- return g_rustlm.GetNativeMethod (std::string_view (mstr, mlen));
195- }
196-
197173bool IsExtensionLoaded (const char * nstr, size_t nlen, const char * cstr, size_t clen) {
198174 std::string_view name (nstr, nlen);
199175 std::string_view constraint (cstr, clen);
@@ -442,8 +418,7 @@ void AssignVectorVector3(plg::vector<plg::vec3>* ptr, plg::vec3* arr, size_t len
442418void AssignVectorVector4 (plg::vector<plg::vec4>* ptr, plg::vec4* arr, size_t len) { AssignVector (ptr, arr, len); }
443419void AssignVectorMatrix4x4 (plg::vector<plg::mat4x4>* ptr, plg::mat4x4* arr, size_t len) { AssignVector (ptr, arr, len); }
444420
445- const std::array<void *, 123 > RustLanguageModule::_pluginApi = {
446- reinterpret_cast <void *>(&::GetMethodPtr),
421+ const std::array<void *, 122 > RustLanguageModule::_pluginApi = {
447422 reinterpret_cast <void *>(&::GetBaseDir),
448423 reinterpret_cast <void *>(&::GetExtensionsDir),
449424 reinterpret_cast <void *>(&::GetConfigsDir),
0 commit comments