#1647 - getCurve exported to the Lua interpreter
This commit is contained in:
@@ -810,6 +810,8 @@ static int luaModelGetMix(lua_State *L)
|
|||||||
lua_pushtableinteger(L, "weight", mix->weight);
|
lua_pushtableinteger(L, "weight", mix->weight);
|
||||||
lua_pushtableinteger(L, "offset", mix->offset);
|
lua_pushtableinteger(L, "offset", mix->offset);
|
||||||
lua_pushtableinteger(L, "switch", mix->swtch);
|
lua_pushtableinteger(L, "switch", mix->swtch);
|
||||||
|
lua_pushtableinteger(L, "curveType", mix->curve.type);
|
||||||
|
lua_pushtableinteger(L, "curveValue", mix->curve.value);
|
||||||
lua_pushtableinteger(L, "multiplex", mix->mltpx);
|
lua_pushtableinteger(L, "multiplex", mix->mltpx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -851,6 +853,12 @@ static int luaModelInsertMix(lua_State *L)
|
|||||||
else if (!strcmp(key, "switch")) {
|
else if (!strcmp(key, "switch")) {
|
||||||
mix->swtch = luaL_checkinteger(L, -1);
|
mix->swtch = luaL_checkinteger(L, -1);
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(key, "curveType")) {
|
||||||
|
mix->curve.type = luaL_checkinteger(L, -1);
|
||||||
|
}
|
||||||
|
else if (!strcmp(key, "curveValue")) {
|
||||||
|
mix->curve.value = luaL_checkinteger(L, -1);
|
||||||
|
}
|
||||||
else if (!strcmp(key, "multiplex")) {
|
else if (!strcmp(key, "multiplex")) {
|
||||||
mix->mltpx = luaL_checkinteger(L, -1);
|
mix->mltpx = luaL_checkinteger(L, -1);
|
||||||
}
|
}
|
||||||
@@ -939,6 +947,48 @@ static int luaModelSetLogicalSwitch(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int luaModelGetCurve(lua_State *L)
|
||||||
|
{
|
||||||
|
int idx = luaL_checkunsigned(L, 1);
|
||||||
|
if (idx < MAX_CURVES) {
|
||||||
|
CurveInfo & curveInfo = g_model.curves[idx];
|
||||||
|
lua_newtable(L);
|
||||||
|
lua_pushtablezstring(L, "name", g_model.curveNames[idx]);
|
||||||
|
lua_pushtableinteger(L, "type", curveInfo.type);
|
||||||
|
lua_pushtableboolean(L, "smooth", curveInfo.smooth);
|
||||||
|
lua_pushtableinteger(L, "points", curveInfo.points+5);
|
||||||
|
lua_pushstring(L, "y");
|
||||||
|
lua_newtable(L);
|
||||||
|
int8_t * point = curveAddress(idx);
|
||||||
|
for (int i=0; i<curveInfo.points+5; i++) {
|
||||||
|
lua_pushinteger(L, i);
|
||||||
|
lua_pushinteger(L, *point++);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
}
|
||||||
|
lua_settable(L, -3);
|
||||||
|
if (curveInfo.type == CURVE_TYPE_CUSTOM) {
|
||||||
|
lua_pushstring(L, "x");
|
||||||
|
lua_newtable(L);
|
||||||
|
lua_pushinteger(L, 0);
|
||||||
|
lua_pushinteger(L, 0);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
for (int i=0; i<curveInfo.points+3; i++) {
|
||||||
|
lua_pushinteger(L, i+1);
|
||||||
|
lua_pushinteger(L, *point++);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
}
|
||||||
|
lua_pushinteger(L, curveInfo.points+4);
|
||||||
|
lua_pushinteger(L, 100);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int luaModelGetCustomFunction(lua_State *L)
|
static int luaModelGetCustomFunction(lua_State *L)
|
||||||
{
|
{
|
||||||
int idx = luaL_checkunsigned(L, 1);
|
int idx = luaL_checkunsigned(L, 1);
|
||||||
@@ -1412,6 +1462,7 @@ const luaL_Reg modelLib[] = {
|
|||||||
{ "setLogicalSwitch", luaModelSetLogicalSwitch },
|
{ "setLogicalSwitch", luaModelSetLogicalSwitch },
|
||||||
{ "getCustomFunction", luaModelGetCustomFunction },
|
{ "getCustomFunction", luaModelGetCustomFunction },
|
||||||
{ "setCustomFunction", luaModelSetCustomFunction },
|
{ "setCustomFunction", luaModelSetCustomFunction },
|
||||||
|
{ "getCurve", luaModelGetCurve },
|
||||||
{ "getOutput", luaModelGetOutput },
|
{ "getOutput", luaModelGetOutput },
|
||||||
{ "setOutput", luaModelSetOutput },
|
{ "setOutput", luaModelSetOutput },
|
||||||
{ "getGlobalVariable", luaModelGetGlobalVariable },
|
{ "getGlobalVariable", luaModelGetGlobalVariable },
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "lstate.h"
|
#include "lstate.h"
|
||||||
#include "lstring.h"
|
#include "lstring.h"
|
||||||
#include "ltable.h"
|
#include "ltable.h"
|
||||||
|
#include "lrotable.h"
|
||||||
#include "ltm.h"
|
#include "ltm.h"
|
||||||
#include "lundump.h"
|
#include "lundump.h"
|
||||||
#include "lvm.h"
|
#include "lvm.h"
|
||||||
@@ -621,9 +622,19 @@ LUA_API void lua_getglobal (lua_State *L, const char *var) {
|
|||||||
Table *reg = hvalue(&G(L)->l_registry);
|
Table *reg = hvalue(&G(L)->l_registry);
|
||||||
const TValue *gt; /* global table */
|
const TValue *gt; /* global table */
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
|
|
||||||
setsvalue2s(L, L->top++, luaS_new(L, var));
|
lu_byte keytype;
|
||||||
luaV_gettable(L, gt, L->top - 1, L->top - 1);
|
luaR_result res = luaR_findglobal(var, &keytype);
|
||||||
|
if (res != 0) {
|
||||||
|
setsvalue2s(L, L->top++, luaS_new(L, var));
|
||||||
|
setlfvalue(L->top - 1, (void*)(size_t)res)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
|
||||||
|
setsvalue2s(L, L->top++, luaS_new(L, var));
|
||||||
|
luaV_gettable(L, gt, L->top - 1, L->top - 1);
|
||||||
|
}
|
||||||
|
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@
|
|||||||
CURVE_TYPE_CUSTOM,
|
CURVE_TYPE_CUSTOM,
|
||||||
CURVE_TYPE_LAST = CURVE_TYPE_CUSTOM
|
CURVE_TYPE_LAST = CURVE_TYPE_CUSTOM
|
||||||
};
|
};
|
||||||
PACK(typedef struct t_CurveInfo {
|
PACK(typedef struct {
|
||||||
uint8_t type:3;
|
uint8_t type:3;
|
||||||
uint8_t smooth:1;
|
uint8_t smooth:1;
|
||||||
uint8_t spare:4;
|
uint8_t spare:4;
|
||||||
@@ -479,7 +479,7 @@ enum CurveRefType {
|
|||||||
CURVE_REF_FUNC,
|
CURVE_REF_FUNC,
|
||||||
CURVE_REF_CUSTOM
|
CURVE_REF_CUSTOM
|
||||||
};
|
};
|
||||||
PACK(typedef struct t_CurveRef {
|
PACK(typedef struct {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
int8_t value;
|
int8_t value;
|
||||||
}) CurveRef;
|
}) CurveRef;
|
||||||
|
|||||||
Reference in New Issue
Block a user