1.1 --- a/core/systems/PluginSys.cpp Mon Mar 12 00:07:54 2007 +0000
1.2 +++ b/core/systems/PluginSys.cpp Mon Mar 12 07:08:05 2007 +0000
1.3 @@ -588,6 +588,7 @@
1.4 m_LoadLookup = sm_trie_create();
1.5 m_AllPluginsLoaded = false;
1.6 m_MyIdent = NULL;
1.7 + m_pNativeLookup = sm_trie_create();
1.8 }
1.9
1.10 CPluginManager::~CPluginManager()
1.11 @@ -598,9 +599,9 @@
1.12 * will crash anyway. YAY
1.13 */
1.14 sm_trie_destroy(m_LoadLookup);
1.15 + sm_trie_destroy(m_pNativeLookup);
1.16 }
1.17
1.18 -
1.19 void CPluginManager::LoadAll_FirstPass(const char *config, const char *basedir)
1.20 {
1.21 /* First read in the database of plugin settings */
1.22 @@ -958,6 +959,7 @@
1.23
1.24 /* Bind all extra natives */
1.25 g_Extensions.BindAllNativesToPlugin(pPlugin);
1.26 + AddFakeNativesToPlugin(pPlugin);
1.27
1.28 /* Find any unbound natives
1.29 * Right now, these are not allowed
1.30 @@ -1013,6 +1015,32 @@
1.31 }
1.32 }
1.33
1.34 +void CPluginManager::AddFakeNativesToPlugin(CPlugin *pPlugin)
1.35 +{
1.36 + IPluginContext *pContext = pPlugin->GetBaseContext();
1.37 + sp_nativeinfo_t native;
1.38 +
1.39 + List<FakeNative *>::iterator iter;
1.40 + FakeNative *pNative;
1.41 + sp_context_t *ctx;
1.42 + for (iter = m_Natives.begin(); iter != m_Natives.end(); iter++)
1.43 + {
1.44 + pNative = (*iter);
1.45 + ctx = pNative->ctx->GetContext();
1.46 + if ((ctx->flags & SPFLAG_PLUGIN_PAUSED) == SPFLAG_PLUGIN_PAUSED)
1.47 + {
1.48 + /* Ignore natives in paused plugins */
1.49 + continue;
1.50 + }
1.51 + native.name = pNative->name.c_str();
1.52 + native.func = pNative->func;
1.53 + if (pContext->BindNative(&native) == SP_ERROR_NONE)
1.54 + {
1.55 + /* :TODO: add to dependency list */
1.56 + }
1.57 + }
1.58 +}
1.59 +
1.60 bool CPluginManager::UnloadPlugin(IPlugin *plugin)
1.61 {
1.62 CPlugin *pPlugin = (CPlugin *)plugin;
1.63 @@ -1675,3 +1703,28 @@
1.64 }
1.65 }
1.66
1.67 +bool CPluginManager::AddFakeNative(IPluginFunction *pFunction, const char *name, SPVM_FAKENATIVE_FUNC func)
1.68 +{
1.69 + if (sm_trie_retrieve(m_pNativeLookup, name, NULL))
1.70 + {
1.71 + return false;
1.72 + }
1.73 +
1.74 + FakeNative *pNative = new FakeNative;
1.75 +
1.76 + pNative->func = g_pVM->CreateFakeNative(func, pNative);
1.77 + if (!pNative->func)
1.78 + {
1.79 + delete pNative;
1.80 + return false;
1.81 + }
1.82 +
1.83 + pNative->call = pFunction;
1.84 + pNative->name.assign(name);
1.85 + pNative->ctx = pFunction->GetParentContext();
1.86 +
1.87 + m_Natives.push_back(pNative);
1.88 + sm_trie_insert(m_pNativeLookup, name,pNative);
1.89 +
1.90 + return true;
1.91 +}