15 auto calcMethodStr = QString(
"function calc(time, value");
19 calcMethodStr += QString(
", v%1").arg(index);
22 calcMethodStr += QString(
")\n%1\nend").arg(
snippet().
function);
23 _lua_engine->safe_script(calcMethodStr.toStdString());
29 const std::vector<const PlotData*>& channels_data,
36 for (
size_t chan_index = 0; chan_index < channels_data.size(); chan_index++)
39 const auto& chan_data = channels_data[chan_index];
40 int index = chan_data->getIndexFromX(old_point.x);
43 value = chan_data->at(index).y;
47 value = std::numeric_limits<double>::quiet_NaN();
53 new_point.x = old_point.x;
72 v[0], v[1], v[2], v[3]);
75 v[0], v[1], v[2], v[3], v[4]);
78 v[0], v[1], v[2], v[3], v[4], v[5]);
81 v[0], v[1], v[2], v[3], v[4], v[5], v[6]);
84 v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);
87 throw std::runtime_error(
"Lua Engine : maximum number of additional source is 8");
92 throw std::runtime_error(
"Lua Engine : invalid function (missing variable?)");
97 new_point.x = result.
get<
double>(0);
98 new_point.y = result.
get<
double>(1);
102 new_point.y = result.
get<
double>(0);
106 throw std::runtime_error(
"Lua Engine : return either a single value " 107 "or an array with size 2 (time, value)");
enum MQTTPropertyCodes value
LuaCustomFunction(const SnippetData &snippet)
const Point & at(size_t index) const
std::vector< double > _chan_values
sol::protected_function _lua_function
void initEngine() override
bool valid() const noexcept
PlotData::Point calculatePoint(const PlotData &src_data, const std::vector< const PlotData * > &channels_data, size_t point_index) override
int return_count() const noexcept
const SnippetData _snippet
std::unique_ptr< sol::state > _lua_engine
const SnippetData & snippet() const
decltype(auto) get(int index_offset=0) const
QStringList additionalSources
typename PlotDataBase< Value >::Point Point