File: obs-script-helpers.cpp

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 (72 lines) | stat: -rw-r--r-- 1,676 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
#include "obs-script-helpers.hpp"
#include "log-helper.hpp"

#include <QFileInfo>
#include <QLibrary>

namespace advss {

static const char *libName =
#if defined(WIN32)
	"obs-scripting.dll";
#elif __APPLE__
	"obs-scripting.dylib";
#else
	"obs-scripting.so";
#endif

typedef obs_script_t *(*obs_script_create_t)(const char *, obs_data_t *);
typedef void (*obs_script_destroy_t)(obs_script_t *);

obs_script_create_t obs_script_create = nullptr;
obs_script_destroy_t obs_script_destroy = nullptr;

static bool setup()
{
	QLibrary scriptingLib(libName);

	obs_script_create =
		(obs_script_create_t)scriptingLib.resolve("obs_script_create");
	if (!obs_script_create) {
		blog(LOG_WARNING,
		     "could not resolve obs_script_create symbol!");
	}

	obs_script_destroy = (obs_script_destroy_t)scriptingLib.resolve(
		"obs_script_destroy");
	if (!obs_script_destroy) {
		blog(LOG_WARNING,
		     "could not resolve obs_script_destroy symbol!");
	}

	return true;
}
static bool setupDone = setup();

obs_script_t *CreateOBSScript(const char *path, obs_data_t *settings)
{
	if (!obs_script_create) {
		return nullptr;
	}
	return obs_script_create(path, settings);
}

void DestroyOBSScript(obs_script_t *script)
{
	if (!obs_script_destroy) {
		return;
	}
	obs_script_destroy(script);
}

std::string GetLUACompatiblePath(const std::string &path)
{
	// Can't use settingsFile here as LUA will complain if Windows style
	// paths (C:\some\path) are used.
	// QFileInfo::absoluteFilePath will convert those paths so LUA won't
	// complain. (C:/some/path)
	const QFileInfo fileInfo(QString::fromStdString(path));
	return fileInfo.absoluteFilePath().toStdString();
}

} // namespace advss