2 #include "cython/vapoursynth_api.h"
4 struct VSScript
: public VPYScriptExport
{
7 int preInitialized
= 0;
8 int initializationCount
= 0;
10 PyThreadState
*ts
= NULL
;
13 VS_API(int) vseval_init(void) {
14 if (initializationCount
== 0) {
15 preInitialized
= Py_IsInitialized();
18 PyGILState_STATE s
= PyGILState_Ensure();
19 int result
= import_vapoursynth();
23 ts
= PyEval_SaveThread();
25 initializationCount
++;
26 return initializationCount
;
29 VS_API(int) vseval_finalize(void) {
30 initializationCount
--;
31 if (initializationCount
)
32 return initializationCount
;
33 //PyEval_RestoreThread(ts);
34 //PyGILState_Release(s);
35 //if (!preInitialized)
40 VS_API(int) vseval_evaluateScript(VSScript
**handle
, const char *script
, const char *errorFilename
) {
41 if (*handle
== NULL
) {
42 *handle
= new VSScript();
43 (*handle
)->pyenvdict
= NULL
;
44 (*handle
)->errstr
= NULL
;
45 (*handle
)->id
= scriptId
++;
47 return vpy_evaluateScript(*handle
, script
, errorFilename
);
50 VS_API(void) vseval_freeScript(VSScript
*handle
) {
52 vpy_freeScript(handle
);
57 VS_API(const char *) vseval_getError(VSScript
*handle
) {
58 return vpy_getError(handle
);
61 VS_API(VSNodeRef
*) vseval_getOutput(VSScript
*handle
, int index
) {
62 return vpy_getOutput(handle
, index
);
65 VS_API(void) vseval_clearOutput(VSScript
*handle
, int index
) {
66 vpy_clearOutput(handle
, index
);
69 VS_API(VSCore
*) vseval_getCore(VSScript
*handle
) {
70 return vpy_getCore(handle
);
73 VS_API(const VSAPI
*) vseval_getVSApi(void) {
74 return vpy_getVSApi();
77 VS_API(int) vseval_getVariable(VSScript
*handle
, const char *name
, VSMap
*dst
) {
78 return vpy_getVariable(handle
, name
, dst
);
81 VS_API(void) vseval_setVariable(VSScript
*handle
, const VSMap
*vars
) {
82 vpy_setVariable(handle
, (VSMap
*)vars
);
85 VS_API(int) vseval_clearVariable(VSScript
*handle
, const char *name
) {
86 return vpy_clearVariable(handle
, name
);
89 VS_API(void) vseval_clearEnvironment(VSScript
*handle
) {
90 vpy_clearEnvironment(handle
);