1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 01:35:21 +03:00

Lua setGlobalVariable / getGlobalVariable added in model library

This commit is contained in:
bsongis 2014-05-05 09:57:21 +02:00
parent 6868b69aad
commit 1466f96e51
2 changed files with 26 additions and 1 deletions

View file

@ -741,6 +741,29 @@ static int luaModelSetOutput(lua_State *L)
return 0;
}
static int luaModelGetGlobalVariable(lua_State *L)
{
int idx = luaL_checkunsigned(L, 1);
int phase = luaL_checkunsigned(L, 2);
if (phase < MAX_PHASES && idx < MAX_GVARS)
lua_pushinteger(L, g_model.phaseData[phase].gvars[idx]);
else
lua_pushnil(L);
return 1;
}
static int luaModelSetGlobalVariable(lua_State *L)
{
int idx = luaL_checkunsigned(L, 1);
int phase = luaL_checkunsigned(L, 2);
int value = luaL_checkinteger(L, 3);
if (phase < MAX_PHASES && idx < MAX_GVARS && value <= 500) {
g_model.phaseData[phase].gvars[idx] = value;
}
return 0;
}
static int luaPopupInput(lua_State *L)
{
uint8_t event = luaL_checkinteger(L, 2);
@ -849,6 +872,8 @@ static const luaL_Reg modelLib[] = {
{ "setCustomFunction", luaModelSetCustomFunction },
{ "getOutput", luaModelGetOutput },
{ "setOutput", luaModelSetOutput },
{ "getGlobalVariable", luaModelGetGlobalVariable },
{ "setGlobalVariable", luaModelSetGlobalVariable },
{ NULL, NULL } /* sentinel */
};