Binary module compilation headache

I’m trying to get a binary module to compile. So I go download garry’s example project and that builds fine, so I update the headers to the ones in http://code.google.com/p/gmodmodules/source/browse/#svn/trunk/secretheaders and make sure everything’s working, which it isn’t. The errors are:

(the last one makes sense).

If I just don’t change those files and skip to the next part there are more errors :smiley: Specifically, I want to use functions like luaL_loadfile n stuff, which are parts of the main lua thing, so I get a copy of the “Windows x86 DLL and Includes”, put it in the project directory, add it to the include path, and lua52.lib to the linker additional dependencies list.
Then in the main file I go #include “lua.hpp”, and then attempt to use any of the functions, which resulted in “code generation” errors (nothing specific). Redid that and it compiled, however if you try to load that DLL in gmod it produces “module not found.” I move lua52.dll into the garrysmod/ (not garrysmod/garrysmod/) directory. (If I build against lua_shared.lib that azuisleet posted it errors “unresolved external symbol _luaL_loadfile”). With that DLL moved it module initializes, but a call to my function (source below) crashes it.

(it’s in a misnamed function because I just used the example)

#define NO_SDK
#include <windows.h>
#include "common/GMLuaModule.h"
#include "lua.hpp"


// This is a ma7cro to make life easier.
// When the dll is loaded it will call the function (Init)
GMOD_MODULE( Init, Shutdown );


//
// A simple messagebox example
//

LUA_FUNCTION( MsgBox )
{
	luaL_loadfile((lua_State*)g_Lua->GetLuaState(),g_Lua->GetString(1));
	// This gets the first parameter ("hello")
	//const char* Msg = 

	// Generic windows function to pop up a message box
	//MessageBox( NULL, Msg, "Lua message!", MB_OK );
 
	// We're returning nothing so return 0
	return 0;
}
(rest of Example.cpp code here)

Any people better at C++/gmod modules out there with ideas?

Yea that’s my fault, ILuaShared.h doesn’t compile with NO_SDK, I updated the SVN so you should be ok. As for using the methods like that you’ll have to create a lib for lua_shared and link against it, or you can do GetProcAddress and call it that way.

Here’s the lib file if you need it.