Add struct metafield
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
#include "script/scriptcontext.h"
|
||||
#include "input/input.h"
|
||||
#include "script/scriptstruct.h"
|
||||
|
||||
int moduleInputBind(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be NULL");
|
||||
@@ -44,6 +45,19 @@ int moduleInputBind(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void moduleInputEventGetter(
|
||||
const scriptcontext_t *context,
|
||||
const char_t *key,
|
||||
const void *structPtr,
|
||||
scriptvalue_t *outValue
|
||||
) {
|
||||
if(stringCompare(key, "action") == 0) {
|
||||
outValue->type = SCRIPT_VALUE_TYPE_INT;
|
||||
outValue->value.intValue = ((const inputevent_t*)structPtr)->action;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void moduleInput(scriptcontext_t *context) {
|
||||
assertNotNull(context, "Script context cannot be NULL");
|
||||
|
||||
@@ -63,6 +77,18 @@ void moduleInput(scriptcontext_t *context) {
|
||||
#endif
|
||||
);
|
||||
|
||||
// Script structure
|
||||
scriptStructRegister(
|
||||
context,
|
||||
"input_mt",
|
||||
&moduleInputEventGetter,
|
||||
NULL
|
||||
);
|
||||
|
||||
// Events
|
||||
scriptContextRegPointer(context,"INPUT_EVENT_PRESSED",&INPUT.eventPressed);
|
||||
scriptContextRegPointer(context,"INPUT_EVENT_RELEASED",&INPUT.eventReleased);
|
||||
|
||||
// Bind methods
|
||||
scriptContextRegFunc(context, "inputBind", moduleInputBind);
|
||||
}
|
||||
Reference in New Issue
Block a user