some changes to how we use streflop:

- Removed all unneeded includes of cmath
- added proper wrapper classes for lua calls to toggle streflop back and forth
- some code cleanup
This commit is contained in:
Mark Vejvoda
2010-05-28 05:31:17 +00:00
parent f0da609e7f
commit 908b155d62
10 changed files with 119 additions and 151 deletions

View File

@@ -23,6 +23,25 @@ using namespace Shared::Util;
namespace Glest{ namespace Game{ namespace Glest{ namespace Game{
//
// This class wraps streflop for the Lua ScriptMAnager. We need to toggle the data type
// for streflop to use when calling into glest from LUA as streflop may corrupt some
// numeric values passed from Lua otherwise
//
class ScriptManager_STREFLOP_Wrapper {
public:
ScriptManager_STREFLOP_Wrapper() {
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
}
~ScriptManager_STREFLOP_Wrapper() {
#ifdef USE_STREFLOP
streflop_init<streflop::Double>();
#endif
}
};
// ===================================================== // =====================================================
// class PlayerModifiers // class PlayerModifiers
// ===================================================== // =====================================================
@@ -131,6 +150,7 @@ void ScriptManager::onUnitDied(const Unit* unit){
// ========================== lua wrappers =============================================== // ========================== lua wrappers ===============================================
string ScriptManager::wrapString(const string &str, int wrapCount){ string ScriptManager::wrapString(const string &str, int wrapCount){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
string returnString; string returnString;
@@ -151,6 +171,8 @@ string ScriptManager::wrapString(const string &str, int wrapCount){
} }
void ScriptManager::showMessage(const string &text, const string &header){ void ScriptManager::showMessage(const string &text, const string &header){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
Lang &lang= Lang::getInstance(); Lang &lang= Lang::getInstance();
messageQueue.push(ScriptManagerMessage(text, header)); messageQueue.push(ScriptManagerMessage(text, header));
@@ -164,88 +186,108 @@ void ScriptManager::clearDisplayText(){
} }
void ScriptManager::setDisplayText(const string &text){ void ScriptManager::setDisplayText(const string &text){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
displayText= wrapString(Lang::getInstance().getScenarioString(text), displayTextWrapCount); displayText= wrapString(Lang::getInstance().getScenarioString(text), displayTextWrapCount);
} }
void ScriptManager::setCameraPosition(const Vec2i &pos){ void ScriptManager::setCameraPosition(const Vec2i &pos){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
gameCamera->centerXZ(pos.x, pos.y); gameCamera->centerXZ(pos.x, pos.y);
} }
void ScriptManager::createUnit(const string &unitName, int factionIndex, Vec2i pos){ void ScriptManager::createUnit(const string &unitName, int factionIndex, Vec2i pos){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,unitName.c_str(),factionIndex); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,unitName.c_str(),factionIndex);
ScriptManager_STREFLOP_Wrapper streflopWrapper;
world->createUnit(unitName, factionIndex, pos); world->createUnit(unitName, factionIndex, pos);
} }
void ScriptManager::giveResource(const string &resourceName, int factionIndex, int amount){ void ScriptManager::giveResource(const string &resourceName, int factionIndex, int amount){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
world->giveResource(resourceName, factionIndex, amount); world->giveResource(resourceName, factionIndex, amount);
} }
void ScriptManager::givePositionCommand(int unitId, const string &commandName, const Vec2i &pos){ void ScriptManager::givePositionCommand(int unitId, const string &commandName, const Vec2i &pos){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
world->givePositionCommand(unitId, commandName, pos); world->givePositionCommand(unitId, commandName, pos);
} }
void ScriptManager::giveProductionCommand(int unitId, const string &producedName){ void ScriptManager::giveProductionCommand(int unitId, const string &producedName){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
world->giveProductionCommand(unitId, producedName); world->giveProductionCommand(unitId, producedName);
} }
void ScriptManager::giveUpgradeCommand(int unitId, const string &producedName){ void ScriptManager::giveUpgradeCommand(int unitId, const string &producedName){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
world->giveUpgradeCommand(unitId, producedName); world->giveUpgradeCommand(unitId, producedName);
} }
void ScriptManager::disableAi(int factionIndex){ void ScriptManager::disableAi(int factionIndex){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
if(factionIndex<GameConstants::maxPlayers){ if(factionIndex<GameConstants::maxPlayers){
playerModifiers[factionIndex].disableAi(); playerModifiers[factionIndex].disableAi();
} }
} }
void ScriptManager::setPlayerAsWinner(int factionIndex){ void ScriptManager::setPlayerAsWinner(int factionIndex){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
if(factionIndex<GameConstants::maxPlayers){ if(factionIndex<GameConstants::maxPlayers){
playerModifiers[factionIndex].setAsWinner(); playerModifiers[factionIndex].setAsWinner();
} }
} }
void ScriptManager::endGame(){ void ScriptManager::endGame(){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
gameOver= true; gameOver= true;
} }
Vec2i ScriptManager::getStartLocation(int factionIndex){ Vec2i ScriptManager::getStartLocation(int factionIndex){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return world->getStartLocation(factionIndex); return world->getStartLocation(factionIndex);
} }
Vec2i ScriptManager::getUnitPosition(int unitId){ Vec2i ScriptManager::getUnitPosition(int unitId){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return world->getUnitPosition(unitId); return world->getUnitPosition(unitId);
} }
int ScriptManager::getUnitFaction(int unitId){ int ScriptManager::getUnitFaction(int unitId){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return world->getUnitFactionIndex(unitId); return world->getUnitFactionIndex(unitId);
} }
int ScriptManager::getResourceAmount(const string &resourceName, int factionIndex){ int ScriptManager::getResourceAmount(const string &resourceName, int factionIndex){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return world->getResourceAmount(resourceName, factionIndex); return world->getResourceAmount(resourceName, factionIndex);
} }
const string &ScriptManager::getLastCreatedUnitName(){ const string &ScriptManager::getLastCreatedUnitName(){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return lastCreatedUnitName; return lastCreatedUnitName;
} }
int ScriptManager::getLastCreatedUnitId(){ int ScriptManager::getLastCreatedUnitId(){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return lastCreatedUnitId; return lastCreatedUnitId;
} }
const string &ScriptManager::getLastDeadUnitName(){ const string &ScriptManager::getLastDeadUnitName(){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return lastDeadUnitName; return lastDeadUnitName;
} }
int ScriptManager::getLastDeadUnitId(){ int ScriptManager::getLastDeadUnitId(){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return lastDeadUnitId; return lastDeadUnitId;
} }
int ScriptManager::getUnitCount(int factionIndex){ int ScriptManager::getUnitCount(int factionIndex){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return world->getUnitCount(factionIndex); return world->getUnitCount(factionIndex);
} }
int ScriptManager::getUnitCountOfType(int factionIndex, const string &typeName){ int ScriptManager::getUnitCountOfType(int factionIndex, const string &typeName){
ScriptManager_STREFLOP_Wrapper streflopWrapper;
return world->getUnitCountOfType(factionIndex, typeName); return world->getUnitCountOfType(factionIndex, typeName);
} }

View File

@@ -24,10 +24,7 @@
#include "opengl.h" #include "opengl.h"
#include "faction.h" #include "faction.h"
#include "factory_repository.h" #include "factory_repository.h"
#include <cstdlib>
#ifndef WIN32
#include <cmath>
#endif
#include "leak_dumper.h" #include "leak_dumper.h"
@@ -541,8 +538,8 @@ void Renderer::renderMouse2d(int x, int y, int anim, float fade){
anim= anim*2-maxMouse2dAnim; anim= anim*2-maxMouse2dAnim;
color2= (abs(anim*fadeFactor)/static_cast<float>(maxMouse2dAnim))/2.f+0.4f; color2= (abs(anim*(int)fadeFactor)/static_cast<float>(maxMouse2dAnim))/2.f+0.4f;
color1= (abs(anim*fadeFactor)/static_cast<float>(maxMouse2dAnim))/2.f+0.8f; color1= (abs(anim*(int)fadeFactor)/static_cast<float>(maxMouse2dAnim))/2.f+0.8f;
glPushAttrib(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_LINE_BIT); glPushAttrib(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_LINE_BIT);
glEnable(GL_BLEND); glEnable(GL_BLEND);

View File

@@ -121,7 +121,6 @@ Program::Program() {
programState= NULL; programState= NULL;
singleton = this; singleton = this;
soundThreadManager = NULL; soundThreadManager = NULL;
loopThreadManager = NULL;
} }
void Program::initNormal(WindowGl *window){ void Program::initNormal(WindowGl *window){
@@ -167,10 +166,6 @@ Program::~Program(){
BaseThread::shutdownAndWait(soundThreadManager); BaseThread::shutdownAndWait(soundThreadManager);
delete soundThreadManager; delete soundThreadManager;
soundThreadManager = NULL; soundThreadManager = NULL;
BaseThread::shutdownAndWait(loopThreadManager);
delete loopThreadManager;
loopThreadManager = NULL;
} }
void Program::keyDown(char key){ void Program::keyDown(char key){
@@ -191,12 +186,7 @@ void Program::simpleTask() {
} }
void Program::loop() { void Program::loop() {
if(loopThreadManager == NULL) { loopWorker();
loopWorker();
}
else {
loopThreadManager->setTaskSignalled(true);
}
} }
void Program::loopWorker() { void Program::loopWorker() {
@@ -407,11 +397,6 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
} }
} }
BaseThread::shutdownAndWait(loopThreadManager);
delete loopThreadManager;
//loopThreadManager = new SimpleTaskThread(this,0,5,true);
//loopThreadManager->start();
NetworkInterface::setAllowGameDataSynchCheck(Config::getInstance().getBool("AllowGameDataSynchCheck","false")); NetworkInterface::setAllowGameDataSynchCheck(Config::getInstance().getBool("AllowGameDataSynchCheck","false"));
NetworkInterface::setAllowDownloadDataSynch(Config::getInstance().getBool("AllowDownloadDataSynch","false")); NetworkInterface::setAllowDownloadDataSynch(Config::getInstance().getBool("AllowDownloadDataSynch","false"));

View File

@@ -110,7 +110,6 @@ private:
WindowGl *window; WindowGl *window;
static Program *singleton; static Program *singleton;
SimpleTaskThread *loopThreadManager;
public: public:
Program(); Program();

View File

@@ -121,17 +121,18 @@ GameNetworkInterface::GameNetworkInterface(){
} }
void GameNetworkInterface::requestCommand(const NetworkCommand *networkCommand, bool insertAtStart) { void GameNetworkInterface::requestCommand(const NetworkCommand *networkCommand, bool insertAtStart) {
Mutex *mutex = getServerSynchAccessor(); assert(networkCommand != NULL);
//Mutex *mutex = getServerSynchAccessor();
if(insertAtStart == false) { if(insertAtStart == false) {
if(mutex != NULL) mutex->p(); //if(mutex != NULL) mutex->p();
requestedCommands.push_back(*networkCommand); requestedCommands.push_back(*networkCommand);
if(mutex != NULL) mutex->v(); //if(mutex != NULL) mutex->v();
} }
else { else {
if(mutex != NULL) mutex->p(); //if(mutex != NULL) mutex->p();
requestedCommands.insert(requestedCommands.begin(),*networkCommand); requestedCommands.insert(requestedCommands.begin(),*networkCommand);
if(mutex != NULL) mutex->v(); //if(mutex != NULL) mutex->v();
} }
} }

View File

@@ -41,7 +41,6 @@ ServerInterface::ServerInterface(){
for(int i= 0; i<GameConstants::maxPlayers; ++i){ for(int i= 0; i<GameConstants::maxPlayers; ++i){
slots[i]= NULL; slots[i]= NULL;
switchSetupRequests[i]= NULL; switchSetupRequests[i]= NULL;
//slotThreads[i] = NULL;
} }
serverSocket.setBlock(false); serverSocket.setBlock(false);
serverSocket.bind(Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str())); serverSocket.bind(Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str()));
@@ -51,10 +50,6 @@ ServerInterface::~ServerInterface(){
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
for(int i= 0; i<GameConstants::maxPlayers; ++i){ for(int i= 0; i<GameConstants::maxPlayers; ++i){
//BaseThread::shutdownAndWait(slotThreads[i]);
//delete slotThreads[i];
//slotThreads[i] = NULL;
delete slots[i]; delete slots[i];
slots[i]=NULL; slots[i]=NULL;
delete switchSetupRequests[i]; delete switchSetupRequests[i];
@@ -76,9 +71,6 @@ void ServerInterface::addSlot(int playerIndex){
slots[playerIndex]= new ConnectionSlot(this, playerIndex); slots[playerIndex]= new ConnectionSlot(this, playerIndex);
updateListen(); updateListen();
//slotThreads[playerIndex] = new ConnectionSlotThread(this);
//slotThreads[playerIndex]->start();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
} }
@@ -108,12 +100,6 @@ bool ServerInterface::switchSlot(int fromPlayerIndex,int toPlayerIndex){
} }
void ServerInterface::removeSlot(int playerIndex) { void ServerInterface::removeSlot(int playerIndex) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
//BaseThread::shutdownAndWait(slotThreads[playerIndex]);
//delete slotThreads[playerIndex];
//slotThreads[playerIndex] = NULL;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex);
delete slots[playerIndex]; delete slots[playerIndex];
@@ -650,7 +636,7 @@ bool ServerInterface::launchGame(const GameSettings* gameSettings){
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
serverSynchAccessor.p(); //serverSynchAccessor.p();
for(int i= 0; i<GameConstants::maxPlayers; ++i) for(int i= 0; i<GameConstants::maxPlayers; ++i)
{ {
@@ -667,7 +653,7 @@ bool ServerInterface::launchGame(const GameSettings* gameSettings){
} }
} }
serverSynchAccessor.v(); //serverSynchAccessor.v();
if(bOkToStart == true) if(bOkToStart == true)
{ {
@@ -749,37 +735,35 @@ void ServerInterface::updateListen() {
return; return;
} }
serverSynchAccessor.p();
int openSlotCount= 0; int openSlotCount= 0;
for(int i= 0; i<GameConstants::maxPlayers; ++i) for(int i= 0; i<GameConstants::maxPlayers; ++i) {
{ serverSynchAccessor.p();
if(slots[i] != NULL && slots[i]->isConnected() == false) bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
{ serverSynchAccessor.v();
if(isSlotOpen == true) {
++openSlotCount; ++openSlotCount;
} }
} }
serverSynchAccessor.p();
serverSocket.listen(openSlotCount); serverSocket.listen(openSlotCount);
serverSynchAccessor.v(); serverSynchAccessor.v();
} }
int ServerInterface::getOpenSlotCount() { int ServerInterface::getOpenSlotCount() {
int openSlotCount= 0; int openSlotCount= 0;
serverSynchAccessor.p(); for(int i= 0; i<GameConstants::maxPlayers; ++i) {
serverSynchAccessor.p();
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
serverSynchAccessor.v();
for(int i= 0; i<GameConstants::maxPlayers; ++i) if(isSlotOpen == true) {
{
if(slots[i] != NULL && slots[i]->isConnected() == false)
{
++openSlotCount; ++openSlotCount;
} }
} }
serverSynchAccessor.v();
return openSlotCount; return openSlotCount;
} }

View File

@@ -23,13 +23,7 @@
#include "skill_type.h" #include "skill_type.h"
#include "core_data.h" #include "core_data.h"
#include "renderer.h" #include "renderer.h"
#include "game.h" #include "game.h"
#ifndef WIN32
#include <cmath>
#endif
#include "socket.h" #include "socket.h"
#include "leak_dumper.h" #include "leak_dumper.h"

View File

@@ -12,8 +12,6 @@
#ifndef _SHARED_GRAPHICS_MATHUTIL_H_ #ifndef _SHARED_GRAPHICS_MATHUTIL_H_
#define _SHARED_GRAPHICS_MATHUTIL_H_ #define _SHARED_GRAPHICS_MATHUTIL_H_
//#include <cmath>
#include "vec.h" #include "vec.h"
namespace Shared{ namespace Graphics{ namespace Shared{ namespace Graphics{

View File

@@ -12,8 +12,6 @@
#ifndef _SHARED_GRAPHICS_MATRIX_H_ #ifndef _SHARED_GRAPHICS_MATRIX_H_
#define _SHARED_GRAPHICS_MATRIX_H_ #define _SHARED_GRAPHICS_MATRIX_H_
//#include <cmath>
#include "vec.h" #include "vec.h"
namespace Shared{ namespace Graphics{ namespace Shared{ namespace Graphics{

View File

@@ -22,11 +22,32 @@ using namespace Shared::Util;
namespace Shared{ namespace Lua{ namespace Shared{ namespace Lua{
//
// This class wraps streflop for LuaScript. We need to toggle the data type
// for streflop to use when calling into LUA as streflop may corrupt some
// numeric values passed from Lua otherwise
//
class Lua_STREFLOP_Wrapper {
public:
Lua_STREFLOP_Wrapper() {
#ifdef USE_STREFLOP
streflop_init<streflop::Double>();
#endif
}
~Lua_STREFLOP_Wrapper() {
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
}
};
// ===================================================== // =====================================================
// class LuaScript // class LuaScript
// ===================================================== // =====================================================
LuaScript::LuaScript(){ LuaScript::LuaScript() {
Lua_STREFLOP_Wrapper streflopWrapper;
luaState= luaL_newstate(); luaState= luaL_newstate();
luaL_openlibs(luaState); luaL_openlibs(luaState);
@@ -38,73 +59,51 @@ LuaScript::LuaScript(){
argumentCount= -1; argumentCount= -1;
} }
LuaScript::~LuaScript(){ LuaScript::~LuaScript() {
Lua_STREFLOP_Wrapper streflopWrapper;
lua_close(luaState); lua_close(luaState);
} }
void LuaScript::loadCode(const string &code, const string &name){ void LuaScript::loadCode(const string &code, const string &name){
Lua_STREFLOP_Wrapper streflopWrapper;
#ifdef USE_STREFLOP
streflop_init<streflop::Double>();
#endif
int errorCode= luaL_loadbuffer(luaState, code.c_str(), code.size(), name.c_str()); int errorCode= luaL_loadbuffer(luaState, code.c_str(), code.size(), name.c_str());
if(errorCode!=0){ if(errorCode!=0){
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
throw runtime_error("Error loading lua code: " + errorToString(errorCode)); throw runtime_error("Error loading lua code: " + errorToString(errorCode));
} }
//run code //run code
errorCode= lua_pcall(luaState, 0, 0, 0)!=0; errorCode= lua_pcall(luaState, 0, 0, 0)!=0;
if(errorCode!=0){ if(errorCode!=0){
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
throw runtime_error("Error initializing lua: " + errorToString(errorCode)); throw runtime_error("Error initializing lua: " + errorToString(errorCode));
} }
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
} }
void LuaScript::beginCall(const string& functionName){ void LuaScript::beginCall(const string& functionName){
#ifdef USE_STREFLOP Lua_STREFLOP_Wrapper streflopWrapper;
streflop_init<streflop::Double>();
#endif
lua_getglobal(luaState, functionName.c_str()); lua_getglobal(luaState, functionName.c_str());
argumentCount= 0; argumentCount= 0;
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
} }
void LuaScript::endCall(){ void LuaScript::endCall(){
#ifdef USE_STREFLOP Lua_STREFLOP_Wrapper streflopWrapper;
streflop_init<streflop::Double>();
#endif
lua_pcall(luaState, argumentCount, 0, 0); lua_pcall(luaState, argumentCount, 0, 0);
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
} }
void LuaScript::registerFunction(LuaFunction luaFunction, const string &functionName){ void LuaScript::registerFunction(LuaFunction luaFunction, const string &functionName){
#ifdef USE_STREFLOP Lua_STREFLOP_Wrapper streflopWrapper;
streflop_init<streflop::Double>();
#endif lua_pushcfunction(luaState, luaFunction);
lua_pushcfunction(luaState, luaFunction);
lua_setglobal(luaState, functionName.c_str()); lua_setglobal(luaState, functionName.c_str());
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
} }
string LuaScript::errorToString(int errorCode){ string LuaScript::errorToString(int errorCode) {
Lua_STREFLOP_Wrapper streflopWrapper;
string error; string error;
switch(errorCode){ switch(errorCode){
case LUA_ERRSYNTAX: case LUA_ERRSYNTAX:
error+= "Syntax error"; error+= "Syntax error";
@@ -132,34 +131,25 @@ string LuaScript::errorToString(int errorCode){
// ===================================================== // =====================================================
LuaArguments::LuaArguments(lua_State *luaState){ LuaArguments::LuaArguments(lua_State *luaState){
#ifdef USE_STREFLOP Lua_STREFLOP_Wrapper streflopWrapper;
streflop_init<streflop::Double>();
#endif
this->luaState= luaState; this->luaState= luaState;
returnCount= 0; returnCount= 0;
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
} }
int LuaArguments::getInt(int argumentIndex) const{ int LuaArguments::getInt(int argumentIndex) const{
#ifdef USE_STREFLOP Lua_STREFLOP_Wrapper streflopWrapper;
streflop_init<streflop::Double>();
#endif if(!lua_isnumber(luaState, argumentIndex)) {
if(!lua_isnumber(luaState, argumentIndex)){
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
throwLuaError("Can not get int from Lua state"); throwLuaError("Can not get int from Lua state");
} }
int result = luaL_checkint(luaState, argumentIndex); int result = luaL_checkint(luaState, argumentIndex);
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
return result; return result;
} }
string LuaArguments::getString(int argumentIndex) const{ string LuaArguments::getString(int argumentIndex) const{
Lua_STREFLOP_Wrapper streflopWrapper;
if(!lua_isstring(luaState, argumentIndex)){ if(!lua_isstring(luaState, argumentIndex)){
throwLuaError("Can not get string from Lua state"); throwLuaError("Can not get string from Lua state");
} }
@@ -167,22 +157,15 @@ string LuaArguments::getString(int argumentIndex) const{
} }
Vec2i LuaArguments::getVec2i(int argumentIndex) const{ Vec2i LuaArguments::getVec2i(int argumentIndex) const{
#ifdef USE_STREFLOP Lua_STREFLOP_Wrapper streflopWrapper;
streflop_init<streflop::Double>();
#endif
Vec2i v; Vec2i v;
if(!lua_istable(luaState, argumentIndex)){ if(!lua_istable(luaState, argumentIndex)){
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
throwLuaError("Can not get vec2i from Lua state, value on the stack is not a table"); throwLuaError("Can not get vec2i from Lua state, value on the stack is not a table");
} }
if(luaL_getn(luaState, argumentIndex)!=2){ if(luaL_getn(luaState, argumentIndex)!=2){
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
throwLuaError("Can not get vec2i from Lua state, array size not 2"); throwLuaError("Can not get vec2i from Lua state, array size not 2");
} }
@@ -194,32 +177,26 @@ Vec2i LuaArguments::getVec2i(int argumentIndex) const{
v.y= luaL_checkint(luaState, argumentIndex); v.y= luaL_checkint(luaState, argumentIndex);
lua_pop(luaState, 1); lua_pop(luaState, 1);
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
return v; return v;
} }
void LuaArguments::returnInt(int value){ void LuaArguments::returnInt(int value){
#ifdef USE_STREFLOP Lua_STREFLOP_Wrapper streflopWrapper;
streflop_init<streflop::Double>();
#endif
++returnCount; ++returnCount;
lua_pushinteger(luaState, value); lua_pushinteger(luaState, value);
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
} }
void LuaArguments::returnString(const string &value){ void LuaArguments::returnString(const string &value){
Lua_STREFLOP_Wrapper streflopWrapper;
++returnCount; ++returnCount;
lua_pushstring(luaState, value.c_str()); lua_pushstring(luaState, value.c_str());
} }
void LuaArguments::returnVec2i(const Vec2i &value){ void LuaArguments::returnVec2i(const Vec2i &value){
#ifdef USE_STREFLOP Lua_STREFLOP_Wrapper streflopWrapper;
streflop_init<streflop::Double>();
#endif
++returnCount; ++returnCount;
lua_newtable(luaState); lua_newtable(luaState);
@@ -229,15 +206,11 @@ void LuaArguments::returnVec2i(const Vec2i &value){
lua_pushnumber(luaState, value.y); lua_pushnumber(luaState, value.y);
lua_rawseti(luaState, -2, 2); lua_rawseti(luaState, -2, 2);
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
} }
void LuaArguments::throwLuaError(const string &message) const{ void LuaArguments::throwLuaError(const string &message) const{
#ifdef USE_STREFLOP Lua_STREFLOP_Wrapper streflopWrapper;
streflop_init<streflop::Double>();
#endif
string stackString; string stackString;
int stackSize = lua_gettop(luaState); int stackSize = lua_gettop(luaState);
@@ -260,9 +233,6 @@ void LuaArguments::throwLuaError(const string &message) const{
stackString+= "\n"; stackString+= "\n";
} }
#ifdef USE_STREFLOP
streflop_init<streflop::Simple>();
#endif
throw runtime_error("Lua error: " + message + "\n\nLua Stack:\n" + stackString); throw runtime_error("Lua error: " + message + "\n\nLua Stack:\n" + stackString);
} }