Modules
This commit is contained in:
65
src/script/module/moduleinput.h
Normal file
65
src/script/module/moduleinput.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/scriptcontext.h"
|
||||
#include "input/input.h"
|
||||
|
||||
int32_t moduleInputBind(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be NULL");
|
||||
|
||||
// Requires action and button.
|
||||
if(!lua_isstring(L, 1)) {
|
||||
luaL_error(L, "inputBind: Expected button name as first argument");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!lua_isstring(L, 2)) {
|
||||
luaL_error(L, "inputBind: Expected action name as second argument");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char_t *strBtn = lua_tostring(L, 1);
|
||||
const char_t *strAct = lua_tostring(L, 2);
|
||||
|
||||
// Get button by name
|
||||
inputbutton_t btn = inputButtonGetByName(strBtn);
|
||||
if(btn.type == INPUT_BUTTON_TYPE_NONE) {
|
||||
printf("inputBind: Unknown button name '%s'\n", strBtn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get action by name
|
||||
inputaction_t act = inputActionGetByName(strAct);
|
||||
if(act == INPUT_ACTION_COUNT) {
|
||||
printf("inputBind: Unknown action name '%s'\n", strAct);
|
||||
return 0;
|
||||
}
|
||||
|
||||
inputBind(btn, act);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void moduleInput(scriptcontext_t *context) {
|
||||
assertNotNull(context, "Script context cannot be NULL");
|
||||
|
||||
// Input values.
|
||||
scriptContextExec(context,
|
||||
#if INPUT_KEYBOARD == 1
|
||||
"INPUT_KEYBOARD = true\n"
|
||||
#endif
|
||||
#if INPUT_GAMEPAD == 1
|
||||
"INPUT_GAMEPAD = true\n"
|
||||
#endif
|
||||
#if INPUT_SDL2 == 1
|
||||
"INPUT_SDL2 = true\n"
|
||||
#endif
|
||||
);
|
||||
|
||||
// Bind methods
|
||||
scriptContextRegFunc(context, "inputBind", moduleInputBind);
|
||||
}
|
||||
Reference in New Issue
Block a user