diff --git a/mta-mono/src/CFunctions.cpp b/mta-mono/src/CFunctions.cpp index 6d045af..4cd6591 100644 --- a/mta-mono/src/CFunctions.cpp +++ b/mta-mono/src/CFunctions.cpp @@ -1,36 +1,45 @@ -/********************************************************* -* -* Copyright © 2013, Innovation Roleplay Engine. -* -* All Rights Reserved. -* -* Redistribution and use in source and binary forms, -* with or without modification, -* is permitted only for authors. -* -*********************************************************/ - -#include "CFunctions.h" -#include "extra/CLuaArguments.h" - -int CFunctions::monoInit( lua_State *pLuaVM ) -{ - if( pLuaVM ) - { - CResource *pResource; - - if( !( pResource = g_pResourceManager->GetFromList( pLuaVM ) ) ) - { - pResource = g_pResourceManager->Create( pLuaVM ); - } - - if( pResource ) - { - pResource->Init(); - - return 1; - } - } - - return 0; +/********************************************************* +* +* Copyright © 2013, Innovation Roleplay Engine. +* +* All Rights Reserved. +* +* Redistribution and use in source and binary forms, +* with or without modification, +* is permitted only for authors. +* +*********************************************************/ + +#include "CFunctions.h" +#include "extra/CLuaArguments.h" + +int CFunctions::monoInit( lua_State *pLuaVM ) +{ + if( pLuaVM ) + { + CResource *pResource = g_pResourceManager->GetFromList( pLuaVM ); + + if( pResource == nullptr ) + { + //if( g_pModuleManager->GetResourceName( luaVM, strName ) ) + + CLuaArgument pLuaArgument( pLuaVM, -1 ); + + string strName = pLuaArgument.GetString(); + + if( !strName.empty() ) + { + pResource = g_pResourceManager->Create( pLuaVM, strName ); + } + } + + if( pResource != nullptr ) + { + pResource->Init(); + + return 1; + } + } + + return 0; } \ No newline at end of file diff --git a/mta-mono/src/mta-mono.cpp b/mta-mono/src/mta-mono.cpp index 545dd5e..a77fcef 100644 --- a/mta-mono/src/mta-mono.cpp +++ b/mta-mono/src/mta-mono.cpp @@ -1,79 +1,78 @@ -/********************************************************* -* -* Copyright © 2013, Innovation Roleplay Engine. -* -* All Rights Reserved. -* -* Redistribution and use in source and binary forms, -* with or without modification, -* is permitted only for authors. -* -*********************************************************/ - -#include "mta-mono.h" - -MTAEXPORT bool InitModule( ILuaModuleManager10 *pManager, char *szModuleName, char *szAuthor, float *fVersion ) -{ - g_pModuleManager = pManager; - g_pResourceManager = new CResourceManager(); - - strncpy( szModuleName, MODULE_NAME, MAX_INFO_LENGTH ); - strncpy( szAuthor, MODULE_AUTHOR, MAX_INFO_LENGTH ); - - (*fVersion) = MODULE_VERSION; - - return true; -} - - -MTAEXPORT void RegisterFunctions( lua_State *pLuaVM ) -{ - if( g_pModuleManager && pLuaVM && g_pResourceManager ) - { - if( g_pModuleManager->RegisterFunction( pLuaVM, "monoInit", CFunctions::monoInit ) ) - { - luaL_dostring( pLuaVM, "addEventHandler( 'onResourceStart', resourceRoot, monoInit )" ); - } - } -} - - -MTAEXPORT bool DoPulse( void ) -{ - if( g_pResourceManager ) - { - g_pResourceManager->DoPulse(); - } - - return true; -} - -MTAEXPORT bool ShutdownModule( void ) -{ - if( g_pResourceManager ) - { - delete g_pResourceManager; - } - - return true; -} - -MTAEXPORT bool ResourceStopping( lua_State* luaVM ) -{ - if( CResource *pResource = g_pResourceManager->GetFromList( luaVM ) ) - { - pResource->OnStopping(); - } - - return true; -} - -MTAEXPORT bool ResourceStopped( lua_State* luaVM ) -{ - if( CResource *pResource = g_pResourceManager->GetFromList( luaVM ) ) - { - delete pResource; - } - - return true; +/********************************************************* +* +* Copyright © 2013, Innovation Roleplay Engine. +* +* All Rights Reserved. +* +* Redistribution and use in source and binary forms, +* with or without modification, +* is permitted only for authors. +* +*********************************************************/ + +#include "mta-mono.h" + +MTAEXPORT bool InitModule( ILuaModuleManager10 *pManager, char *szModuleName, char *szAuthor, float *fVersion ) +{ + g_pModuleManager = pManager; + g_pResourceManager = new CResourceManager(); + + strncpy( szModuleName, MODULE_NAME, MAX_INFO_LENGTH ); + strncpy( szAuthor, MODULE_AUTHOR, MAX_INFO_LENGTH ); + + (*fVersion) = MODULE_VERSION; + + return true; +} + +MTAEXPORT void RegisterFunctions( lua_State *pLuaVM ) +{ + if( g_pModuleManager && pLuaVM && g_pResourceManager ) + { + if( g_pModuleManager->RegisterFunction( pLuaVM, "monoInit", CFunctions::monoInit ) ) + { + //luaL_dostring( pLuaVM, "addEventHandler( 'onResourceStart', resourceRoot, monoInit )" ); + luaL_dostring( pLuaVM, "addEventHandler( 'onResourceStart', resourceRoot, function( res ) monoInit( getResourceName( res ) ) end )" ); + } + } +} + +MTAEXPORT bool DoPulse( void ) +{ + if( g_pResourceManager ) + { + g_pResourceManager->DoPulse(); + } + + return true; +} + +MTAEXPORT bool ShutdownModule( void ) +{ + if( g_pResourceManager ) + { + delete g_pResourceManager; + } + + return true; +} + +MTAEXPORT bool ResourceStopping( lua_State* luaVM ) +{ + if( CResource *pResource = g_pResourceManager->GetFromList( luaVM ) ) + { + pResource->OnStopping(); + } + + return true; +} + +MTAEXPORT bool ResourceStopped( lua_State* luaVM ) +{ + if( CResource *pResource = g_pResourceManager->GetFromList( luaVM ) ) + { + delete pResource; + } + + return true; } \ No newline at end of file