2023-04-04 15:17:37 +00:00
|
|
|
#pragma once
|
|
|
|
#include <JuceHeader.h>
|
2023-12-20 13:27:22 +00:00
|
|
|
#include <regex>
|
2023-04-04 15:17:37 +00:00
|
|
|
#include "../shape/Shape.h"
|
|
|
|
|
2023-12-20 17:13:38 +00:00
|
|
|
class ErrorListener {
|
|
|
|
public:
|
|
|
|
virtual void onError(int lineNumber, juce::String error) = 0;
|
|
|
|
};
|
|
|
|
|
2023-04-04 15:17:37 +00:00
|
|
|
struct lua_State;
|
|
|
|
class LuaParser {
|
|
|
|
public:
|
2023-12-20 17:13:38 +00:00
|
|
|
LuaParser(juce::String script, std::function<void(int, juce::String)> errorCallback, juce::String fallbackScript = "return { 0.0, 0.0 }");
|
2023-04-04 15:17:37 +00:00
|
|
|
~LuaParser();
|
|
|
|
|
2023-07-21 16:42:29 +00:00
|
|
|
std::vector<float> run();
|
2023-07-04 19:47:54 +00:00
|
|
|
void setVariable(juce::String variableName, double value);
|
2023-09-14 19:21:08 +00:00
|
|
|
bool isFunctionValid();
|
|
|
|
juce::String getScript();
|
2023-12-20 17:13:38 +00:00
|
|
|
void addErrorListener(ErrorListener* listener);
|
|
|
|
void removeErrorListener(ErrorListener* listener);
|
2023-07-04 13:58:36 +00:00
|
|
|
|
2023-04-04 15:17:37 +00:00
|
|
|
private:
|
2023-09-14 19:21:08 +00:00
|
|
|
void reset(juce::String script);
|
2023-12-20 17:13:38 +00:00
|
|
|
void reportError(const char* error);
|
2023-07-01 14:29:53 +00:00
|
|
|
void parse();
|
2023-07-04 13:58:36 +00:00
|
|
|
|
2023-09-11 20:28:34 +00:00
|
|
|
static int panic(lua_State* L);
|
|
|
|
|
2023-07-01 14:29:53 +00:00
|
|
|
int functionRef = -1;
|
2023-12-20 17:13:38 +00:00
|
|
|
bool usingFallbackScript = false;
|
2023-04-04 15:17:37 +00:00
|
|
|
long step = 1;
|
2023-09-14 19:21:08 +00:00
|
|
|
lua_State* L = nullptr;
|
2023-04-04 15:17:37 +00:00
|
|
|
juce::String script;
|
2023-09-14 19:21:08 +00:00
|
|
|
juce::String fallbackScript;
|
2023-07-04 13:58:36 +00:00
|
|
|
std::atomic<bool> updateVariables = false;
|
2023-07-04 19:47:54 +00:00
|
|
|
juce::SpinLock variableLock;
|
2023-07-04 13:58:36 +00:00
|
|
|
std::vector<juce::String> variableNames;
|
|
|
|
std::vector<double> variables;
|
2023-12-20 17:13:38 +00:00
|
|
|
std::function<void(int, juce::String)> errorCallback;
|
2023-04-04 15:17:37 +00:00
|
|
|
};
|