diff options
Diffstat (limited to 'src/livecode/api')
| -rw-r--r-- | src/livecode/api/api.h | 2 | ||||
| -rw-r--r-- | src/livecode/api/context.cpp | 43 | ||||
| -rw-r--r-- | src/livecode/api/input.cpp | 1 | ||||
| -rw-r--r-- | src/livecode/api/point.cpp | 27 |
4 files changed, 53 insertions, 20 deletions
diff --git a/src/livecode/api/api.h b/src/livecode/api/api.h index 94694ca56..4df3f40be 100644 --- a/src/livecode/api/api.h +++ b/src/livecode/api/api.h @@ -21,7 +21,7 @@ extern const JanetAbstractType geom_point_type; Janet janet_wrap_point(Geom::Point const &x); Janet janet_wrap_point(Geom::IntPoint const &x); -Geom::Point janet_unwrap_point(Janet x); +Geom::Point &janet_unwrap_point(Janet x); /* input.cpp */ void janet_lib_input(JanetTable *env); diff --git a/src/livecode/api/context.cpp b/src/livecode/api/context.cpp index 43c6881d1..f5da3f7cd 100644 --- a/src/livecode/api/context.cpp +++ b/src/livecode/api/context.cpp @@ -13,8 +13,51 @@ Context &ctx() { 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); } } diff --git a/src/livecode/api/input.cpp b/src/livecode/api/input.cpp index 0fc820bbd..1677e68eb 100644 --- a/src/livecode/api/input.cpp +++ b/src/livecode/api/input.cpp @@ -106,6 +106,7 @@ const JanetReg it_cfuns[] = { void janet_lib_input(JanetTable *env) { + janet_printf("yoloading"); janet_cfuns(env, NULL, it_cfuns); } diff --git a/src/livecode/api/point.cpp b/src/livecode/api/point.cpp index 6eab6af1d..25d03d4bb 100644 --- a/src/livecode/api/point.cpp +++ b/src/livecode/api/point.cpp @@ -10,13 +10,13 @@ extern "C" void geom_point_set(void *p, Janet key, Janet value); extern "C" void geom_point_tostring(void *p, JanetBuffer *buffer) { std::stringstream stream; - stream << "<2geom/point " << *static_cast<Geom::Point *>(p) << ">"; + stream << "<geom/point " << *static_cast<Geom::Point *>(p) << ">"; janet_buffer_push_cstring(buffer, stream.str().c_str()); } const JanetAbstractType geom_point_type = { - "2geom/point", + "geom/point", NULL, NULL, geom_point_get, @@ -39,7 +39,7 @@ Janet janet_wrap_point(Geom::IntPoint const &x) { return janet_wrap_abstract(box); } -Geom::Point janet_unwrap_point(Janet x) { +Geom::Point &janet_unwrap_point(Janet x) { if (janet_checktype(x, JANET_ABSTRACT)) { void *abst = janet_unwrap_abstract(x); if (janet_abstract_type(abst) == &geom_point_type) @@ -62,17 +62,6 @@ Geom::Point janet_unwrap_point_or_scalar(Janet x) { janet_panic("expected a geom/point"); } - -Geom::Point& janet_unwrap_point_ref(Janet x) { - if (janet_checktype(x, JANET_ABSTRACT)) { - void *abst = janet_unwrap_abstract(x); - if (janet_abstract_type(abst) == &geom_point_type) - return *(Geom::Point *)abst; - } - - janet_panic("expected a geom/point"); -} - extern "C" Janet cfun_geom_point_new(int32_t argc, Janet *argv) { janet_arity(argc, 0, 2); double x = 0; @@ -89,7 +78,7 @@ extern "C" Janet cfun_geom_point_new(int32_t argc, Janet *argv) { const JanetReg it_cfuns[] = { { - "point", cfun_geom_point_new, + "geom/point", cfun_geom_point_new, "(geom/point x y)\n\nCreate a Point from x/y coordinate values." }, {NULL, NULL, NULL} @@ -177,15 +166,15 @@ static Janet cfun_geom_point_div_mut(int32_t argc, Janet *argv) { static Janet cfun_geom_point_eq(int32_t argc, Janet *argv) { janet_fixarity(argc, 2); - Geom::Point& v1 = janet_unwrap_point_ref(argv[0]); - Geom::Point& v2 = janet_unwrap_point_ref(argv[1]); + Geom::Point &v1 = janet_unwrap_point(argv[0]); + Geom::Point &v2 = janet_unwrap_point(argv[1]); return janet_wrap_boolean(v1 == v2); } static Janet cfun_geom_point_lt(int32_t argc, Janet *argv) { janet_fixarity(argc, 2); - Geom::Point& v1 = janet_unwrap_point_ref(argv[0]); - Geom::Point& v2 = janet_unwrap_point_ref(argv[1]); + Geom::Point &v1 = janet_unwrap_point(argv[0]); + Geom::Point &v2 = janet_unwrap_point(argv[1]); return janet_wrap_boolean(v1 < v2); } |
