scripting.h fix + input library
This commit is contained in:
@@ -127,13 +127,14 @@ void lua::LuaState::createLibs() {
|
||||
openlib("core", corelib, 0);
|
||||
openlib("file", filelib, 0);
|
||||
openlib("gui", guilib, 0);
|
||||
openlib("input", inputlib, 0);
|
||||
openlib("inventory", inventorylib, 0);
|
||||
openlib("item", itemlib, 0);
|
||||
openlib("json", jsonlib, 0);
|
||||
openlib("pack", packlib, 0);
|
||||
openlib("player", playerlib, 0);
|
||||
openlib("time", timelib, 0);
|
||||
openlib("world", worldlib, 0);
|
||||
openlib("json", jsonlib, 0);
|
||||
|
||||
addfunc("print", lua_wrap_errors<l_print>);
|
||||
}
|
||||
@@ -426,6 +427,17 @@ void lua::LuaState::removeEnvironment(int id) {
|
||||
logger.debug() << "removed environment " << envName(id);
|
||||
}
|
||||
|
||||
bool lua::LuaState::emit_event(const std::string &name, std::function<int(lua::LuaState *)> args) {
|
||||
getglobal("events");
|
||||
getfield("emit");
|
||||
pushstring(name);
|
||||
callNoThrow(args(this) + 1);
|
||||
bool result = toboolean(-1);
|
||||
pop(2);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void lua::LuaState::dumpStack() {
|
||||
int top = gettop();
|
||||
for (int i = 1; i <= top; i++) {
|
||||
|
||||
@@ -67,6 +67,7 @@ namespace lua {
|
||||
int createEnvironment(int parent);
|
||||
void removeEnvironment(int id);
|
||||
const std::string storeAnonymous();
|
||||
bool emit_event(const std::string& name, std::function<int(lua::LuaState*)> args=[](auto*){return 0;});
|
||||
|
||||
void dumpStack();
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ extern const luaL_Reg playerlib [];
|
||||
extern const luaL_Reg timelib [];
|
||||
extern const luaL_Reg worldlib [];
|
||||
extern const luaL_Reg jsonlib [];
|
||||
|
||||
extern const luaL_Reg inputlib [];
|
||||
|
||||
// Lua Overrides
|
||||
extern int l_print(lua_State* L);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "lua_commons.h"
|
||||
#include "api_lua.h"
|
||||
#include "LuaState.h"
|
||||
|
||||
#include "../../../engine.h"
|
||||
#include "../../../files/settings_io.hpp"
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "api_lua.h"
|
||||
#include "lua_commons.h"
|
||||
#include "../scripting.h"
|
||||
|
||||
#include "../../../window/input.h"
|
||||
#include "../../../window/Events.h"
|
||||
#include "../../../frontend/screens/Screen.hpp"
|
||||
#include "../../../engine.h"
|
||||
|
||||
#include "LuaState.h"
|
||||
|
||||
namespace scripting {
|
||||
extern lua::LuaState* state;
|
||||
}
|
||||
|
||||
static int l_keycode(lua_State* L) {
|
||||
const char* name = lua_tostring(L, 1);
|
||||
lua_pushinteger(L, static_cast<int>(input_util::keycode_from(name)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg inputlib [] = {
|
||||
{"keycode", lua_wrap_errors<l_keycode>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user