1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

* added missing files

* fixed displaying objects
* fixed memory leak
This commit is contained in:
Michał W. Urbańczyk 2007-10-28 11:34:33 +00:00
parent cc01243da5
commit 32baadfbfa
3 changed files with 113 additions and 5 deletions

72
CLua.cpp Normal file
View File

@ -0,0 +1,72 @@
#include "stdafx.h"
#include "CLua.h"
#include "CLuaHandler.h"
#include "lualib.h"
#include "lauxlib.h"
CObjectScript::CObjectScript()
{
//std::cout << "Tworze obiekt objectscript "<<this<<std::endl;
}
CObjectScript::~CObjectScript()
{
//std::cout << "Usuwam obiekt objectscript "<<this<<std::endl;
}
CScript::CScript()
{
//std::cout << "Tworze obiekt CScript "<<this<<std::endl;
}
CScript::~CScript()
{
//std::cout << "Usuwam obiekt CScript "<<this<<std::endl;
}
#define LST (is)
CLua::CLua(std::string initpath)
{
opened=false;
LST = lua_open();
opened = true;
LUA_OPEN_LIB(LST, luaopen_base);
LUA_OPEN_LIB(LST, luaopen_io);
if ((luaL_loadfile (LST, "test.lua")) == 0)
{
//lua_pcall (LST, 0, LUA_MULTRET, 0);
}
else
{
std::string temp = "Cannot open script";
temp += initpath;
throw std::exception(temp.c_str());
}
}
CLua::CLua()
{
//std::cout << "Tworze obiekt clua "<<this<<std::endl;
opened=false;
}
void CLua::registerCLuaCallback()
{
}
CLua::~CLua()
{
//std::cout << "Usuwam obiekt clua "<<this<<std::endl;
if (opened)
{
std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
lua_close(LST);
}
}
#undef LST
CLuaObjectScript::CLuaObjectScript()
{
//std::cout << "Tworze obiekt CLuaObjectScript "<<this<<std::endl;
}
CLuaObjectScript::~CLuaObjectScript()
{
//std::cout << "Usuwam obiekt CLuaObjectScript "<<this<<std::endl;
}

36
CLua.h Normal file
View File

@ -0,0 +1,36 @@
#include "global.h"
#include "lstate.h"
class CLua;
class CObjectScript
{
public:
int owner;
int getOwner(){return owner;} //255 - neutral / 254 - not flaggable
CObjectScript();
virtual ~CObjectScript();
};
class CScript
{
public:
CScript();
virtual ~CScript();
};
class CLua :public CScript
{
lua_State * is; /// tez niebezpieczne!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ale chwilowo okielznane)
bool opened;
public:
CLua(std::string initpath);
void registerCLuaCallback();
CLua();
virtual ~CLua();
};
class CLuaObjectScript : public CLua, public CObjectScript
{
public:
CLuaObjectScript();
virtual ~CLuaObjectScript();
};

View File

@ -99,13 +99,13 @@ bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const //screen p
return true;
if(this->pos.y>cmp.pos.y)
return false;
if(defInfo->isOnDefList && !(defInfo->isOnDefList))
if(defInfo->isOnDefList && !(cmp.defInfo->isOnDefList))
return true;
if(defInfo->isOnDefList && !(defInfo->isOnDefList))
if(cmp.defInfo->isOnDefList && !(defInfo->isOnDefList))
return false;
if(!defInfo->isVisitable() && defInfo->isVisitable())
if(!defInfo->isVisitable() && cmp.defInfo->isVisitable())
return true;
if(!defInfo->isVisitable() && defInfo->isVisitable())
if(!cmp.defInfo->isVisitable() && defInfo->isVisitable())
return false;
if(this->pos.x<cmp.pos.x)
return true;
@ -258,7 +258,7 @@ CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right)
defInfo = right.defInfo;
info = right.info;
defObjInfoNumber = right.defObjInfoNumber;
state = new CLuaObjectScript();
//state = new CLuaObjectScript();
*state = *right.state;
return *this;
}