I include a .h and my project expodes with errors :(

Started by
10 comments, last by alvaro 12 years ago
The project I am working on is a little bit to big to upload.. So I will link the only parts I can immagine are causing the issue.

I have a class called LuaInstance... I have been using it for quiet a while, when ever I get a new thing I wish to add to it (so lua can interact with it)
here's the header:

#ifndef LUAINSTANCE_H
#define LUAINSTANCE_H
#include <map>
#include <iostream>
#include <cstring>
#include <lua.hpp>
#include <luabind/luabind.hpp>
#include "../ComponentFactory/ComponentCompiler.h"
#include "../Component/DrawComponent.h"
#include "../../ManiacsMayhem entity testing/entManager.h"
/** \class LuaInstance
* \brief holds several instances of lua_State and grants access to them, using namespaces would have probably been a better
* solution, but there is insufficient information on how they work for me to be confident to use them properly
* @author Michael Crook
* @date 6/4/2012
*/
class LuaInstance
{
public:
// variables
enum instID {
construction = 0,
keyboard = 1,
draw = 2,
character = 3
}; /**< instID enum, this is used to make calling of an instance more readable.. that way when you call an instance, other people reading your code will understand which instance it is */
// functions
/**
* default constructor... creates lua instances and places them into states.
* if you want another luaState you have to add it in here! also don't forget to modify the instID enum
*/
LuaInstance();
~LuaInstance();
/**
* LuaInstance is a singleton, this call will allow you to access LuaInstance
* @return the lua instnace
*/
static LuaInstance *getInstance();
/**
* returns the luaState specified in instEnum
* @param instID instEnum, is used to access the coresponding lua state
* @return a pointer to a lua state
*/
lua_State *getLuaState(instID instEnum) const;
/**
* returns a pointer to an array of strings containing all of the errors thrown during lua execution for given lua state
* this will clear the lua stack, so if you just want to clear the stack don't catch the string it returns
* @param instID inst, the instance ID that you wish to get the stack for
* @return std::string ** a pointer to a string array, "/0" = no more elements
*/
std::string *stackDump(instID inst);
//int compileLua(std::string luaStream, instID instEnum);
/**
* given a number of arguments, if it returns anything AND the lua instance enum this will execute the function
* that has been pushed onto the lua stack (to do so, use pushLuaFunc to push the function, then a pushInt if the function needs it)
* @param int NumArgs (the number of arguments sent to the function), bool hasRet(if the funtion expects a return/you need one), instID instEnum(the instance which has the scope you need to forfill your task)
* @return void *, needs to be cast into the data that you were expecting from the function
*/
void *doLua(int NumArgs, bool hasRet, instID instEnum);
/**
* pushes an int onto the given lua_instance stack
* @param instID instEnum(the instance ID that you wish to use), int data(the data you want added to the stack)
*/
void pushInt(instID instEnum, int data);
///////////////////////////void pushString(instID instEnum, std::string data); /////////////// currently fixing, DO NOT IMPLIMENT
/**
* given an instance and a function name will add it to the given lua instance, if it fails, it will return false
* @param instID instEnum(the instance ID that you wish to use), std::string funcName(the function you wish to pop onto the stack so it can be called)
* @return what does it return
* @todo things that need to be added/moded to function
*/
bool pushLuaFunc(instID instEnum, std::string funcName);
/**
* there really is no need for this instance, luaL_dostring will do the same
* it is included as it uses the instance enum which makes everything so much more clean
* also, the name, do n load makes more sense, so that when people are using the functions
* they will understand that it means that the file is both compiled and done.
* #NOTE# if lua is wrapped in function....end it will not be executed, BUT, the function will
* be added to globals and will be pushable onto the lua stack using pushLuaFunc, if it isn't in a chunk, it will be executed #/NOTE#
* @param instID instEnum, the enumarator for the required lua instance std::string luaString,
* the string which contains the lua file
* @return 0 = success, 1 = fail
*/
int do_n_LoadLua(instID instEnum, std::string luaString);
//void bindObject(instID instEnum, const char *luaVarName, void *object); glitched, impliment later
private:
// variables
std::map<instID, lua_State*> states; /**< holds a pointer to all of the avaiable lua instances */
static LuaInstance *singleton; /**< a pointer to the single instance of LuaInstance */
// functions
//const char* istream_ChunkReader( lua_State *L, void *data, size_t *size );
};
#endif
/*
doxy comments:
functions:
/**
* information on calss
* more lines
* EVEN MORE LINES!
* @param paramaters and what they need to be
* @return what does it return
* @todo things that need to be added/moded to function
*/
// int someFunction();

/*
variables
bool someVar /**< insert variable description here */


When I remove #include "../../ManiacsMayhem entity testing/entManager.h" all of my errors go away.


and here's the implementation:

#include "LuaInstance.h"

LuaInstance* LuaInstance::singleton = 0;
LuaInstance *LuaInstance::getInstance()
{
if(singleton == 0)
{
singleton = new LuaInstance();
}
return(singleton);
}
int LuaInstance::do_n_LoadLua(instID instEnum, std::string funcName)
{
return(luaL_dostring(getLuaState(instEnum), funcName.c_str()));
}
/*
int LuaInstance::compileLua(std::string luaStream, instID instEnum)
{
return(luaL_loadstring(getLuaState(instEnum), luaStream.c_str()));
}
*/
bool LuaInstance::pushLuaFunc(instID instEnum, std::string funcName)
{
bool retVal = true;
lua_getglobal(getLuaState(instEnum), funcName.c_str());
//uncomment for debugging
//int i = lua_type(getLuaState(instEnum), -1);
if (lua_type(getLuaState(instEnum), -1)!=LUA_TFUNCTION)
{
//std::cout << funcName;
retVal = false;
}
return(retVal);
}
/* being worked on
void LuaInstance::pushString(instID instEnum, std::string data)
{
lua_pushstring(getLuaState(instEnum), data.c_str());
// uncomment for debugging
//int i = lua_type(getLuaState(instEnum), -1);
//
}
*/
void LuaInstance::pushInt(instID instEnum, int data)
{
lua_pushnumber(getLuaState(instEnum), data);
///* uncomment for debugging
//int i = lua_type(getLuaState(instEnum), -1);
//*/
}
/*
void LuaInstance::bindObject(instID instEnum, const char *luaVarName, void *object)
{
luabind::globals(getLuaState(instEnum))[luaVarName] = object;
}
*/
void *LuaInstance::doLua(int NumArgs, bool hasRet, instID instEnum)
{
int i, luaData;
int numRet = 0;
int pcallResult;
void *returnVal = NULL;
std::string debugging; // on creation of user UI, at the end of doLua, this will be sent to the error handler, if "" is sent, no errors, if string exists, there's errors
//std::string *debugging2;
//temporary returnTypes
bool b_tmpRet;
int i_tmpRet;
const char * s_tmpRet;
lua_State * ls_tmpRet;
size_t *strSize;
strSize = new size_t();
//NumArgs++; // number of arguments I inteperate as number of objects passed, +1 is for the function that it passes
lua_State *L = getLuaState(instEnum);
if(hasRet)
{
numRet = 1;
}
/*
int a, b, c, d;
a = lua_type(getLuaState(instEnum), 1);
b = lua_type(getLuaState(instEnum), 2);
c = lua_type(getLuaState(instEnum), 3);
d = lua_type(getLuaState(instEnum), 4);
*/
pcallResult = lua_pcall(L, NumArgs, numRet, 0);
/*
int a, b, c, d, e, f, g;
a = lua_type(getLuaState(instEnum), 1);
b = lua_type(getLuaState(instEnum), 2);
c = lua_type(getLuaState(instEnum), 3);
d = lua_type(getLuaState(instEnum), 0);
e = lua_type(getLuaState(instEnum), -1);
f = lua_type(getLuaState(instEnum), -2);
g = lua_type(getLuaState(instEnum), -3);

int aa, bb, cc;
aa = lua_tointeger(getLuaState(instEnum), 1);
bb = lua_tointeger(getLuaState(instEnum), 0);
cc = lua_tointeger(getLuaState(instEnum), 1);
*/
if(hasRet) // if the function is expecting data to be returned
{
luaData = lua_type(getLuaState(instEnum), -1);
if(pcallResult != 0)
{
luaData = 9; // this indicates syntax error in function
}
switch(luaData) // switching the diferent possible return types to be placed inside of
{
case LUA_TNIL:
debugging.append("error running function: ");
debugging.append("no data returned");
break; // nill returned
case LUA_TBOOLEAN:
b_tmpRet = lua_toboolean(getLuaState(instEnum), -1);
memcpy(&returnVal, &b_tmpRet, sizeof b_tmpRet);
break;
case LUA_TLIGHTUSERDATA:
debugging.append("error running function: ");
debugging.append("returning bound objects is currently not supported");
//returnVal = lua_touserdata(L, -1);
case LUA_TNUMBER:
i_tmpRet = lua_tointeger(getLuaState(instEnum), -1);
memcpy(&returnVal, &i_tmpRet, sizeof i_tmpRet);
break;
case LUA_TSTRING:
s_tmpRet = lua_tolstring(getLuaState(instEnum), -1, strSize);
memcpy(&returnVal, &s_tmpRet, *strSize);
break;
case LUA_TTABLE:
debugging.append("error running function: ");
debugging.append("tables not supported");
break;
case LUA_TFUNCTION:
debugging.append("error running function: ");
debugging.append("returning functions not supported");
break;
case LUA_TUSERDATA:
debugging.append("error running function: ");
debugging.append("returning bound objects is currently not supported");
//returnVal = lua_touserdata(L, -1);
break;
case LUA_TTHREAD:
ls_tmpRet = lua_tothread(getLuaState(instEnum), -1);
memcpy(&returnVal, &ls_tmpRet, sizeof ls_tmpRet);
break;
case 9:
debugging.append("error running function: ");
debugging.append(lua_tostring(L, -1));
break;
default:
debugging.append("error running function: ");
debugging.append("return of unknown datatype");
break;
}
lua_pop(L, 1); // pop returned value
}
else
{
if(pcallResult != 0)
{
debugging.append("error running function: ");
debugging.append(lua_tostring(L, -1));
}
}
return(returnVal);
}
LuaInstance::LuaInstance()
{
states.insert(std::make_pair(construction, lua_open()));
states.insert(std::make_pair(keyboard, lua_open()));
states.insert(std::make_pair(draw, lua_open()));
states.insert(std::make_pair(character, lua_open()));
// setting up the compiler to be usable in lua
std::map<instID, lua_State*>::iterator iter;
// opens all lua instances
for(iter = states.begin(); iter != states.end(); ++iter)
{
luaL_openlibs(iter->second);
luabind::open(iter->second);
lua_pcall(iter->second, 0, 0, 0); // initiates pcall
}
//CompCompiler::setupLuaBinds(getLuaState(construction));
//keyBinds::setupLuaBinds(getLuaState(keyboard));
ComponentCompiler::setupLuaBinds(getLuaState(construction));
DrawComponent::setupLuaBinds(getLuaState(draw));
CharacterComponent::setupLuaBinds(getLuaState(character));
}
LuaInstance::~LuaInstance()
{
std::map<instID, lua_State*>::iterator iter;
// closes all lua instances
for(iter = states.begin(); iter != states.end(); ++iter)
{
lua_close(iter->second);
}
}
lua_State *LuaInstance::getLuaState(instID instEnum) const
{
return(states.find(instEnum)->second);
}
std::string *LuaInstance::stackDump(instID inst)
{
lua_State *L = getLuaState(inst);
int top = lua_gettop(L);
if(top == 0)
{
return(NULL);
}
//std::string* stkDmp;
std::string* retVal;
//stkDmp = new std::string[top];
retVal = new std::string[top+1];
int i = 0;

while(lua_gettop(L) != 0) // every time you call lua_remove, it shuffles all of the stack down, thus, eventually the stack will equal 0, thus stack cleared
{
if(lua_isstring(L, 1))
{
retVal = (std::string)lua_tostring(L, 1); // pushes stack element by element onto stkDmp**
}

lua_remove(L, 1); //
i++;
}
retVal[top] = "/0";
return(retVal);
}



here's the header for entManager.h

#pragma once
#include <map>
#include "../src/Tools/LuaInstance.h"
#include "../src/Entity/Entity.h"
// this is a demo class, therefore it isn't following the design patern we have
class entManager
{
public:
entManager(void);
~entManager(void);
//entity stuff
/**
* this will create an entity, if it fails it will return 0, else 1 (so luabind can use)
* @param std::string entityIcz link to the entity file
* @return entity ID (or -1 if failed)
*/
int makeEntity(std::string entityIcz, int entID);
/**
* this will kill the given entity (killing all of it's components)
* @param int entID the entity to kill
* @return will return false if entity does not exist
*/
bool killEntity(int entID);
static void setupLuaBinds(lua_State *L);
private:
std::map<int, Entity*> m_entitys;

};


and implementation:

#include "entManager.h"

entManager::entManager(void)
{
}

entManager::~entManager(void)
{
}
int entManager::makeEntity(std::string entityIcz, int entID)
{
int retVal = 1;
Entity *tmpEnt;
tmpEnt = new Entity(entityIcz, entID); //std::make_pair
if(tmpEnt->getEntId() == -1)
{
//failed
retVal = 0;
}
else
{
m_entitys.insert(std::make_pair(entID, tmpEnt));
}
return(retVal);
}
bool entManager::killEntity(int entID)
{
return(m_entitys.erase(entID)); // this will call the entity's deconstructor which will in return call set
} // all of the components to be deleted on next itteration.
void entManager::setupLuaBinds(lua_State *L)
{
luabind::module(L)
[
luabind::class_<entManager>("entManager")
.def(luabind::constructor<>())
.def("entManager", &entManager::makeEntity)
];
}



although the errors that are produced during compilation are mostly imo bogus (i.e. somthing is causing a big stuff up, which in return is causing working code to apear as if it isn't) here it is:

1>------ Build started: Project: maniacsMayhem, Configuration: Debug Win32 ------
1>Build started 16/04/2012 1:19:42 AM.
1>InitializeBuildStatus:
1> Creating "Debug\maniacsMayhem.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> CharacterCF.cpp
1>g:\crsm-svn\backbone demo\usin myshit\src\renderer\light.h(38): warning C4018: '<' : signed/unsigned mismatch
1> Generating Code...
1> Compiling...
1> entManager.cpp
1>g:\crsm-svn\backbone demo\usin myshit\src\renderer\light.h(38): warning C4018: '<' : signed/unsigned mismatch
1>g:\crsm-svn\backbone demo\usin myshit\maniacsmayhem entity testing\entmanager.cpp(32): warning C4800: 'unsigned int' : forcing value to bool 'true' or 'false' (performance warning)
1> LuaInstance.cpp
1>g:\crsm-svn\backbone demo\usin myshit\src\renderer\light.h(38): warning C4018: '<' : signed/unsigned mismatch
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.cpp(131): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.cpp(67): warning C4101: 'i' : unreferenced local variable
1> entTest.cpp
1>g:\crsm-svn\backbone demo\usin myshit\src\renderer\light.h(38): warning C4018: '<' : signed/unsigned mismatch
1>g:\crsm-svn\backbone demo\usin myshit\maniacsmayhem entity testing\entmanager.h(30): error C2065: 'Entity' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\maniacsmayhem entity testing\entmanager.h(30): error C2059: syntax error : '>'
1>g:\crsm-svn\backbone demo\usin myshit\maniacsmayhem entity testing\entmanager.h(33): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(20): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(23): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(25): error C2065: 'keyboard' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(26): error C2065: 'draw' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(27): error C2065: 'character' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(28): error C2143: syntax error : missing ',' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(28): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(66): error C2065: 'instID' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(100): error C2065: 'instID' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(104): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.h(25): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.h(63): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.h(71): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\testing\enttest.cpp(3): error C2146: syntax error : missing ',' before identifier 'argv'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\testing\enttest.cpp(3): error C2065: 'argv' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\testing\enttest.cpp(3): error C2059: syntax error : ']'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\testing\enttest.cpp(4): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\testing\enttest.cpp(7): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\testing\enttest.cpp(8): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\testing\enttest.cpp(8): fatal error C1004: unexpected end-of-file found
1> Entity.cpp
1>g:\crsm-svn\backbone demo\usin myshit\src\renderer\light.h(38): warning C4018: '<' : signed/unsigned mismatch
1>g:\crsm-svn\backbone demo\usin myshit\maniacsmayhem entity testing\entmanager.h(30): error C2065: 'Entity' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\maniacsmayhem entity testing\entmanager.h(30): error C2059: syntax error : '>'
1>g:\crsm-svn\backbone demo\usin myshit\maniacsmayhem entity testing\entmanager.h(33): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(20): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(23): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(25): error C2065: 'keyboard' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(26): error C2065: 'draw' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(27): error C2065: 'character' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(28): error C2143: syntax error : missing ',' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(28): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(66): error C2065: 'instID' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(100): error C2065: 'instID' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(104): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.h(25): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.h(63): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.h(71): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(3): error C2653: 'Entity' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(4): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(14): error C2653: 'LuaInstance' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(14): error C2653: 'LuaInstance' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(25): error C2065: 'buffer' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(25): error C2065: 'fileSize' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(25): error C2143: syntax error : missing ',' before ')'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(27): error C2653: 'LuaInstance' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(27): error C2653: 'LuaInstance' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(27): error C2065: 'buffer' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(28): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(30): error C2653: 'LuaInstance' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(30): error C2653: 'LuaInstance' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(32): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(39): error C2653: 'LuaInstance' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(39): error C2653: 'LuaInstance' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(40): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(43): error C2653: 'Entity' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(44): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(46): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(48): error C2653: 'Entity' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(49): error C2143: syntax error : missing ';' before '{'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(50): error C2065: 'entId' : undeclared identifier
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(51): error C2143: syntax error : missing ';' before '}'
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(53): error C2653: 'Entity' : is not a class or namespace name
1>g:\crsm-svn\backbone demo\usin myshit\src\entity\entity.cpp(53): fatal error C1903: unable to recover from previous error(s); stopping compilation
1> DrawCF.cpp
1>g:\crsm-svn\backbone demo\usin myshit\src\renderer\light.h(38): warning C4018: '<' : signed/unsigned mismatch
1> ComponentCompiler.cpp
1>g:\crsm-svn\backbone demo\usin myshit\src\renderer\light.h(38): warning C4018: '<' : signed/unsigned mismatch
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:20.21
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



luainstance, entity were bug free till now, and through looking through the errors, for instance

1>g:\crsm-svn\backbone demo\usin myshit\src\tools\luainstance.h(20): error C2143: syntax error : missing ';' before '{'


which is referring to this:


class LuaInstance
{ // <------- this is what it is refering to
public:


I believe that the including of the header is in some way doing somthing I shouldn't without me knowing (ive already gone through all of my headers an made sure I have used

#ifndef
#define
#endif

or equivalent.

What I suspect might be the problem is that entManager is including some file, then another file is reclairing it, causing some sort of mumbo jumbo..

I just can't figure out why

note:
during creation of this monster post I found out that if I include entManager in any headder it causes the things that attach to that hedder to expload... I am going to further examine my code, hopefully I can find a solution myself, but I am still going to post as this assignment is due soon and I'm kinda lacking time sad.png
Advertisement
ok, here's an update...

if I remove

#include "../src/Entity/Entity.h"

from entManager, the errors go away.

here's the code for Entity:

.h

#ifndef ENTITY_H
#define ENTITY_H
#include <vector>
#include <string.h>
//#include "../Component/Component.h"
#include "../Tools/LuaInstance.h"
#include "../ComponentFactory/ComponentCompiler.h"
#include "../ResourceHandler/IczOpener.h"
/** \class Entity
* \brief Entity holds all components of a game entity, it knows nothing of what they do or how to use them, entity just holds them
* all entities will be in a vector in the game instance, when a entity is deleted, it will call constructor, marking all
* components it holds for removal
* @author Michael Crook
* @date 21/3/2012
* @todo add function which compiles a .efcg file (entity configuration file) this will be done through this ROUGH psducode
* loop(all needed components)
* {
* Component* newComponent;
* ComponentCompiler::make(newComponent, componentID, linkToLuaMakefile);
* }
*/
class Entity
{
public:
// variables

// functions
/**
* returns if the entity is still in use
* @return if t he entity is still "alive" (killme==1 = dead)
*/
//bool entityIsDead(); // returns this.killme
/**
* default constructor
*/
Entity();
/**
* constructor accepts a file containing the data required to build an entity, runs createEntity after running default constructor
* @param entityInfoLuaFile a string argument linking to a entity creation lua file
* @see Entity()
* @see createEntity()
* @return The test results
*/
Entity(std::string ICZLoc, int entId);
/**
* default deconstructor, will call all of it's components kill function, this will make all of the components have their isKilled flagged as true and run the childs kill()
*/
~Entity();
/**
* creates entity, will flush all current entities (mark the component for removal from component controller/free memory during removal from controller)
* after that it will read in the file at 'entityInfoLuaFile' (this will later be changed to a char pointer once physicsFS zip library is installed
* creating the components using their component factory (the CF will set the component up and add to the controller)
* @param entityInfoLuaFile a string argument linking to a entity creation lua file
*/
void createEntity(std::string ICZLoc, int entId);
int getEntId(){return(m_entID);};
private:
// variables
//bool m_killme; /**< if true, the entity has been flagged for removal, all components will destroy them selves if their holding entity is flagged for this */
std::vector<Component*> m_component_holder; /**< holds all of an entities components, they have to be pointers so that once the entity is deleted, its components are removed from the controllers */
int m_entID;
// functions
void clear();
};
#endif



.cpp

#include "Entity.h"
void Entity::createEntity(std::string ICZLoc, int entId)
{
m_entID = entId;
clear(); // will call all of the kill functions of all of the components
m_component_holder = *(new std::vector<Component*>); // lets go of tracking the components in m_component_holder, clear() MUST be called first
char *buffer;
std::string *errStr;
ComponentCompiler *compiler;
compiler = new ComponentCompiler();
lua_State *L = LuaInstance::getInstance()->getLuaState(LuaInstance::construction);
luabind::globals(L)["CC"] = compiler;
IczOpener *zipInstance;
zipInstance = IczOpener::getInstance();
zipInstance->setArchive(ICZLoc);
int fileSize = zipInstance->getFileLength("entLoad.lua");
buffer = new char[fileSize];
zipInstance->getFileStream("entLoad.lua", buffer, fileSize); // lua file is now inside of Entity

if(LuaInstance::getInstance()->do_n_LoadLua(LuaInstance::construction, buffer) != 0)
{
// entity loading failed
errStr = LuaInstance::getInstance()->stackDump(LuaInstance::construction);
entId = -1;
}
//luaL_dostring(L, buffer); // runs the lua file entLoad.lua
zipInstance->deInit(); // unloads zip, allows for data access outside of program, for example, once you load all of the lua you need from an
// icz, you unload it, that way during balancing you can modify the lua, it will then reload/unload with new values
std::string *tmpStr = LuaInstance::getInstance()->stackDump(LuaInstance::construction);
}

Entity::Entity()
{
}
Entity::Entity(std::string ICZLoc, int entId)
{
createEntity(ICZLoc, entId);
}
Entity::~Entity()
{
clear();
}
void Entity::clear()
{
std::vector<Component*>::iterator it;
for (it = m_component_holder.begin(); it != m_component_holder.end(); ++it) // itterates through all Components
{
(*it)->setIsKilled(true); // marks them to be destroyed next controller itteration
}
}


I recently changed it, before this is what it was:

.h

#ifndef ENTITY
#define ENTITY
#include <vector>
#include <string.h>
//#include "../Component/Component.h"
#include "../Tools/LuaInstance.h"
#include "../ComponentFactory/ComponentCompiler.h"
#include "../ResourceHandler/IczOpener.h"
/** \class Entity
* \brief Entity holds all components of a game entity, it knows nothing of what they do or how to use them, entity just holds them
* all entities will be in a vector in the game instance, when a entity is deleted, it will call constructor, marking all
* components it holds for removal
* @author Michael Crook
* @date 21/3/2012
* @todo add function which compiles a .efcg file (entity configuration file) this will be done through this ROUGH psducode
* loop(all needed components)
* {
* Component* newComponent;
* ComponentCompiler::make(newComponent, componentID, linkToLuaMakefile);
* }
*/
class Entity
{
public:
// variables

// functions
/**
* returns if the entity is still in use
* @return if t he entity is still "alive" (killme==1 = dead)
*/
//bool entityIsDead(); // returns this.killme
/**
* default constructor
*/
Entity();
/**
* constructor accepts a file containing the data required to build an entity, runs createEntity after running default constructor
* @param entityInfoLuaFile a string argument linking to a entity creation lua file
* @see Entity()
* @see createEntity()
* @return The test results
*/
Entity(std::string ICZLoc);
/**
* default deconstructor, will call all of it's components kill function, this will make all of the components have their isKilled flagged as true and run the childs kill()
*/
~Entity();
/**
* creates entity, will flush all current entities (mark the component for removal from component controller/free memory during removal from controller)
* after that it will read in the file at 'entityInfoLuaFile' (this will later be changed to a char pointer once physicsFS zip library is installed
* creating the components using their component factory (the CF will set the component up and add to the controller)
* @param entityInfoLuaFile a string argument linking to a entity creation lua file
*/
void createEntity(std::string ICZLoc);
private:
// variables
//bool m_killme; /**< if true, the entity has been flagged for removal, all components will destroy them selves if their holding entity is flagged for this */
std::vector<Component*> m_component_holder; /**< holds all of an entities components, they have to be pointers so that once the entity is deleted, its components are removed from the controllers */
// functions
void clear();
};
#endif



.cpp

#include "Entity.h"
void Entity::createEntity(std::string ICZLoc, int entId)
{
clear(); // will call all of the kill functions of all of the components
m_component_holder = *(new std::vector<Component*>); // lets go of tracking the components in m_component_holder, clear() MUST be called first
char *buffer;
std::string *errStr;
ComponentCompiler *compiler;
compiler = new ComponentCompiler();
lua_State *L = LuaInstance::getInstance()->getLuaState(LuaInstance::construction);
luabind::globals(L)["CC"] = compiler;
IczOpener *zipInstance;
zipInstance = IczOpener::getInstance();
zipInstance->setArchive(ICZLoc);
int fileSize = zipInstance->getFileLength("entLoad.lua");
buffer = new char[fileSize];
zipInstance->getFileStream("entLoad.lua", buffer, fileSize); // lua file is now inside of Entity

if(LuaInstance::getInstance()->do_n_LoadLua(LuaInstance::construction, buffer) != 0)
{
// entity loading failed
errStr = LuaInstance::getInstance()->stackDump(LuaInstance::construction);
}
//luaL_dostring(L, buffer); // runs the lua file entLoad.lua
zipInstance->deInit(); // unloads zip, allows for data access outside of program, for example, once you load all of the lua you need from an
// icz, you unload it, that way during balancing you can modify the lua, it will then reload/unload with new values
std::string *tmpStr = LuaInstance::getInstance()->stackDump(LuaInstance::construction);
}

Entity::Entity()
{
}
Entity::Entity(std::string ICZLoc, int entId)
{
createEntity(ICZLoc, entId);
}
Entity::~Entity()
{
clear();
}
void Entity::clear()
{
std::vector<Component*>::iterator it;
for (it = m_component_holder.begin(); it != m_component_holder.end(); ++it) // itterates through all Components
{
(*it)->setIsKilled(true); // marks them to be destroyed next controller itteration
}
}



Hmmm, I just found out that before I had no headers implimenting entity, only a .cpp


#include "../Entity.h"
int main(int argc, char *argv[])
{
Entity entManager("testUnit.icz");
return(0);
}


which was from a test program... Is there anything inside of Entity.h's header which when placed as an include in another header could cause problems
as a side note... when ever I look at my #includes of parts of the project that I have created, the #include is red... it says the following:
errorjl.png
although during compilation it finds the files without issue... Any idea why? it's been like this for a while and hasn't causesd the program not to compile

edit:
what is odd, is that most files are doing this... but I found about 20% arn't... for example, this file isn't


#ifndef DRAWCF
#define DRAWCF
#include "ComponentFactory.h"
#include "../ResourceHandler/IczOpener.h"
#include "../Component/DrawComponent.h"
#include "../Tools/LuaInstance.h"
#include <iostream>
class DrawCF : public ComponentFactory
{
public:
static ComponentFactory * createComponentFac(int entID);
Component *createComp(std::string linkToLua);
bool linkOtherComponent(int linkToSetup, ComponentFactory *linkedComponentF);
DrawCF(int entID){m_entID = entID;};
private:
DrawComponent* drwCmp;
};

#endif


Although luaInstance does get the not found error...


edit 2:
and when I include

#include "../../ManiacsMayhem entity testing/entManager.h"

in the headers which don't get that weird error, it doesn't cause problems.. Ok.. I might be onto it


edit:

I've had a read through my team mates code... they for some STUPID STUPID reason insist on having half of their #includes in the header, and half in the implementation... I've told them that I don't like this, but because they love making me cry they still do it..

So, in an attempt to fix the problem, I started moving their #includes so that they were all inside of the headers.. I even found that in some places they had #included in the cpp and in the h... which I believe can cause issues... after moving everything into .h I am still getting the problem, but there is a chance I have missed one double up.. I'm going to keep an eye out, but is this the kinda thing that could cause this error?

sorry, for post spam, but every time I make a post, I tell myself I'm getting off, yet I havn't yet :\
Tell your compilers to output the pre-processed source. Look at said output. The chances are the problem might be a little easier to understand if you are looking at the same view as the compiler.

There is too much code to examine in detail, but it sounds like you have a circular reference. The entity header includes LuaInstance, and the LuaInstance indirectly tries to include Entity. You might want to see if you can use forward declarations to break the dependency cycle.

Depending on what is going on, it might be better to actually remove the dependency. A quick skim suggests that the dependency is in the LuaInstance constructor. Instead of setting the bindings in the constructor, try passing the bindings into the constructor. A separate file can link these together, using a "factory" function.

Depending on what is going on, it might be better to actually remove the dependency. A quick skim suggests that the dependency is in the LuaInstance constructor. Instead of setting the bindings in the constructor, try passing the bindings into the constructor. A separate file can link these together, using a "factory" function.


I was actually going to do that, but I was running out of time so I took the lazy approach, boy does it look like that has come back to bite me

I will in the morning, 6 hours before the assignment is due attempt to impliment a function iniside of LuaInstance which will accept a pointer to a function which needs a lua state to bind a class to lua using
typedef void (*classBinder)(lua_instance*)
and hope like billoes that that will accept a function reference which has a void return and needs a lua_instance pointer
I've never looked at precompiled thingamabobs... Anything I should be looking for?

btw, they are here:
I'm not talking about precompiled headers. I'm talking about a compiler switch which causes the compiler to output the pre-processed source to disk. The preprocessor is the part of the c++ compilation process that handles #include, #define etc. The compiler works not on the source, but the output of of the pre-processor.

If circular dependencies are the problem, you'll see something like this:

// Pages and pages of standard headers and library headers

class Foo
{
// ...

// Example of a reference to another class not defined yet
void frobnicate(Bar bar)
{

}
};

// Sometime later

class Bar
{
// ...
};


In fact, looking closer at your original post, it could be as simple as moving the following preprocessor directives from the lua instance header file to the lua instance source file (nothing in the header obviously depends on the detail in these included files):


#include "../ComponentFactory/ComponentCompiler.h"
#include "../Component/DrawComponent.h"
#include "../../ManiacsMayhem entity testing/entManager.h"
Yes, it's a circular dependency. LuaInstance.h includes entManager.h, which includes Entity.h, which includes LuaInstance.h. If you are compiling a module that includes entManager.h or Entity.h, by the time LuaInstance.h is compiled, the compiler hasn't seen the definition of Entity, so it doesn't know what to do with it.

You should probably figure out which of these modules are lower level than which other modules, and make the higher-level modules include the lower-level ones, and not the other way around. If you have a legitimate reason why module A and module B should include each other, use forward declarations to break the circle of dependencies.

I'm not talking about precompiled headers. I'm talking about a compiler switch which causes the compiler to output the pre-processed source to disk. The preprocessor is the part of the c++ compilation process that handles #include, #define etc. The compiler works not on the source, but the output of of the pre-processor.

If circular dependencies are the problem, you'll see something like this:

// Pages and pages of standard headers and library headers

class Foo
{
// ...

// Example of a reference to another class not defined yet
void frobnicate(Bar bar)
{

}
};

// Sometime later

class Bar
{
// ...
};


In fact, looking closer at your original post, it could be as simple as moving the following preprocessor directives from the lua instance header file to the lua instance source file (nothing in the header obviously depends on the detail in these included files):


#include "../ComponentFactory/ComponentCompiler.h"
#include "../Component/DrawComponent.h"
#include "../../ManiacsMayhem entity testing/entManager.h"



I think I will attempt to create a function which will allow users to add their classes without needing to be known of inside of luaInstance, It was what I wanted to do originally, I was just trying to save time
Maybe it's just me, but I would really get into the habit of NOT using #include in header files except when you really need them. Using forward declarations wherever possible means not ending up with including includes that include includes that end up with every single source file including almost every header in your entire project.

If your class is only showing up as a pointer or reference in some other header, do NOT include the entire class header and just forward declare. After a while it will be as natural as not putting 'using namespace' in header files and just type out the entire names.
f@dzhttp://festini.device-zero.de

This topic is closed to new replies.

Advertisement