summaryrefslogtreecommitdiffstats
path: root/src/livecode/api/context.cpp
blob: f5da3f7cd1eef3c1f5914520bfa1106b48c7e201 (plain)
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
#include "livecode/api/api.h"

namespace Inkscape {
namespace Livecode {

static Context *_context = nullptr;

Context &ctx() {
    if (!_context) {
        janet_panic("Livecode Context uninitialized!!");
    }

    return *_context;
}

extern "C" Janet cfun_input_point(int32_t argc, Janet *argv) {
    janet_fixarity(argc, 2);
    ctx().input_point(janet_getcstring(argv, 0),
                      &janet_unwrap_point(argv[1]));
    return janet_wrap_nil();
}

extern "C" Janet cfun_input_line(int32_t argc, Janet *argv) {
    janet_fixarity(argc, 3);
    ctx().input_line(janet_getcstring(argv, 0),
                     &janet_unwrap_point(argv[1]),
                     &janet_unwrap_point(argv[2]));
    return janet_wrap_nil();
}

extern "C" Janet cfun_input_arrow(int32_t argc, Janet *argv) {
    janet_fixarity(argc, 3);
    ctx().input_arrow(janet_getcstring(argv, 0),
                      &janet_unwrap_point(argv[1]),
                      &janet_unwrap_point(argv[2]));
    return janet_wrap_nil();
}

const JanetReg it_cfuns[] = {
    {
        "input/point", cfun_input_point,
        "(input/point id p)\n\nMake p modifiable via a handle.\n"
        "This function mutates p."
    },
    {
        "input/line", cfun_input_line,
        "(input/line id p1 p2)\n\nMake a modifiable line between p1 and p2\n"
        "This function mutates p1 and p2."
    },
    {
        "input/arrow", cfun_input_arrow,
        "(input/arrow id from to)\n\nMake a modifiable arrow between from and to\n"
        "This function mutates from and to."
    },
    {NULL, NULL, NULL}
};

void janet_lib_context(JanetTable *env, Context &context) {
    _context = &context;
    janet_cfuns(env, NULL, it_cfuns);
}

}
}