mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-28 10:20:04 +02:00
Derive LuaScriptInterface from TPTScriptInterface
Also convert stray references to LSI to stray references to CommandInterface. Not a lot better as it's still a global >_> but it's easier to follow.
This commit is contained in:
@@ -52,9 +52,7 @@
|
|||||||
#include "common/String.h"
|
#include "common/String.h"
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
|
|
||||||
#ifdef LUACONSOLE
|
#include "lua/CommandInterface.h"
|
||||||
# include "lua/LuaScriptInterface.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "client/http/RequestManager.h"
|
#include "client/http/RequestManager.h"
|
||||||
#include "gui/preview/Comment.h"
|
#include "gui/preview/Comment.h"
|
||||||
@@ -1036,9 +1034,7 @@ SaveFile * Client::LoadSaveFile(ByteString filename)
|
|||||||
{
|
{
|
||||||
file->SetLoadingError(err.FromUtf8());
|
file->SetLoadingError(err.FromUtf8());
|
||||||
}
|
}
|
||||||
#ifdef LUACONSOLE
|
commandInterface->SetLastError(err.FromUtf8());
|
||||||
luacon_ci->SetLastError(err.FromUtf8());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
@@ -90,8 +90,7 @@ GameController::GameController():
|
|||||||
|
|
||||||
gameView->SetDebugHUD(Client::Ref().GetPrefBool("Renderer.DebugMode", false));
|
gameView->SetDebugHUD(Client::Ref().GetPrefBool("Renderer.DebugMode", false));
|
||||||
|
|
||||||
commandInterface = CommandInterface::Create(this, gameModel);
|
CommandInterface::Create(this, gameModel);
|
||||||
gameModel->commandInterface = commandInterface;
|
|
||||||
|
|
||||||
Client::Ref().AddListener(this);
|
Client::Ref().AddListener(this);
|
||||||
|
|
||||||
|
@@ -50,7 +50,6 @@ private:
|
|||||||
TagsController * tagsWindow;
|
TagsController * tagsWindow;
|
||||||
LocalBrowserController * localBrowser;
|
LocalBrowserController * localBrowser;
|
||||||
OptionsController * options;
|
OptionsController * options;
|
||||||
CommandInterface * commandInterface;
|
|
||||||
std::vector<DebugInfo*> debugInfo;
|
std::vector<DebugInfo*> debugInfo;
|
||||||
std::unique_ptr<Snapshot> beforeRestore;
|
std::unique_ptr<Snapshot> beforeRestore;
|
||||||
unsigned int debugFlags;
|
unsigned int debugFlags;
|
||||||
|
@@ -23,7 +23,6 @@ class Renderer;
|
|||||||
class Snapshot;
|
class Snapshot;
|
||||||
struct SnapshotDelta;
|
struct SnapshotDelta;
|
||||||
class GameSave;
|
class GameSave;
|
||||||
class CommandInterface;
|
|
||||||
|
|
||||||
class ToolSelection
|
class ToolSelection
|
||||||
{
|
{
|
||||||
@@ -252,6 +251,4 @@ public:
|
|||||||
void UpdateUpTo(int upTo);
|
void UpdateUpTo(int upTo);
|
||||||
void BeforeSim();
|
void BeforeSim();
|
||||||
void AfterSim();
|
void AfterSim();
|
||||||
|
|
||||||
CommandInterface *commandInterface = nullptr;
|
|
||||||
};
|
};
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cassert>
|
||||||
#if !defined(WIN) || defined(__GNUC__)
|
#if !defined(WIN) || defined(__GNUC__)
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -10,15 +11,20 @@
|
|||||||
#include "gui/game/GameModel.h"
|
#include "gui/game/GameModel.h"
|
||||||
#include "simulation/Particle.h"
|
#include "simulation/Particle.h"
|
||||||
|
|
||||||
CommandInterface::CommandInterface(GameController * c, GameModel * m) {
|
CommandInterface *commandInterface = nullptr;
|
||||||
|
|
||||||
|
CommandInterface::CommandInterface(GameController * c, GameModel * m)
|
||||||
|
{
|
||||||
|
assert(!commandInterface);
|
||||||
|
commandInterface = this;
|
||||||
this->m = m;
|
this->m = m;
|
||||||
this->c = c;
|
this->c = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void CommandInterface::AttachGameModel(GameModel * m)
|
CommandInterface::~CommandInterface()
|
||||||
{
|
{
|
||||||
this->m = m;
|
commandInterface = nullptr;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
int CommandInterface::Command(String command)
|
int CommandInterface::Command(String command)
|
||||||
{
|
{
|
||||||
@@ -78,6 +84,3 @@ String CommandInterface::GetLastError()
|
|||||||
{
|
{
|
||||||
return lastError;
|
return lastError;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandInterface::~CommandInterface() {
|
|
||||||
}
|
|
||||||
|
@@ -39,3 +39,5 @@ public:
|
|||||||
|
|
||||||
static CommandInterface *Create(GameController * c, GameModel * m);
|
static CommandInterface *Create(GameController * c, GameModel * m);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern CommandInterface *commandInterface;
|
||||||
|
@@ -277,6 +277,7 @@ void luacon_hook(lua_State * l, lua_Debug * ar)
|
|||||||
|
|
||||||
String luacon_geterror()
|
String luacon_geterror()
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
luaL_tostring(luacon_ci->l, -1);
|
luaL_tostring(luacon_ci->l, -1);
|
||||||
String err = tpt_lua_optString(luacon_ci->l, -1, "failed to execute");
|
String err = tpt_lua_optString(luacon_ci->l, -1, "failed to execute");
|
||||||
lua_pop(luacon_ci->l, 1);
|
lua_pop(luacon_ci->l, 1);
|
||||||
@@ -395,6 +396,7 @@ int luatpt_togglewater(lua_State* l)
|
|||||||
|
|
||||||
int luatpt_setconsole(lua_State* l)
|
int luatpt_setconsole(lua_State* l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
int acount = lua_gettop(l);
|
int acount = lua_gettop(l);
|
||||||
if (acount == 0)
|
if (acount == 0)
|
||||||
{
|
{
|
||||||
@@ -410,6 +412,7 @@ int luatpt_setconsole(lua_State* l)
|
|||||||
|
|
||||||
int luatpt_log(lua_State* l)
|
int luatpt_log(lua_State* l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
int args = lua_gettop(l);
|
int args = lua_gettop(l);
|
||||||
String text;
|
String text;
|
||||||
bool hasText = false;
|
bool hasText = false;
|
||||||
@@ -560,6 +563,7 @@ int luatpt_reset_spark(lua_State* l)
|
|||||||
|
|
||||||
int luatpt_set_property(lua_State* l)
|
int luatpt_set_property(lua_State* l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
int r, i, x, y, w, h, t = 0, nx, ny, partsel = 0;
|
int r, i, x, y, w, h, t = 0, nx, ny, partsel = 0;
|
||||||
float f = 0;
|
float f = 0;
|
||||||
int acount = lua_gettop(l);
|
int acount = lua_gettop(l);
|
||||||
@@ -803,6 +807,7 @@ int luatpt_get_elecmap(lua_State* l)
|
|||||||
|
|
||||||
int luatpt_get_property(lua_State* l)
|
int luatpt_get_property(lua_State* l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
ByteString prop = tpt_lua_optByteString(l, 1, "");
|
ByteString prop = tpt_lua_optByteString(l, 1, "");
|
||||||
int i = luaL_optint(l, 2, 0); //x coord or particle index, depending on arguments
|
int i = luaL_optint(l, 2, 0); //x coord or particle index, depending on arguments
|
||||||
int y = luaL_optint(l, 3, -1);
|
int y = luaL_optint(l, 3, -1);
|
||||||
|
@@ -8,14 +8,13 @@
|
|||||||
class GameModel;
|
class GameModel;
|
||||||
class GameController;
|
class GameController;
|
||||||
class Simulation;
|
class Simulation;
|
||||||
class LuaScriptInterface;
|
class CommandInterface;
|
||||||
class Graphics;
|
class Graphics;
|
||||||
class Renderer;
|
class Renderer;
|
||||||
|
|
||||||
extern GameModel * luacon_model;
|
extern GameModel * luacon_model;
|
||||||
extern GameController * luacon_controller;
|
extern GameController * luacon_controller;
|
||||||
extern Simulation * luacon_sim;
|
extern Simulation * luacon_sim;
|
||||||
extern LuaScriptInterface * luacon_ci;
|
|
||||||
extern Graphics * luacon_g;
|
extern Graphics * luacon_g;
|
||||||
extern Renderer * luacon_ren;
|
extern Renderer * luacon_ren;
|
||||||
|
|
||||||
|
@@ -76,7 +76,6 @@ extern "C"
|
|||||||
GameModel * luacon_model;
|
GameModel * luacon_model;
|
||||||
GameController * luacon_controller;
|
GameController * luacon_controller;
|
||||||
Simulation * luacon_sim;
|
Simulation * luacon_sim;
|
||||||
LuaScriptInterface * luacon_ci;
|
|
||||||
Graphics * luacon_g;
|
Graphics * luacon_g;
|
||||||
Renderer * luacon_ren;
|
Renderer * luacon_ren;
|
||||||
|
|
||||||
@@ -103,14 +102,14 @@ int atPanic(lua_State *l)
|
|||||||
|
|
||||||
int TptIndexClosure(lua_State *l)
|
int TptIndexClosure(lua_State *l)
|
||||||
{
|
{
|
||||||
LuaScriptInterface *lsi = (LuaScriptInterface *)lua_touserdata(l, lua_upvalueindex(1));
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
return lsi->tpt_index(l);
|
return luacon_ci->tpt_index(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TptNewindexClosure(lua_State *l)
|
int TptNewindexClosure(lua_State *l)
|
||||||
{
|
{
|
||||||
LuaScriptInterface *lsi = (LuaScriptInterface *)lua_touserdata(l, lua_upvalueindex(1));
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
return lsi->tpt_newIndex(l);
|
return luacon_ci->tpt_newIndex(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bz2_compress_wrapper(lua_State *L)
|
static int bz2_compress_wrapper(lua_State *L)
|
||||||
@@ -176,7 +175,7 @@ static void initBZ2API(lua_State *L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
|
LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
|
||||||
CommandInterface(c, m),
|
TPTScriptInterface(c, m),
|
||||||
luacon_mousex(0),
|
luacon_mousex(0),
|
||||||
luacon_mousey(0),
|
luacon_mousey(0),
|
||||||
luacon_mousebutton(0),
|
luacon_mousebutton(0),
|
||||||
@@ -186,7 +185,6 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
|
|||||||
luacon_selectedreplace(""),
|
luacon_selectedreplace(""),
|
||||||
luacon_mousedown(false),
|
luacon_mousedown(false),
|
||||||
currentCommand(false),
|
currentCommand(false),
|
||||||
legacy(new TPTScriptInterface(c, m)),
|
|
||||||
textInputRefcount(0)
|
textInputRefcount(0)
|
||||||
{
|
{
|
||||||
luacon_model = m;
|
luacon_model = m;
|
||||||
@@ -194,7 +192,6 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
|
|||||||
luacon_sim = m->GetSimulation();
|
luacon_sim = m->GetSimulation();
|
||||||
luacon_g = ui::Engine::Ref().g;
|
luacon_g = ui::Engine::Ref().g;
|
||||||
luacon_ren = m->GetRenderer();
|
luacon_ren = m->GetRenderer();
|
||||||
luacon_ci = this;
|
|
||||||
|
|
||||||
for (auto moving = 0; moving < PT_NUM; ++moving)
|
for (auto moving = 0; moving < PT_NUM; ++moving)
|
||||||
{
|
{
|
||||||
@@ -434,11 +431,9 @@ tpt.partsdata = nil");
|
|||||||
|
|
||||||
//make tpt.* a metatable
|
//make tpt.* a metatable
|
||||||
lua_newtable(l);
|
lua_newtable(l);
|
||||||
lua_pushlightuserdata(l, this);
|
lua_pushcfunction(l, TptIndexClosure);
|
||||||
lua_pushcclosure(l, TptIndexClosure, 1);
|
|
||||||
lua_setfield(l, -2, "__index");
|
lua_setfield(l, -2, "__index");
|
||||||
lua_pushlightuserdata(l, this);
|
lua_pushcfunction(l, TptNewindexClosure);
|
||||||
lua_pushcclosure(l, TptNewindexClosure, 1);
|
|
||||||
lua_setfield(l, -2, "__newindex");
|
lua_setfield(l, -2, "__newindex");
|
||||||
lua_setmetatable(l, -2);
|
lua_setmetatable(l, -2);
|
||||||
|
|
||||||
@@ -470,11 +465,10 @@ void LuaScriptInterface::Init()
|
|||||||
{
|
{
|
||||||
if (Platform::FileExists("autorun.lua"))
|
if (Platform::FileExists("autorun.lua"))
|
||||||
{
|
{
|
||||||
lua_State *l = luacon_ci->l;
|
|
||||||
if(luaL_loadfile(l, "autorun.lua") || lua_pcall(l, 0, 0, 0))
|
if(luaL_loadfile(l, "autorun.lua") || lua_pcall(l, 0, 0, 0))
|
||||||
luacon_ci->Log(CommandInterface::LogError, luacon_geterror());
|
Log(CommandInterface::LogError, luacon_geterror());
|
||||||
else
|
else
|
||||||
luacon_ci->Log(CommandInterface::LogWarning, "Loaded autorun.lua");
|
Log(CommandInterface::LogWarning, "Loaded autorun.lua");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,6 +603,7 @@ void LuaScriptInterface::initInterfaceAPI()
|
|||||||
|
|
||||||
int LuaScriptInterface::interface_addComponent(lua_State * l)
|
int LuaScriptInterface::interface_addComponent(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
void *opaque = nullptr;
|
void *opaque = nullptr;
|
||||||
LuaComponent *luaComponent = nullptr;
|
LuaComponent *luaComponent = nullptr;
|
||||||
if ((opaque = Luna<LuaButton>::tryGet(l, 1)))
|
if ((opaque = Luna<LuaButton>::tryGet(l, 1)))
|
||||||
@@ -641,6 +636,7 @@ int LuaScriptInterface::interface_addComponent(lua_State * l)
|
|||||||
|
|
||||||
int LuaScriptInterface::interface_removeComponent(lua_State * l)
|
int LuaScriptInterface::interface_removeComponent(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
void *opaque = nullptr;
|
void *opaque = nullptr;
|
||||||
LuaComponent *luaComponent = nullptr;
|
LuaComponent *luaComponent = nullptr;
|
||||||
if ((opaque = Luna<LuaButton>::tryGet(l, 1)))
|
if ((opaque = Luna<LuaButton>::tryGet(l, 1)))
|
||||||
@@ -674,6 +670,7 @@ int LuaScriptInterface::interface_removeComponent(lua_State * l)
|
|||||||
|
|
||||||
int LuaScriptInterface::interface_grabTextInput(lua_State * l)
|
int LuaScriptInterface::interface_grabTextInput(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
luacon_ci->textInputRefcount += 1;
|
luacon_ci->textInputRefcount += 1;
|
||||||
luacon_controller->GetView()->DoesTextInput = luacon_ci->textInputRefcount > 0;
|
luacon_controller->GetView()->DoesTextInput = luacon_ci->textInputRefcount > 0;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -681,6 +678,7 @@ int LuaScriptInterface::interface_grabTextInput(lua_State * l)
|
|||||||
|
|
||||||
int LuaScriptInterface::interface_dropTextInput(lua_State * l)
|
int LuaScriptInterface::interface_dropTextInput(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
luacon_ci->textInputRefcount -= 1;
|
luacon_ci->textInputRefcount -= 1;
|
||||||
luacon_controller->GetView()->DoesTextInput = luacon_ci->textInputRefcount > 0;
|
luacon_controller->GetView()->DoesTextInput = luacon_ci->textInputRefcount > 0;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1903,6 +1901,7 @@ int LuaScriptInterface::simulation_saveStamp(lua_State * l)
|
|||||||
|
|
||||||
int LuaScriptInterface::simulation_loadStamp(lua_State * l)
|
int LuaScriptInterface::simulation_loadStamp(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
int i = -1;
|
int i = -1;
|
||||||
int pushed = 1;
|
int pushed = 1;
|
||||||
SaveFile * tempfile = NULL;
|
SaveFile * tempfile = NULL;
|
||||||
@@ -2143,6 +2142,7 @@ int LuaScriptInterface::simulation_elementCount(lua_State * l)
|
|||||||
|
|
||||||
int LuaScriptInterface::simulation_canMove(lua_State * l)
|
int LuaScriptInterface::simulation_canMove(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
int movingElement = luaL_checkint(l, 1);
|
int movingElement = luaL_checkint(l, 1);
|
||||||
int destinationElement = luaL_checkint(l, 2);
|
int destinationElement = luaL_checkint(l, 2);
|
||||||
if (movingElement < 0 || movingElement >= PT_NUM)
|
if (movingElement < 0 || movingElement >= PT_NUM)
|
||||||
@@ -3025,6 +3025,7 @@ void LuaScriptInterface::LuaSetParticleProperty(lua_State* l, int particleID, St
|
|||||||
|
|
||||||
int LuaScriptInterface::elements_loadDefault(lua_State * l)
|
int LuaScriptInterface::elements_loadDefault(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
int args = lua_gettop(l);
|
int args = lua_gettop(l);
|
||||||
if (args)
|
if (args)
|
||||||
{
|
{
|
||||||
@@ -3088,6 +3089,7 @@ int LuaScriptInterface::elements_loadDefault(lua_State * l)
|
|||||||
|
|
||||||
int LuaScriptInterface::elements_allocate(lua_State * l)
|
int LuaScriptInterface::elements_allocate(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
luaL_checktype(l, 1, LUA_TSTRING);
|
luaL_checktype(l, 1, LUA_TSTRING);
|
||||||
luaL_checktype(l, 2, LUA_TSTRING);
|
luaL_checktype(l, 2, LUA_TSTRING);
|
||||||
auto group = tpt_lua_toByteString(l, 1).ToUpper();
|
auto group = tpt_lua_toByteString(l, 1).ToUpper();
|
||||||
@@ -3164,6 +3166,7 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
|
|||||||
|
|
||||||
static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
|
static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
auto *builtinUpdate = GetElements()[parts[i].type].Update;
|
auto *builtinUpdate = GetElements()[parts[i].type].Update;
|
||||||
if (builtinUpdate && lua_el_mode[parts[i].type] == 1)
|
if (builtinUpdate && lua_el_mode[parts[i].type] == 1)
|
||||||
{
|
{
|
||||||
@@ -3207,6 +3210,7 @@ static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
|
|||||||
|
|
||||||
static int luaGraphicsWrapper(GRAPHICS_FUNC_ARGS)
|
static int luaGraphicsWrapper(GRAPHICS_FUNC_ARGS)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
if (lua_gr_func[cpart->type])
|
if (lua_gr_func[cpart->type])
|
||||||
{
|
{
|
||||||
int cache = 0, callret;
|
int cache = 0, callret;
|
||||||
@@ -3253,6 +3257,7 @@ static int luaGraphicsWrapper(GRAPHICS_FUNC_ARGS)
|
|||||||
|
|
||||||
static void luaCreateWrapper(ELEMENT_CREATE_FUNC_ARGS)
|
static void luaCreateWrapper(ELEMENT_CREATE_FUNC_ARGS)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
if (luaCreateHandlers[sim->parts[i].type])
|
if (luaCreateHandlers[sim->parts[i].type])
|
||||||
{
|
{
|
||||||
lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, luaCreateHandlers[sim->parts[i].type]);
|
lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, luaCreateHandlers[sim->parts[i].type]);
|
||||||
@@ -3271,6 +3276,7 @@ static void luaCreateWrapper(ELEMENT_CREATE_FUNC_ARGS)
|
|||||||
|
|
||||||
static bool luaCreateAllowedWrapper(ELEMENT_CREATE_ALLOWED_FUNC_ARGS)
|
static bool luaCreateAllowedWrapper(ELEMENT_CREATE_ALLOWED_FUNC_ARGS)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (luaCreateAllowedHandlers[t])
|
if (luaCreateAllowedHandlers[t])
|
||||||
{
|
{
|
||||||
@@ -3296,6 +3302,7 @@ static bool luaCreateAllowedWrapper(ELEMENT_CREATE_ALLOWED_FUNC_ARGS)
|
|||||||
|
|
||||||
static void luaChangeTypeWrapper(ELEMENT_CHANGETYPE_FUNC_ARGS)
|
static void luaChangeTypeWrapper(ELEMENT_CHANGETYPE_FUNC_ARGS)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
if (luaChangeTypeHandlers[sim->parts[i].type])
|
if (luaChangeTypeHandlers[sim->parts[i].type])
|
||||||
{
|
{
|
||||||
lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, luaChangeTypeHandlers[sim->parts[i].type]);
|
lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, luaChangeTypeHandlers[sim->parts[i].type]);
|
||||||
@@ -3314,6 +3321,7 @@ static void luaChangeTypeWrapper(ELEMENT_CHANGETYPE_FUNC_ARGS)
|
|||||||
|
|
||||||
static bool luaCtypeDrawWrapper(CTYPEDRAW_FUNC_ARGS)
|
static bool luaCtypeDrawWrapper(CTYPEDRAW_FUNC_ARGS)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (luaCtypeDrawHandlers[sim->parts[i].type])
|
if (luaCtypeDrawHandlers[sim->parts[i].type])
|
||||||
{
|
{
|
||||||
@@ -3338,6 +3346,7 @@ static bool luaCtypeDrawWrapper(CTYPEDRAW_FUNC_ARGS)
|
|||||||
|
|
||||||
int LuaScriptInterface::elements_element(lua_State * l)
|
int LuaScriptInterface::elements_element(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
int id = luaL_checkinteger(l, 1);
|
int id = luaL_checkinteger(l, 1);
|
||||||
if (!luacon_sim->IsElementOrNone(id))
|
if (!luacon_sim->IsElementOrNone(id))
|
||||||
{
|
{
|
||||||
@@ -3524,6 +3533,7 @@ void LuaScriptInterface::SetDefaultProperties(lua_State * l, int id, int stackPo
|
|||||||
|
|
||||||
int LuaScriptInterface::elements_property(lua_State * l)
|
int LuaScriptInterface::elements_property(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
int id = luaL_checkinteger(l, 1);
|
int id = luaL_checkinteger(l, 1);
|
||||||
if (!luacon_sim->IsElementOrNone(id))
|
if (!luacon_sim->IsElementOrNone(id))
|
||||||
{
|
{
|
||||||
@@ -4163,6 +4173,7 @@ void LuaScriptInterface::initEventAPI()
|
|||||||
|
|
||||||
int LuaScriptInterface::event_register(lua_State * l)
|
int LuaScriptInterface::event_register(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
int eventType = luaL_checkinteger(l, 1);
|
int eventType = luaL_checkinteger(l, 1);
|
||||||
luaL_checktype(l, 2, LUA_TFUNCTION);
|
luaL_checktype(l, 2, LUA_TFUNCTION);
|
||||||
if (eventType < 0 || eventType >= int(luacon_ci->gameControllerEventHandlers.size()))
|
if (eventType < 0 || eventType >= int(luacon_ci->gameControllerEventHandlers.size()))
|
||||||
@@ -4179,6 +4190,7 @@ int LuaScriptInterface::event_register(lua_State * l)
|
|||||||
|
|
||||||
int LuaScriptInterface::event_unregister(lua_State * l)
|
int LuaScriptInterface::event_unregister(lua_State * l)
|
||||||
{
|
{
|
||||||
|
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
|
||||||
int eventType = luaL_checkinteger(l, 1);
|
int eventType = luaL_checkinteger(l, 1);
|
||||||
luaL_checktype(l, 2, LUA_TFUNCTION);
|
luaL_checktype(l, 2, LUA_TFUNCTION);
|
||||||
if (eventType < 0 || eventType >= int(luacon_ci->gameControllerEventHandlers.size()))
|
if (eventType < 0 || eventType >= int(luacon_ci->gameControllerEventHandlers.size()))
|
||||||
@@ -4634,8 +4646,8 @@ int LuaScriptInterface::Command(String command)
|
|||||||
luacon_hasLastError = false;
|
luacon_hasLastError = false;
|
||||||
if (command[0] == '!')
|
if (command[0] == '!')
|
||||||
{
|
{
|
||||||
int ret = legacy->Command(command.Substr(1));
|
int ret = TPTScriptInterface::Command(command.Substr(1));
|
||||||
lastError = legacy->GetLastError();
|
lastError = GetLastError();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -4903,17 +4915,18 @@ String LuaScriptInterface::FormatCommand(String command)
|
|||||||
{
|
{
|
||||||
if(command.size() && command[0] == '!')
|
if(command.size() && command[0] == '!')
|
||||||
{
|
{
|
||||||
return "!"+legacy->FormatCommand(command.Substr(1));
|
return "!" + TPTScriptInterface::FormatCommand(command.Substr(1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return highlight(command);
|
return highlight(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaScriptInterface::~LuaScriptInterface() {
|
LuaScriptInterface::~LuaScriptInterface()
|
||||||
|
{
|
||||||
delete tptPart;
|
delete tptPart;
|
||||||
for (auto &component_and_ref : grabbed_components)
|
for (auto &component_and_ref : grabbed_components)
|
||||||
{
|
{
|
||||||
luacon_ci->Window->RemoveComponent(component_and_ref.first->GetComponent());
|
Window->RemoveComponent(component_and_ref.first->GetComponent());
|
||||||
component_and_ref.second.Clear();
|
component_and_ref.second.Clear();
|
||||||
component_and_ref.first->owner_ref = component_and_ref.second;
|
component_and_ref.first->owner_ref = component_and_ref.second;
|
||||||
component_and_ref.first->SetParentWindow(nullptr);
|
component_and_ref.first->SetParentWindow(nullptr);
|
||||||
@@ -4928,7 +4941,6 @@ LuaScriptInterface::~LuaScriptInterface() {
|
|||||||
lua_gr_func_v.clear();
|
lua_gr_func_v.clear();
|
||||||
lua_cd_func_v.clear();
|
lua_cd_func_v.clear();
|
||||||
lua_close(l);
|
lua_close(l);
|
||||||
delete legacy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NOHTTP
|
#ifndef NOHTTP
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "CommandInterface.h"
|
#include "CommandInterface.h"
|
||||||
#include "gui/game/GameControllerEvents.h"
|
#include "gui/game/GameControllerEvents.h"
|
||||||
|
#include "TPTScriptInterface.h"
|
||||||
#include "simulation/StructProperty.h"
|
#include "simulation/StructProperty.h"
|
||||||
#include "simulation/ElementDefs.h"
|
#include "simulation/ElementDefs.h"
|
||||||
|
|
||||||
@@ -21,16 +22,14 @@ class Tool;
|
|||||||
//Because lua only has bindings for C, we're going to have to go outside "outside" the LuaScriptInterface, this means we can only have one instance :(
|
//Because lua only has bindings for C, we're going to have to go outside "outside" the LuaScriptInterface, this means we can only have one instance :(
|
||||||
|
|
||||||
class Simulation;
|
class Simulation;
|
||||||
class TPTScriptInterface;
|
|
||||||
class LuaComponent;
|
class LuaComponent;
|
||||||
|
|
||||||
class LuaScriptInterface: public CommandInterface
|
class LuaScriptInterface: public TPTScriptInterface
|
||||||
{
|
{
|
||||||
int luacon_mousex, luacon_mousey, luacon_mousebutton;
|
int luacon_mousex, luacon_mousey, luacon_mousebutton;
|
||||||
ByteString luacon_selectedl, luacon_selectedr, luacon_selectedalt, luacon_selectedreplace;
|
ByteString luacon_selectedl, luacon_selectedr, luacon_selectedalt, luacon_selectedreplace;
|
||||||
bool luacon_mousedown;
|
bool luacon_mousedown;
|
||||||
bool currentCommand;
|
bool currentCommand;
|
||||||
TPTScriptInterface * legacy;
|
|
||||||
int textInputRefcount;
|
int textInputRefcount;
|
||||||
|
|
||||||
// signs
|
// signs
|
||||||
@@ -222,8 +221,6 @@ public:
|
|||||||
virtual ~LuaScriptInterface();
|
virtual ~LuaScriptInterface();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern LuaScriptInterface *luacon_ci;
|
|
||||||
|
|
||||||
void tpt_lua_pushByteString(lua_State *L, const ByteString &str);
|
void tpt_lua_pushByteString(lua_State *L, const ByteString &str);
|
||||||
void tpt_lua_pushString(lua_State *L, const String &str);
|
void tpt_lua_pushString(lua_State *L, const String &str);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user