27 std::unique_lock<std::mutex> lk(
mutex_);
36 throw std::runtime_error(
getError(err));
39 auto calcMethodStr = QString(
"function calc(time, value");
42 calcMethodStr += QString(
", v%1").arg(
index);
44 calcMethodStr += QString(
")\n%1\nend").arg(
snippet().
function);
50 throw std::runtime_error(
getError(err));
57 std::vector<PlotData::Point>& points)
59 std::unique_lock<std::mutex> lk(
mutex_);
65 for (
size_t chan_index = 0; chan_index < src_data.size(); chan_index++)
68 const PlotData* chan_data = src_data[chan_index];
72 value = chan_data->
at(index).y;
76 value = std::numeric_limits<double>::quiet_NaN();
99 result =
_lua_function(old_point.x, v[0], v[1], v[2], v[3], v[4]);
102 result =
_lua_function(old_point.x, v[0], v[1], v[2], v[3], v[4], v[5]);
105 result =
_lua_function(old_point.x, v[0], v[1], v[2], v[3], v[4], v[5], v[6]);
108 result =
_lua_function(old_point.x, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);
111 result =
_lua_function(old_point.x, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7],
115 throw std::runtime_error(
"Lua Engine: maximum number of additional data sources is " 122 throw std::runtime_error(
getError(err));
128 new_point.x = result.
get<
double>(0);
129 new_point.y = result.
get<
double>(1);
130 points.push_back(new_point);
135 new_point.x = old_point.x;
136 new_point.y = result.
get<
double>(0);
137 points.push_back(new_point);
141 static std::vector<std::array<double, 2>> multi_samples;
142 multi_samples.clear();
144 multi_samples = result.
get<std::vector<std::array<double, 2>>>(0);
146 for (std::array<double, 2> sample : multi_samples)
151 points.push_back(point);
156 throw std::runtime_error(
"Wrong return object: expecting either a single value, " 157 "two values (time, value) " 158 "or an array of two-sized arrays (time, value)");
172 auto parts = QString(err.
what()).split(
":");
174 if (parts.size() < 3)
179 bool is_function = parts[0].contains(
"[string \"function calc(time,");
180 out = is_function ?
"[Function]: line " :
"[Global]: line ";
182 int line_num = parts[1].toInt();
187 out += std::to_string(line_num) +
": ";
188 out += parts[2].toStdString();
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
std::string getError(sol::error err)
protected_function_result safe_script(lua_Reader reader, void *data, Fx &&on_error, const std::string &chunkname=detail::default_chunk_name(), load_mode mode=load_mode::any)
std::vector< double > _chan_values
LuaCustomFunction(SnippetData snippet={})
sol::protected_function _lua_function
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
int getIndexFromX(double x) const
type get_type(int index_offset=0) const noexcept
void initEngine() override
bool valid() const noexcept
int return_count() const noexcept
void calculatePoints(const std::vector< const PlotData *> &channels_data, size_t point_index, std::vector< PlotData::Point > &points) override
const SnippetData & snippet() const
typename PlotDataBase< double, Value >::Point Point
const Point & at(size_t index) const
virtual const char * what() const noexcept override
void open_libraries(Args &&... args)
QStringList additional_sources
decltype(auto) get(int index_offset=0) const