1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Fixed the QTM __index method

This commit is contained in:
Firew0lf 2015-09-12 12:05:04 +02:00
parent 848fe42096
commit 9d8c499afc

View file

@ -5,10 +5,14 @@
#include <lapi.h>
#include <lauxlib.h>
#include <string.h>
typedef struct {
qtmHeadtrackingInfo *info;
} qtm_userdata;
static const struct luaL_Reg qtm_methods[];
static int qtm_init(lua_State *L) {
Result ret = qtmInit();
if (ret) {
@ -54,6 +58,7 @@ static int qtm_checkHeadFullyDetected(lua_State *L) {
static int qtm___index(lua_State *L) {
qtm_userdata *info = luaL_checkudata(L, 1, "LQTM");
if (lua_isinteger(L, 2)) { // index
lua_Integer index = luaL_checkinteger(L, 2);
index = index - 1; // Lua index begins at 1
if (index > 3 || index < 0) {
@ -64,8 +69,19 @@ static int qtm___index(lua_State *L) {
lua_pushnumber(L, info->info->coords0[index].x);
lua_pushnumber(L, info->info->coords0[index].y);
return 2;
} else if (lua_isstring(L, 2)) { //method
const char *mname = luaL_checkstring(L, 2);
for (u8 i=0;qtm_methods[i].name;i++) {
if (strcmp(qtm_methods[i].name, mname) == 0) {
lua_pushcfunction(L, qtm_methods[i].func);
return 1;
}
}
}
lua_pushnil(L);
return 1;
}
static int qtm_convertCoordToScreen(lua_State *L) {