-
Notifications
You must be signed in to change notification settings - Fork 810
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
include(functions/FetchContent_MakeAvailableExcludeFromAll) | ||
|
||
set(LUA_ENABLE_TESTING OFF) | ||
set(LUA_BUILD_COMPILER OFF) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare(Lua | ||
URL https://github.com/walterschell/Lua/archive/88246d621abf7b6fba9332f49229d507f020e450.tar.gz | ||
URL_HASH MD5=03b76927cb5341ffc53bea12c37ddcca | ||
) | ||
FetchContent_MakeAvailableExcludeFromAll(Lua) | ||
|
||
if(ANDROID AND ("${ANDROID_ABI}" STREQUAL "armeabi-v7a" OR "${ANDROID_ABI}" STREQUAL "x86")) | ||
target_compile_definitions(lua_internal INTERFACE -DLUA_USE_C89) | ||
elseif(NINTENDO_3DS OR VITA OR NINTENDO_SWITCH) | ||
target_compile_definitions(lua_static PUBLIC -DLUA_USE_C89) | ||
elseif(IOS) | ||
target_compile_definitions(lua_static PUBLIC -DLUA_USE_IOS) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "utils/lua.hpp" | ||
|
||
extern "C" { | ||
#include <lauxlib.h> | ||
#include <lua.h> | ||
#include <lualib.h> | ||
} | ||
|
||
#include "plrmsg.h" | ||
|
||
namespace devilution { | ||
|
||
namespace { | ||
|
||
lua_State *LuaState; | ||
|
||
int LuaPlayerMessage(lua_State *state) | ||
{ | ||
if (lua_isstring(LuaState, 1)) { | ||
std::string msg = lua_tostring(state, 1); | ||
EventPlrMsg(msg, UiFlags::ColorRed); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
} // namespace | ||
|
||
void LuaInitialize() | ||
{ | ||
LuaState = luaL_newstate(); | ||
lua_register(LuaState, "PlayerMessage", LuaPlayerMessage); | ||
|
||
int status = luaL_dofile(LuaState, "init.lua"); | ||
if (status != LUA_OK) | ||
SDL_Log("%s", lua_tostring(LuaState, -1)); | ||
} | ||
|
||
void LuaShutdown() | ||
{ | ||
if (LuaState == nullptr) | ||
return; | ||
|
||
lua_close(LuaState); | ||
} | ||
|
||
void LuaEvent(std::string name) | ||
{ | ||
lua_getglobal(LuaState, name.c_str()); | ||
if (!lua_isfunction(LuaState, -1)) | ||
return; | ||
int status = lua_pcall(LuaState, 0, 0, 0); | ||
if (status != LUA_OK) | ||
SDL_Log("%s", lua_tostring(LuaState, -1)); | ||
} | ||
|
||
} // namespace devilution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace devilution { | ||
|
||
void LuaInitialize(); | ||
void LuaShutdown(); | ||
void LuaEvent(std::string name); | ||
|
||
} // namespace devilution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters