File: inline-script.hpp

package info (click to toggle)
obs-advanced-scene-switcher 1.31.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,252 kB
  • sloc: xml: 297,593; cpp: 142,370; python: 387; sh: 189; ansic: 170; makefile: 31
file content (76 lines) | stat: -rw-r--r-- 1,689 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include "obs-script-helpers.hpp"
#include "variable-text-edit.hpp"

#include <memory>
#include <optional>
#include <string>
#include <string_view>

#include <obs-data.h>

namespace advss {

class InlineScript {
public:
	InlineScript();
	InlineScript(const InlineScript &);

	enum Type { INLINE, FILE };

	void Save(obs_data_t *) const;
	void Load(obs_data_t *);

	void SetType(Type);
	Type GetType() const { return _type; }
	void SetLanguage(obs_script_lang);
	obs_script_lang GetLanguage() const { return _language; }
	void SetText(const std::string &);
	const StringVariable &GetText() const;
	void SetPath(const std::string &);
	const std::string &GetPath() const { return _file; }

	bool Run();

	void ResolveVariablesToFixedValues();

private:
	void Setup();
	void SetupFile();
	void SetupInline();
	std::string GetID() const;

	Type _type = INLINE;
	obs_script_lang _language = OBS_SCRIPT_LANG_PYTHON;
	std::string _file;
	StringVariable _textPython = _defaultPythonScript.data();
	StringVariable _textLUA = _defaultLUAScript.data();
	std::string _lastResolvedText;
	std::string _lastPath;
	std::string _fileId;
	const uint64_t _instanceId;

	struct ScriptDeleter {
		void operator()(obs_script_t *);
		std::string tempScriptPath;
	};
	std::unique_ptr<obs_script_t, ScriptDeleter> _script;

	static std::atomic_uint64_t _instanceIdCounter;
	static const std::string_view _defaultPythonScript;
	static const std::string_view _defaultLUAScript;
};

class ScriptEditor : public VariableTextEdit {
	Q_OBJECT
public:
	ScriptEditor(QWidget *parent);

signals:
	void ScriptChanged();

private:
	bool eventFilter(QObject *obj, QEvent *event) override;
};

} // namespace advss