aboutsummaryrefslogtreecommitdiff
path: root/examples/ffi.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-11 16:02:26 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-11 16:02:26 +0530
commit49d6379c3d40b684b28f4a957ff1ffb81a2560ee (patch)
treefac62b2de1670ecfea6496949b028fa8fe0fe444 /examples/ffi.ts
parenta6ff70d09e1e5f161e401a3665bfe44b2abfc44e (diff)
downloadts-types-lang-49d6379c3d40b684b28f4a957ff1ffb81a2560ee.tar.gz
ts-types-lang-49d6379c3d40b684b28f4a957ff1ffb81a2560ee.zip
refactor: minor refactor all around
Diffstat (limited to 'examples/ffi.ts')
-rw-r--r--examples/ffi.ts19
1 files changed, 12 insertions, 7 deletions
diff --git a/examples/ffi.ts b/examples/ffi.ts
index f118085..a09aeef 100644
--- a/examples/ffi.ts
+++ b/examples/ffi.ts
@@ -6,19 +6,24 @@ interface PrintK<Label extends string = ''> extends Kind1 {
return: Debug<Label, this['input']>
}
-type Square<N extends number> = JsExpr<`${N} ** 2`>
+// Declare custom effect
+interface CustomThingy<_A, _B extends number> extends Effect {}
-interface Mathemagic<_A, _B extends number> extends Effect {}
+// Alias for squaring a number
+type Square<N extends number> = JsExpr<`${N} ** 2`>
export type main = [
+ // FFI via js expression
Bind<JsExpr<'{ boobaa: [5 * 3, 5 * 2] }'>, PrintK<'|'>>,
Bind<Square<69>, PrintK<'69^2 ='>>,
+
+ // FFI via custom effect
DefineEffect<
- 'Mathemagic',
- `(a, b) => {
- console.log(typeToString(a))
- return { result: 5 * b.getLiteralValue() }
+ 'CustomThingy',
+ `([a, b], ctx) => {
+ console.log(ctx.typeToString(a))
+ return { result: 5 * ctx.getTypeValue(b) }
}`
>,
- Bind<Mathemagic<'a', 69>, PrintK<'69 * 5 ='>>
+ Bind<CustomThingy<'a', 69>, PrintK<'69 * 5 ='>>
]