"identifier lua_State is undefined" even if I include the Lua source files?

Started by
11 comments, last by BiiXteR 7 years, 3 months ago

I'm trying to use the Lua source code in my application but C++ won't let me.

I have this piece of code, on line 21 it tells me that lua_State is undefined, and as far as I know I haven't missed including any files?


#pragma once

#include <External\LuaBridge\LuaBridge.h>

extern "C" {
#include <External/Lua/lua.h>
#include <External/Lua/lualib.h>
#include <External/Lua/lauxlib.h>
}

class LuaManager
{

public:

	LuaManager();
	~LuaManager();
	
private:

	lua_State* L; // Error here.

};

Have no idea what I'm doing wrong :(

Advertisement

So, is that identifier in the included files? (maybe it's "lua_state" or "Lua_state" or so).

Also, do you get an error during compiling or during linking? In the latter case, did you supply a library to link against?

It should work. That struct is defined and typedefed in lua_State. Are your .h files okay?

So, is that identifier in the included files? (maybe it's "lua_state" or "Lua_state" or so).

Also, do you get an error during compiling or during linking? In the latter case, did you supply a library to link against?

I did not supply a library to link since I'm just using the source of Lua.

And I checked both versions, none of them work.

In the build output I get these errors at the same line :


1>c:\users\alex\desktop\untitledcppgame\untitledcppgame\luamanager.h(21): error C2143: syntax error: missing ';' before '*'
1>c:\users\alex\desktop\untitledcppgame\untitledcppgame\luamanager.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\alex\desktop\untitledcppgame\untitledcppgame\luamanager.h(21): error C2238: unexpected token(s) preceding ';'

And lua_State should be in there somewhere.

It should work. That struct is defined and typedefed in lua_State. Are your .h files okay?

Unsure what you mean, if you mean the Lua source files, I have replaced them several times just in case I might have deleted something or modified them by mistake.

Now I'm even more confused...

I randomly played around with the code hoping to find a solution somehow, and removed the line which includes LuaBridge.h, and after removing it the solution compiles and runs like it should? o.o

How does including LuaBridge.h result in lua_State being "undefined" ?

What.

Oh, that's simple. Include the lua header files in a non-default name space so their definitions do not end up globally available.

As a side effect, they define the #ifndef/#define protection variable which is likely in the lua header files, so if you include them again in the global name space, the protection makes that the content is not defined again.

Note, this is just one way to get that effect, I don't know if that is actually happening here, you'll have to check the luabridge header file for that.

Smells like circular inclusion.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

What is the content of LuaBridge.h?

What is the content of LuaBridge.h?

The source of LuaBridge is here : https://github.com/vinniefalco/LuaBridge

Smells like circular inclusion.

Can't find any circular inclusions, unless here are some in either Lua or LuaBridge which i highly doubt.

Oh, that's simple. Include the lua header files in a non-default name space so their definitions do not end up globally available.

As a side effect, they define the #ifndef/#define protection variable which is likely in the lua header files, so if you include them again in the global name space, the protection makes that the content is not defined again.

Note, this is just one way to get that effect, I don't know if that is actually happening here, you'll have to check the luabridge header file for that.

What do you mean by "including the lua header files in a non-default namespace" ?

Untangling the source of the LuaBridge demos, it looks like the demo code provides the extern "C" {} include block, that includes the Lua headers, BEFORE #including LuaBridge. Try switching your includes like so:


extern "C" {
#include <External/Lua/lua.h>
#include <External/Lua/lualib.h>
#include <External/Lua/lauxlib.h>
}

#include <External\LuaBridge\LuaBridge.h>

This topic is closed to new replies.

Advertisement