mirror of
https://github.com/janet-lang/janet
synced 2025-11-06 18:43:04 +00:00
Add triangles examples.
This commit is contained in:
@@ -127,25 +127,25 @@ static int cfun_slice(DstArgs args) {
|
||||
|
||||
static int cfun_prepend(DstArgs args) {
|
||||
const Dst *t;
|
||||
int32_t len;
|
||||
Dst *n;
|
||||
if (args.n != 2) return dst_throw(args, "expected 2 arguments");
|
||||
if (!dst_checktype(args.v[0], DST_TUPLE)) return dst_throw(args, "expected tuple");
|
||||
t = dst_unwrap_tuple(args.v[0]);
|
||||
n = dst_tuple_begin(dst_tuple_length(t) + 1);
|
||||
memcpy(n + 1, t, sizeof(Dst) * dst_tuple_length(t));
|
||||
if (!dst_seq_view(args.v[0], &t, &len)) return dst_throw(args, "expected tuple/array");
|
||||
n = dst_tuple_begin(len + 1);
|
||||
memcpy(n + 1, t, sizeof(Dst) * len);
|
||||
n[0] = args.v[1];
|
||||
return dst_return(args, dst_wrap_tuple(dst_tuple_end(n)));
|
||||
}
|
||||
|
||||
static int cfun_append(DstArgs args) {
|
||||
const Dst *t;
|
||||
int32_t len;
|
||||
Dst *n;
|
||||
if (args.n != 2) return dst_throw(args, "expected 2 arguments");
|
||||
if (!dst_checktype(args.v[0], DST_TUPLE)) return dst_throw(args, "expected tuple");
|
||||
t = dst_unwrap_tuple(args.v[0]);
|
||||
n = dst_tuple_begin(dst_tuple_length(t) + 1);
|
||||
memcpy(n, t, sizeof(Dst) * dst_tuple_length(t));
|
||||
n[dst_tuple_length(t)] = args.v[1];
|
||||
if (!dst_seq_view(args.v[0], &t, &len)) return dst_throw(args, "expected tuple/array");
|
||||
n = dst_tuple_begin(len + 1);
|
||||
memcpy(n, t, sizeof(Dst) * len);
|
||||
n[len] = args.v[1];
|
||||
return dst_return(args, dst_wrap_tuple(dst_tuple_end(n)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user