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

This topic is 622 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 :(

Edited by BiiXteR

##### Share on other sites

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?

##### Share on other sites

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

##### Share on other sites

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.

Edited by BiiXteR

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites
Smells like circular inclusion.

##### Share on other sites
What is the content of LuaBridge.h?

##### Share on other sites

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" ?

##### Share on other sites
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>


1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 12
• 15
• 9
• 14
• 10
• ### Forum Statistics

• Total Topics
632655
• Total Posts
3007675
• ### Who's Online (See full list)

There are no registered users currently online

×