Skip to content

Commit 05766f0

Browse files
committed
Update to latest ILuaModuleManager
1 parent 2119a51 commit 05766f0

File tree

3 files changed

+54
-41
lines changed

3 files changed

+54
-41
lines changed

amx-deps/src/CFunctions.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,15 @@ int CFunctions::amxRegisterLuaPrototypes(lua_State *luaVM) {
407407
luaL_checktype(luaVM, 1, LUA_TTABLE);
408408
int mainTop = lua_gettop(mainVM);
409409

410-
string resName;
411-
pModuleManager->GetResourceName(luaVM, resName);
410+
char resName[255];
411+
pModuleManager->GetResourceName(luaVM, resName, 255);
412412
lua_getfield(mainVM, LUA_REGISTRYINDEX, "amx");
413-
lua_getfield(mainVM, -1, resName.c_str());
413+
lua_getfield(mainVM, -1, resName);
414414
if(lua_isnil(mainVM, -1)) {
415415
lua_pop(mainVM, 1);
416416
lua_newtable(mainVM);
417417
lua_pushvalue(mainVM, -1);
418-
lua_setfield(mainVM, -3, resName.c_str());
418+
lua_setfield(mainVM, -3, resName);
419419
}
420420

421421
lua_newtable(mainVM);
@@ -488,18 +488,18 @@ int CFunctions::pawn(lua_State *luaVM) {
488488

489489
int mainTop = lua_gettop(mainVM);
490490

491-
string resName;
492-
pModuleManager->GetResourceName(luaVM, resName);
491+
char resName[255];
492+
pModuleManager->GetResourceName(luaVM, resName, 255);
493493
lua_getfield(mainVM, LUA_REGISTRYINDEX, "amx");
494-
lua_getfield(mainVM, -1, resName.c_str());
494+
lua_getfield(mainVM, -1, resName);
495495
if(lua_isnil(mainVM, -1)) {
496496
lua_settop(mainVM, mainTop);
497-
return luaL_error(luaVM, "pawn: resource %s is not an amx resource", resName.c_str());
497+
return luaL_error(luaVM, "pawn: resource %s is not an amx resource", resName);
498498
}
499499
lua_getfield(mainVM, -1, "pawnprototypes");
500500
if(lua_isnil(mainVM, -1)) {
501501
lua_settop(mainVM, mainTop);
502-
return luaL_error(luaVM, "pawn: resource %s does not have any registered Pawn functions - see amxRegisterPawnPrototypes", resName.c_str());
502+
return luaL_error(luaVM, "pawn: resource %s does not have any registered Pawn functions - see amxRegisterPawnPrototypes", resName);
503503
}
504504
lua_getfield(mainVM, -1, fnName);
505505
if(lua_isnil(mainVM, -1)) {
Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,65 @@
11
/*****************************************************************************
2-
*
3-
* PROJECT: Multi Theft Auto v1.0
4-
* LICENSE: See LICENSE in the top level directory
5-
* FILE: publicsdk/include/ILuaModuleManager.h
6-
* PURPOSE: Lua dynamic module interface
7-
*
8-
* Multi Theft Auto is available from http://www.multitheftauto.com/
9-
*
10-
*****************************************************************************/
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: publicsdk/include/ILuaModuleManager.h
6+
* PURPOSE: Lua dynamic module interface
7+
*
8+
* Multi Theft Auto is available from http://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
1111

1212
// INTERFACE for Lua dynamic modules
1313

14-
#ifndef __ILUAMODULEMANAGER_H
15-
#define __ILUAMODULEMANAGER_H
14+
#pragma once
1615

1716
#define MAX_INFO_LENGTH 128
1817

1918
extern "C"
2019
{
21-
#include "lua.h"
22-
#include "lualib.h"
23-
#include "lauxlib.h"
20+
#include <lua.h>
21+
#include <lualib.h>
22+
#include <lauxlib.h>
2423
}
24+
#include <string>
25+
26+
#ifndef __CChecksum_H
27+
class CChecksum
28+
{
29+
public:
30+
unsigned long ulCRC;
31+
unsigned char mD5[16];
32+
};
33+
#endif
2534

2635
/* Interface for modules until DP2.3 */
2736
class ILuaModuleManager
2837
{
2938
public:
30-
virtual void ErrorPrintf ( const char* szFormat, ... ) = 0;
31-
virtual void DebugPrintf ( lua_State * luaVM, const char* szFormat, ... ) = 0;
32-
virtual void Printf ( const char* szFormat, ... ) = 0;
33-
34-
virtual bool RegisterFunction ( lua_State * luaVM, const char *szFunctionName, lua_CFunction Func ) = 0;
35-
virtual bool GetResourceName ( lua_State * luaVM, std::string &strName ) = 0;
36-
virtual unsigned long GetResourceMetaCRC ( lua_State * luaVM ) = 0;
37-
virtual unsigned long GetResourceFileCRC ( lua_State * luaVM, const char* szFile ) = 0;
39+
virtual void ErrorPrintf(const char* szFormat, ...) = 0;
40+
virtual void DebugPrintf(lua_State* luaVM, const char* szFormat, ...) = 0;
41+
virtual void Printf(const char* szFormat, ...) = 0;
42+
43+
virtual bool RegisterFunction(lua_State* luaVM, const char* szFunctionName, lua_CFunction Func) = 0;
44+
virtual bool GetResourceName(
45+
lua_State* luaVM, std::string& strName) = 0; // This function might not work if module and MTA were compiled with different compiler versions
46+
virtual CChecksum GetResourceMetaChecksum(lua_State* luaVM) = 0;
47+
virtual CChecksum GetResourceFileChecksum(lua_State* luaVM, const char* szFile) = 0;
3848
};
3949

4050
/* Interface for modules until 1.0 */
4151
class ILuaModuleManager10 : public ILuaModuleManager
4252
{
4353
public:
44-
virtual unsigned long GetVersion ( ) = 0;
45-
virtual const char* GetVersionString ( ) = 0;
46-
virtual const char* GetVersionName ( ) = 0;
47-
virtual unsigned long GetNetcodeVersion ( ) = 0;
48-
virtual const char* GetOperatingSystemName ( ) = 0;
54+
virtual unsigned long GetVersion() = 0;
55+
virtual const char* GetVersionString() = 0;
56+
virtual const char* GetVersionName() = 0;
57+
virtual unsigned long GetNetcodeVersion() = 0;
58+
virtual const char* GetOperatingSystemName() = 0;
4959

50-
virtual lua_State* GetResourceFromName ( const char* szResourceName ) = 0;
51-
};
60+
virtual lua_State* GetResourceFromName(const char* szResourceName) = 0;
5261

53-
#endif
62+
// GetResourceName above doesn't work if module and MTA were compiled with different compiler versions
63+
virtual bool GetResourceName(lua_State* luaVM, char* szName, size_t length) = 0;
64+
virtual bool GetResourceFilePath(lua_State* luaVM, const char* fileName, char* path, size_t length) = 0;
65+
};

amx-deps/src/ml_base.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ MTAEXPORT void RegisterFunctions ( lua_State * luaVM )
150150
pModuleManager->RegisterFunction(luaVM, "amxVersion", CFunctions::amxVersion);
151151
pModuleManager->RegisterFunction(luaVM, "amxVersionString", CFunctions::amxVersionString);
152152

153-
string resName;
154-
if(!pModuleManager->GetResourceName(luaVM, resName) || resName.compare("amx"))
153+
char resNameBuf[4];
154+
bool ok = pModuleManager->GetResourceName(luaVM, resNameBuf, 4);
155+
if (!ok || std::string(resNameBuf) != "amx")
155156
return;
156157

157158
mainVM = luaVM;

0 commit comments

Comments
 (0)