Old TPT console commands with "!" prefix

This commit is contained in:
Simon Robertshaw
2012-08-03 21:48:45 +01:00
parent f586a5585f
commit 6173901875
5 changed files with 76 additions and 21 deletions

View File

@@ -8,13 +8,15 @@
#include <string>
#include "Config.h"
#include "LuaScriptInterface.h"
#include "TPTScriptInterface.h"
#include "simulation/Simulation.h"
#include "game/GameModel.h"
#include "LuaScriptHelper.h"
LuaScriptInterface::LuaScriptInterface(GameModel * m):
CommandInterface(m),
currentCommand(false)
currentCommand(false),
legacy(new TPTScriptInterface(m))
{
int i = 0, j;
char tmpname[12];
@@ -284,16 +286,26 @@ void LuaScriptInterface::OnTick()
int LuaScriptInterface::Command(std::string command)
{
int ret;
lastError = "";
currentCommand = true;
if((ret = luaL_dostring(l, command.c_str())))
if(command[0] == '!')
{
lastError = luacon_geterror();
//Log(LogError, lastError);
lastError = "";
int ret = legacy->Command(command.substr(1));
lastError = legacy->GetLastError();
return ret;
}
else
{
int ret;
lastError = "";
currentCommand = true;
if((ret = luaL_dostring(l, command.c_str())))
{
lastError = luacon_geterror();
//Log(LogError, lastError);
}
currentCommand = false;
return ret;
}
currentCommand = false;
return ret;
}
std::string LuaScriptInterface::FormatCommand(std::string command)
@@ -302,7 +314,7 @@ std::string LuaScriptInterface::FormatCommand(std::string command)
}
LuaScriptInterface::~LuaScriptInterface() {
// TODO Auto-generated destructor stub
delete legacy;
}
#ifndef FFI

View File

@@ -33,10 +33,12 @@ extern "C"
#define LUACON_EL_MODIFIED_GRAPHICS 0x2
#define LUACON_EL_MODIFIED_MENUS 0x4
class TPTScriptInterface;
class LuaScriptInterface: public CommandInterface {
int luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_mousebutton, luacon_brushx, luacon_brushy;
bool luacon_mousedown;
bool currentCommand;
TPTScriptInterface * legacy;
public:
lua_State *l;
LuaScriptInterface(GameModel * m);

View File

@@ -9,6 +9,7 @@
#define TPTSTYPES_H_
#include <string>
#include <typeinfo>
#include "interface/Point.h"
enum ValueType { TypeNumber, TypePoint, TypeString, TypeNull, TypeFunction };
@@ -26,15 +27,6 @@ public:
}
};
class InvalidConversionException: public GeneralException
{
private:
ValueType from;
ValueType to;
public:
InvalidConversionException(ValueType from_, ValueType to_): GeneralException("Invalid conversion"), from(from_), to(to_) {
}
};
class NumberType;
class StringType;
@@ -52,9 +44,56 @@ public:
operator StringType();
operator PointType();
ValueType GetType();
std::string TypeName()
{
switch(type)
{
case TypeNumber:
return "Number";
case TypePoint:
return "Point";
case TypeString:
return "String";
case TypeNull:
return "Null";
case TypeFunction:
return "Function";
default:
return "Unknown";
}
}
static std::string TypeName(ValueType type)
{
switch(type)
{
case TypeNumber:
return "Number";
case TypePoint:
return "Point";
case TypeString:
return "String";
case TypeNull:
return "Null";
case TypeFunction:
return "Function";
default:
return "Unknown";
}
}
~AnyType();
};
class InvalidConversionException: public GeneralException
{
private:
ValueType from;
ValueType to;
public:
InvalidConversionException(ValueType from_, ValueType to_):
GeneralException("Invalid conversion from " + AnyType::TypeName(from_) + " to " + AnyType::TypeName(to_)), from(from_), to(to_) {
}
};
class NumberType: public AnyType
{
public:

View File

@@ -167,8 +167,8 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
{
//Arguments from stack
StringType property = eval(words);
AnyType value = eval(words);
AnyType selector = eval(words);
AnyType value = eval(words);
Simulation * sim = m->GetSimulation();
@@ -187,7 +187,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
{
ui::Point tempPoint = ((PointType)selector).Value();
if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES)
throw GeneralException("Invalid particle");
throw GeneralException("Invalid position");
}
else

View File

@@ -65,6 +65,8 @@ void Textbox::SetText(std::string newText)
else
Label::SetText(newText);
cursor = newText.length();
if(cursor)
{
Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY);