C++ module coding

I’ve asked several people what would be the best section for this and they all recommended me to place it here since it’s more related to GMod Lua than C++ in general. If this is the wrong forum for this question, move it to Programming and ban me.

Anyway, I’m trying to rewrite the gmcl_steamid module to practice coding a Lua module and to help the author out, since he lost the original source. So far it’s going pretty good, however it fails to load the engine interface. The error message in the code below is displayed:

[cpp]#define GAME_DLL

#include “GMLuaModule.h”
#include “cdll_int.h”

ILuaInterface* g_Lua = NULL;
IVEngineClient* g_ClientEngine = NULL;

GMOD_MODULE( Init, Shutdown );

LUA_FUNCTION( GetPlayerSteamID )
{
g_Lua->CheckType( 1, GLua::TYPE_ENTITY );

Lua()->Push( (const char*)"UNKNOWN LOL" );

return 1;

}

LUA_FUNCTION( Init )
{
g_Lua = Lua( );

CreateInterfaceFn enginedll = Sys_GetFactory( "engine.dll" );
g_ClientEngine = (IVEngineClient*)enginedll( VENGINE_CLIENT_INTERFACE_VERSION, NULL );

if( !g_ClientEngine )
{
	g_Lua->Error( "gmcl_steamid -> Failed to load engine interface!" );
	return 1;
}

ILuaObject* playerMeta = g_Lua->GetMetaTable( "Player", GLua::TYPE_ENTITY );
playerMeta->SetMember( "SteamID", GetPlayerSteamID );

return 0;

}

LUA_FUNCTION( Shutdown )
{
return 0;
}[/cpp]

I’ve also tried compiling Nevec’s gm_modelinfo model using the same setup and it also fails to load the engine interface. Does anyone have any idea what could be wrong? Here is a link to the project files.

You didn’t post the error :wink:

Edit: Oh right. I have no idea why that is happening

I would really appreciate it if someone could update the wiki on how to set up Visual Studio for lua modules. I’ve wanted to make one for a while, but no matter what I do I get spammed with errors unrelated to the actual code.

It sounds like your source SDK headers are out of date. Make sure that VENGINE_CLIENT_INTERFACE_VERSION is defined as “VEngineClient013”, since the code appears to be correct.

Also of note is the following snippet:


if( !g_ClientEngine )  
{  
    g_Lua->Error( "gmcl_steamid -> Failed to load engine interface!" );  
    return 1;  
} 

You don’t need to worry about returning a value as ILuaInterface::Error returns execution directly to Lua, not to mention that the return value of the init and shutdown functions gets discarded anyways.

Ah, that’s the problem, it is defined as ‘VEngineClient012’. I’ll see what went wrong.

Dont take ratings seriously. People just rate everyone dumb’s because they cant do better.

Also, I rated you a heart :3

I found the source if you want it. http://pastebin.com/m21e5e9fa