couch/core/Input.cpp

29 lines
625 B
C++
Raw Normal View History

2021-01-13 18:51:58 -06:00
#include "Input.h"
Input::Input() {}
Input *Input::instance = nullptr;
Input *Input::GetInstance() {
if (!instance) {
instance = new Input();
}
return instance;
}
void Input::Use(Window *window){
glfwSetKeyCallback(window, (GLFWkeyfun)HandleKeys);
}
void Input::HandleKeys(Window *window, int keys, int code, int action, int mods) {
#ifdef LUA_SCRIPTING
lua_State *L = (lua_State*) glfwGetWindowUserPointer(window);
lua_getglobal(L, "onkey");
lua_pushinteger(L, keys);
lua_pushinteger(L, code);
lua_pushinteger(L, action);
lua_pushinteger(L, mods);
lua_call(L, 4, 0);
#endif // LUA_SCRIPTING
}