Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions rts/Lua/LuaHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "Sim/Units/UnitDef.h"
#include "Sim/Weapons/Weapon.h"
#include "Sim/Weapons/WeaponDef.h"
#include "System/FileSystem/FileHandler.h"
#include "System/FileSystem/VFSModes.h"
#include "System/creg/SerializeLuaState.h"
#include "System/Config/ConfigHandler.h"
#include "System/EventHandler.h"
Expand All @@ -56,6 +58,8 @@

#include "LuaInclude.h"

#include "lib/luasocket/src/luasocket.h"

#include <SDL_keyboard.h>
#include <SDL_keycode.h>
#include <SDL_mouse.h>
Expand Down Expand Up @@ -549,6 +553,28 @@ bool CLuaHandle::LoadCode(lua_State* L, std::string code, const string& debug)
}


void CLuaHandle::InitLuaSocket(lua_State* L)
{
RECOIL_DETAILED_TRACY_ZONE;

const std::string filename = "LuaSocket/socket.lua";
CFileHandler f(filename, SPRING_VFS_BASE);
if (!f.FileExists()) {
LOG_L(L_ERROR, "Error loading %s (file does not exist)", filename.c_str());
return;
}

LUA_OPEN_LIB(L, luaopen_socket_core);

std::string code;
if (f.LoadStringData(code)) {
LoadCode(L, std::move(code), filename);
} else {
LOG_L(L_ERROR, "Error loading %s", filename.c_str());
}
}


int CLuaHandle::LoadStringData(lua_State* L)
{
RECOIL_DETAILED_TRACY_ZONE;
Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ class CLuaHandle : public CEventClient
bool AddBasicCalls(lua_State* L);
bool AddCommonModules(lua_State* L);
bool LoadCode(lua_State* L, std::string code, const std::string& debug);
void InitLuaSocket(lua_State* L);
static bool AddEntriesToTable(lua_State* L, const char* name, bool (*entriesFunc)(lua_State*));

/// returns error code and sets traceback on error
Expand Down
17 changes: 0 additions & 17 deletions rts/Lua/LuaMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "System/FileSystem/FileHandler.h"
#include "System/FileSystem/FileSystem.h"
#include "System/Threading/SpringThreading.h"
#include "lib/luasocket/src/luasocket.h"
#include "LuaUI.h"

#include "System/Misc/TracyDefs.h"
Expand Down Expand Up @@ -134,22 +133,6 @@ string CLuaMenu::LoadFile(const string& name) const
}


void CLuaMenu::InitLuaSocket(lua_State* L) {
RECOIL_DETAILED_TRACY_ZONE;
std::string code;
std::string filename = "socket.lua";
CFileHandler f(filename);

LUA_OPEN_LIB(L, luaopen_socket_core);

if (f.LoadStringData(code)) {
LoadCode(L, std::move(code), filename);
} else {
LOG_L(L_ERROR, "Error loading %s", filename.c_str());
}
}


bool CLuaMenu::RemoveSomeOpenGLFunctions(lua_State* L)
{
// remove some spring opengl functions that don't work preloading
Expand Down
1 change: 0 additions & 1 deletion rts/Lua/LuaMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class CLuaMenu : public CLuaHandle
static bool LoadUnsyncedReadFunctions(lua_State* L);
static bool RemoveSomeOpenGLFunctions(lua_State* L);
static bool PushGameVersion(lua_State* L);
void InitLuaSocket(lua_State* L);
protected:
QueuedAction queuedAction;
};
Expand Down
20 changes: 0 additions & 20 deletions rts/Lua/LuaUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include "System/Config/ConfigHandler.h"
#include "System/StringUtil.h"
#include "System/Threading/SpringThreading.h"
#include "lib/luasocket/src/luasocket.h"

#include <cctype>

Expand Down Expand Up @@ -207,25 +206,6 @@ GetWatchDef(Explosion)
SetWatchDef(Explosion)


void CLuaUI::InitLuaSocket(lua_State* L) {
std::string code;
std::string filename = "LuaSocket/socket.lua";
CFileHandler f(filename, SPRING_VFS_BASE);

if (!f.FileExists()) {
LOG_L(L_ERROR, "Error loading %s (file does not exist)", filename.c_str());
return;
}

LUA_OPEN_LIB(L, luaopen_socket_core);

if (f.LoadStringData(code)) {
LoadCode(L, std::move(code), filename);
} else {
LOG_L(L_ERROR, "Error loading %s", filename.c_str());
}
}

string CLuaUI::LoadFile(const string& name, const std::string& mode) const
{
CFileHandler f(name, mode);
Expand Down
1 change: 0 additions & 1 deletion rts/Lua/LuaUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class CLuaUI : public CLuaHandle
string LoadFile(const string& name, const std::string& mode) const;

bool LoadCFunctions(lua_State* L);
void InitLuaSocket(lua_State* L);

bool BuildCmdDescTable(lua_State* L, const vector<SCommandDescription>& cmds);
bool GetLuaIntMap(lua_State* L, int index, spring::unordered_map<int, int>& intList);
Expand Down
Loading