Phasor
3.3.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
#define PHASOR_FFI_BUILD_DLL
2
#include <
PhasorFFI.h
>
3
#include <stdio.h>
4
#include "
../../../Bindings/macOS/AppleScript.h
"
5
6
static
PhasorValue
applescript_run
(
PhasorVM
*,
int
argc,
const
PhasorValue
*argv)
7
{
8
int64_t status = -1;
9
if
(argc < 1 || !
phasor_is_string
(argv[0]))
10
{
11
return
phasor_make_int
(-1);
12
}
13
const
char
*script =
phasor_to_string
(argv[0]);
14
AppleScriptResult
result =
executeAppleScript
(script);
15
if
(result.
success
)
16
{
17
if
(result.
output
)
18
{
19
PhasorValue
ret =
phasor_make_string
(result.
output
);
20
freeAppleScriptResult
(&result);
21
return
ret;
22
}
23
24
freeAppleScriptResult
(&result);
25
return
phasor_make_int
(0);
26
}
27
else
28
{
29
if
(result.
error
)
30
{
31
puts(result.
error
);
32
}
33
PhasorValue
ret =
phasor_make_int
(result.
errorCode
);
34
freeAppleScriptResult
(&result);
35
return
ret;
36
}
37
return
phasor_make_int
(status);
38
}
39
40
PHASOR_FFI_EXPORT
void
phasor_plugin_entry
(
const
PhasorAPI
*api,
PhasorVM
*vm)
41
{
42
api->
register_function
(vm,
"applescript_run"
,
applescript_run
);
43
}
AppleScript.h
executeAppleScript
AppleScriptResult executeAppleScript(const char *script)
Definition
AppleScript.m:20
freeAppleScriptResult
void freeAppleScriptResult(AppleScriptResult *result)
Definition
AppleScript.m:54
PhasorFFI.h
phasor_is_string
static bool phasor_is_string(PhasorValue val)
Definition
PhasorFFI.h:165
phasor_to_string
static const char * phasor_to_string(PhasorValue val)
Definition
PhasorFFI.h:194
phasor_make_string
static PhasorValue phasor_make_string(const char *s)
Definition
PhasorFFI.h:131
phasor_make_int
static PhasorValue phasor_make_int(int64_t i)
Definition
PhasorFFI.h:115
PhasorVM
struct PhasorVM PhasorVM
Phasor Virtual Machine pointer.
Definition
PhasorFFI.h:59
PHASOR_FFI_EXPORT
#define PHASOR_FFI_EXPORT
Definition
PhasorFFI.h:50
applescript_run
static PhasorValue applescript_run(PhasorVM *, int argc, const PhasorValue *argv)
Definition
main.c:6
phasor_plugin_entry
PHASOR_FFI_EXPORT void phasor_plugin_entry(const PhasorAPI *api, PhasorVM *vm)
The one and only entry point for a Phasor plugin.
Definition
main.c:40
AppleScriptResult
Definition
AppleScript.h:12
AppleScriptResult::errorCode
int errorCode
Definition
AppleScript.h:16
AppleScriptResult::output
char * output
Definition
AppleScript.h:14
AppleScriptResult::success
int success
Definition
AppleScript.h:13
AppleScriptResult::error
char * error
Definition
AppleScript.h:15
PhasorAPI
The collection of API functions that the Phasor host provides to the plugin.
Definition
PhasorFFI.h:211
PhasorAPI::register_function
PhasorRegisterFunction register_function
Registers a native C function with the given name.
Definition
PhasorFFI.h:213
PhasorValue
Represents a value in the Phasor VM.
Definition
PhasorFFI.h:79
src
Executable
Bindings
macOS
main.c
Generated by
1.16.1