Skip to content

Commit

Permalink
Initial lua support
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyuu17 committed Jul 8, 2024
1 parent 9b81c03 commit 2199b6a
Show file tree
Hide file tree
Showing 11 changed files with 4,130 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "extern/godot-cpp"]
path = extern/godot-cpp
url = https://github.com/godotengine/godot-cpp.git
[submodule "extern/lua"]
path = extern/lua
url = https://github.com/Lyuu17/lua.git
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ add_subdirectory(extern)
target_link_libraries( ${PROJECT_NAME}
PRIVATE
godot-cpp
lua
)
3 changes: 3 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ set_target_properties(godot-cpp
PROPERTIES
CXX_VISIBILITY_PRESET hidden # visibility needs to be the same as the main library
)

# lua
add_subdirectory(lua)
1 change: 1 addition & 0 deletions extern/lua
Submodule lua added at 039d13
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ target_sources(${PROJECT_NAME}
"SWBF2/Native/Chunks/UcfbChunk.cpp"
"SWBF2/Native/Chunks/WorldChunk.cpp"
"SWBF2/Native/Models/Model.cpp"
"SWBF2/Native/Scripting/Lua/LuaCallbacks.cpp"
"SWBF2/Native/Scripting/Lua/ScriptCB.cpp"
"SWBF2/Native/Texture/Texture.cpp"
"SWBF2/Native/Texture/TextureUtils.cpp"
"SWBF2/Native/Hashes.cpp"
Expand Down
6 changes: 6 additions & 0 deletions src/SWBF2/Native/SWBF2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace SWBF2::Native
{
lua_State *SWBF2::m_luaState;

SkyDome SWBF2::m_skyDome;

std::string SWBF2::m_curMapName;
Expand All @@ -27,6 +29,8 @@ namespace SWBF2::Native

if (!UcfbChunk::ReadUcfbFile("data/_lvl_pc/common.lvl"))
throw std::runtime_error{ "failed to load common.lvl from game directory" };

m_luaState = lua_open();
}

void SWBF2::Reset()
Expand All @@ -41,6 +45,8 @@ namespace SWBF2::Native
m_models.clear();
m_tex.clear();
m_locl.clear();

lua_close(m_luaState);
}

bool SWBF2::LoadLevelFile(const std::string &levelname)
Expand Down
4 changes: 4 additions & 0 deletions src/SWBF2/Native/SWBF2.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

#pragma once

#include <lua.h>

#include "Native/Models/Model.hpp"
#include "Native/Texture/Texture.hpp"
#include "Native/Objects/ObjectDefinition.hpp"
Expand Down Expand Up @@ -71,6 +73,8 @@ namespace SWBF2::Native
std::unordered_map<TeamClassType, TeamClass> m_classes;
};

static lua_State *m_luaState;

static SkyDome m_skyDome;

static std::string m_curMapName;
Expand Down
608 changes: 608 additions & 0 deletions src/SWBF2/Native/Scripting/Lua/LuaCallbacks.cpp

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/SWBF2/Native/Scripting/Lua/LuaCallbacks.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#pragma once

#include <lua.h>

namespace SWBF2::Native::Scripting::Lua
{
class LuaCallbacks {
public:
static void Init();
static void RegisterCallback(const char *name, lua_CFunction func);
};
}
Loading

0 comments on commit 2199b6a

Please sign in to comment.