Creating a Garry's Mod Module

How would one I go about doing this? The example is not working for me, and I’m not really sure why. I get a ton of errors thrown and I have nowhere to turn to, as I have found no real documentation that is current and easy to understand for someone just starting out with this. I’m able to make an .exe interact with Lua, but getting a .dll to work with Garry’s Mod is a bit frustrating. There are no errors regarding GarrysMod/Lua/Interface.h

Most of the errors are just from LUA being undefined.

Can someone lend me a hand to just get the example working?

How could you miss this thread?

[editline]15th October 2013[/editline]

Before you start you should learn c++ first.

You need to define GMMODULE either at the top of your code or in the property pages:

Thanks for that guys - very helpful. I suppose I’ve made progress, and I’ve followed that tutorial, yet still receive errors.

I have followed the tutorial twice so far and the same errors are present.

EDIT: Nevermind. Followed what MakeR posted and that seemed to fix it. I didn’t realize that your post was adding onto Robotboy’s. Thank you guys, it means a lot. Feels good to finally see this

I put

#define GMMODULE


#include <Interface.h>

Here’s what I did to create a global table called ‘example’ and a function within called ‘Hello’:

#define GMMODULE

#include "GarrysMod/Lua/Interface.h"

using namespace GarrysMod::Lua;

int SayHello( lua_State * state ) {
	LUA->PushSpecial( SPECIAL_GLOB );
		LUA->GetField( -1, "print" );
		LUA->PushString( "Hello world!" );
		LUA->Call( 1, 0 );
	return 0;

	LUA->PushSpecial( SPECIAL_GLOB );
			LUA->PushCFunction( SayHello );
			LUA->SetField( -2, "Hello" );
		LUA->SetField( -2, "example" );
	return 0;

	return 0;

(The extra brackets are just b/c I like to organize that way, and are not required.)

How is the module to be called in the latest gmod environment? I created the following in my common\Garrysmod\garrysmod\addons\ folder:

example\lua	estbridge.lua

and in testbridge.lua:

require( "example" );

MsgN( TestFunction() );

MsgN( TestFunction( 24.75 ) );

This is built off example from the example:

but when I call

lua_openscript testbridge.lua

from console I get:

] lua_openscript testbridge.lua
Running script testbridge.lua...
Couldn't include file 'includes\modules\example.lua' (File not found) (@addons/gduino/lua/testbridge.lua (line 1))

[ERROR] addons/gduino/lua/testbridge.lua:1: Module not found!
  1. require - [C]:-1
   2. unknown - addons/gduino/lua/testbridge.lua:1


Couldn’t include file ‘includes\modules\example.lua’ (File not found) (@addons/gduino/lua/testbridge.lua (line 1))

Couldn’t include file ‘includes\modules\example.lua’ (File not found)

you should google some things before posting

edit: im kind of in a good mood so here, instead of putting it in addons/gudino/whateveryohuhave it as put it in lua/bin/ instead of in your addons folder

again you should google some times

thanks for the link:

found with search string “Couldn’t include file ‘includes\modules\example.lua’ dll”

Why so much hostility towards people trying to learn?

you don’t get a free pass to be lazy and not look at the other threads just because you’re new

You have both made threads looking for information readily available

If you’re trying to argue against Bletotum and Robotboy, both two of the most incredibly helpful members in the GLua community; you really need to reconsider what you’re doing.

I am saying this passive aggressiveness towards people trying to learn is both idiotic and hypocritical. I could care less how helpful they are in your opinion to the GLua community; Just because you can script in Lua doesn’t mean you need to be an arrogant asshat

I don’t think you know what arrogant means.

As stated, the problem isn’t him trying to learn, but missing a thread that at the time was on the front page. You’re turning this into something it isn’t.

Big deal? The front page has a lot of threads. It’s easy to miss one.