C++ Help

Hi,
So recently I’ve been wanting to learn C++ for gmod, I finally got visual studio to compile my dll, but when I try to add lua functions, I get this.



1>  main.cpp
1>main.cpp(24): error C2065: 'LUA' : undeclared identifier
1>main.cpp(24): error C2227: left of '->CreateTable' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>main.cpp(26): error C2065: 'LUA' : undeclared identifier
1>main.cpp(26): error C2227: left of '->PushCFunction' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>main.cpp(26): error C2065: 'gcDeleteWrapper' : undeclared identifier
1>main.cpp(27): error C2065: 'LUA' : undeclared identifier
1>main.cpp(27): error C2227: left of '->SetField' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>main.cpp(29): error C2065: 'LUA' : undeclared identifier
1>main.cpp(29): error C2227: left of '->PushCFunction' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>main.cpp(29): error C2065: 'toStringWrapper' : undeclared identifier
1>main.cpp(30): error C2065: 'LUA' : undeclared identifier
1>main.cpp(30): error C2227: left of '->SetField' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>main.cpp(32): error C2065: 'LUA' : undeclared identifier
1>main.cpp(32): error C2227: left of '->PushCFunction' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>main.cpp(32): error C2065: 'indexWrapper' : undeclared identifier
1>main.cpp(33): error C2065: 'LUA' : undeclared identifier
1>main.cpp(33): error C2227: left of '->SetField' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>main.cpp(35): error C2065: 'LUA' : undeclared identifier
1>main.cpp(35): error C2227: left of '->PushCFunction' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>main.cpp(35): error C2065: 'newIndexWrapper' : undeclared identifier
1>main.cpp(36): error C2065: 'LUA' : undeclared identifier
1>main.cpp(36): error C2227: left of '->SetField' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>main.cpp(38): error C2065: 'metatable' : undeclared identifier
1>main.cpp(38): error C2065: 'LUA' : undeclared identifier
1>main.cpp(38): error C2227: left of '->ReferenceCreate' must point to class/struct/union/generic type
1>          type is ''unknown-type''
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


How do I declare the LUA identifier, this is my code



#include "Interface.h"
#include <stdio.h>

using namespace GarrysMod::Lua;



int GMOD_MODULE_OPEN()
{
	LUA->CreateTable();

    LUA->PushCFunction( gcDeleteWrapper );
    LUA->SetField( -2, "__gc" );

    LUA->PushCFunction( toStringWrapper );
    LUA->SetField( -2, "__tostring" );

    LUA->PushCFunction( indexWrapper );
    LUA->SetField( -2, "__index" );

    LUA->PushCFunction( newIndexWrapper );
    LUA->SetField( -2, "__newindex" );

metatable = LUA->ReferenceCreate();
}

int GMOD_MODULE_CLOSE()
{
	return 0;
}


thx,
wise

It’s not in the example, but you need:



#define GMMODULE


Somewhere (before LUA and some other things are being used). This line is why it’s needed.

Still did not work, is it my setup? The tutorial doesn’t use the LUA headers, it just shows you how to set visual studio up

Do you have the LUA interface headers provided by Garry here? If so are they included in your project properties?

Also we can’t help you without seeing errors. So paste the last builds log (after defining GMMODULE at the top).

So, I found this on Blue Kirby’s tut post link thread (if this makes sence) and I found out that sometimes you have to add GMMODULE to preprocessor definitions, so I did that and It worked!

You don’t need “int” before your usage of the GMOD_MODULE_OPEN and GMOD_MODULE_CLOSE macros.