The amount of trouble shooting that accompanies the first steps towards GMod module writing is in no way justified by the result, but nonetheless I have to get this working.
I compile this and save it as gmcl_test.dll and require("test") in game and it works:
[code]
#include <lua.hpp>
#include <windows.h>
#define NO_SDK
#include "GMLuaModule.h"
GMOD_MODULE(Init,Shutdown)
int Init(lua_State *L)
{
return 0;
}
int Shutdown(lua_State *L)
{
return 0;
}
[/code]
works fine, but this simple progression:
[code]
#include <lua.hpp>
#include <windows.h>
#define NO_SDK
#include "GMLuaModule.h"
GMOD_MODULE(Init,Shutdown)
int Init(lua_State *L)
{
lua_getfield(L, LUA_GLOBALSINDEX, "Msg");
lua_pushstring(L, "Loaded\n");
lua_call(L, 1, 0);
return 0;
}
int Shutdown(lua_State *L)
{
lua_getfield(L, LUA_GLOBALSINDEX, "Msg");
lua_pushstring(L, "Unloaded\n");
lua_call(L, 1, 0);
return 0;
}
[/code]
results in this error when I require() it in game:
[code]
error loading module 'test' from file 'c:\program files (x86)\steam\steamapps\****\garrysmod\garrysmod\lua\includes\modules\gmcl_test.dll':
The specified module could not be found.
[/code]
If you need more info about my Visual Studio setup, let me know.
50 views and no replys? This seems trivial, what am I doing wrong?
Btw, where did you learn about how to write GMod modules? It looks interesting.
You should really use the ILuaInterface that comes with modules, in which case your code would look like this:
[cpp]
#include <windows.h>
#define NO_SDK
#include "GMLuaModule.h"
GMOD_MODULE(Init,Shutdown)
int Init(lua_State *L)
{
Msg( "Loaded\n" );
return 0;
}
int Shutdown(lua_State *L)
{
Msg( "Unloaded\n");
return 0;
}[/cpp]
If you want to go the hard way about printing you should also do that via the ILuaInterface.
I actually found a good way to setup the headers and include the SDK.
[url]http://gmodmodules.googlecode.com/svn/trunk/gm_transmittools/gm_transmittools/gm_transmittools.h[/url]
[code]
#define _RETAIL 1
#define GAME_DLL 1
//hl2sdk-ob-2e2ec01be7aa off the sourcemod mercurial
#include <server/cbase.h>
[/code]
I wish I had known sooner! This does all the includes you need for the SDK, and then you don't have to define NO_SDK. And like the previous poster said, you should be using the ILuaInterface interface and not the lua_ functions, you would have to GetProcAddress them or make a .lib and link against it.
Thanks guys, this helped a lot, I didn't realize GMod modules where so different from normal lua modules.
Here is the import library for lua_shared.dll
[url]http://www.cdbarrett.com/dump/releases/lua_shared.lib[/url]
[QUOTE=Howe;18633023]The amount of trouble shooting that accompanies the first steps towards GMod module writing is in no way justified by the result, but nonetheless I have to get this working.
I compile this and save it as gmcl_test.dll and require("test") in game and it works:
[code]
#include <lua.hpp>
#include <windows.h>
#define NO_SDK
Thank you very much! I will test it!
#include "GMLuaModule.h"
GMOD_MODULE(Init,Shutdown)
int Init(lua_State *L)
{
return 0;
}
int Shutdown(lua_State *L)
{
return 0;
}
[/code]
works fine, but this simple progression:
[code]
#include <lua.hpp>
#include <windows.h>
#define NO_SDK
#include "GMLuaModule.h"
GMOD_MODULE(Init,Shutdown)
int Init(lua_State *L)
{
lua_getfield(L, LUA_GLOBALSINDEX, "Msg");
lua_pushstring(L, "Loaded\n");
lua_call(L, 1, 0);
return 0;
}
int Shutdown(lua_State *L)
{
lua_getfield(L, LUA_GLOBALSINDEX, "Msg");
lua_pushstring(L, "Unloaded\n");
lua_call(L, 1, 0);
return 0;
}
[/code]
results in this error when I require() it in game:
[code]
error loading module 'test' from file 'c:\program files (x86)\steam\steamapps\****\garrysmod\garrysmod\lua\includes\modules\gmcl_test.dll':
The specified module could not be found.
[/code]
If you need more info about my Visual Studio setup, let me know.[/QUOTE]
[editline]27th January 2012[/editline]
Thank you very much!
[QUOTE=Howe;18633023]The amount of trouble shooting that accompanies the first steps towards GMod module writing is in no way justified by the result, but nonetheless I have to get this working.
I compile this and save it as gmcl_test.dll and require("test") in game and it works:
[code]
#include <lua.hpp>
#include <windows.h>
#define NO_SDK
#include "GMLuaModule.h"
GMOD_MODULE(Init,Shutdown)
int Init(lua_State *L)
{
return 0;
}
int Shutdown(lua_State *L)
{
return 0;
}
[/code]
works fine, but this simple progression:
[code]
#include <lua.hpp>
#include <windows.h>
#define NO_SDK
#include "GMLuaModule.h"
GMOD_MODULE(Init,Shutdown)
int Init(lua_State *L)
{
lua_getfield(L, LUA_GLOBALSINDEX, "Msg");
lua_pushstring(L, "Loaded\n");
lua_call(L, 1, 0);
return 0;
}
int Shutdown(lua_State *L)
{
lua_getfield(L, LUA_GLOBALSINDEX, "Msg");
lua_pushstring(L, "Unloaded\n");
lua_call(L, 1, 0);
return 0;
}
[/code]
results in this error when I require() it in game:
[code]
error loading module 'test' from file 'c:\program files (x86)\steam\steamapps\****\garrysmod\garrysmod\lua\includes\modules\gmcl_test.dll':
The specified module could not be found.
[/code]
If you need more info about my Visual Studio setup, let me know.[/QUOTE]
[editline]27th January 2012[/editline]
Thank you! But could you tell me where can I get all of the header files used in programming?!
[QUOTE=Dr Magnusson;18637430]You should really use the ILuaInterface that comes with modules, in which case your code would look like this:
[cpp]
#include <windows.h>
#define NO_SDK
#include "GMLuaModule.h"
GMOD_MODULE(Init,Shutdown)
int Init(lua_State *L)
{
Msg( "Loaded\n" );
return 0;
}
int Shutdown(lua_State *L)
{
Msg( "Unloaded\n");
return 0;
}[/cpp]
If you want to go the hard way about printing you should also do that via the ILuaInterface.[/QUOTE]
Sorry, you need to Log In to post a reply to this thread.