diff options
Diffstat (limited to 'js/baba-yaga/examples/js-interop-simple.baba')
-rw-r--r-- | js/baba-yaga/examples/js-interop-simple.baba | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/js/baba-yaga/examples/js-interop-simple.baba b/js/baba-yaga/examples/js-interop-simple.baba new file mode 100644 index 0000000..b937503 --- /dev/null +++ b/js/baba-yaga/examples/js-interop-simple.baba @@ -0,0 +1,49 @@ +// js-interop-simple.baba - Simple JavaScript interop demonstration + +io.out "=== JavaScript Interop Demo ==="; +io.out ""; + +// Mathematical operations +io.out "Math Operations:"; +absResult : io.callJS "Math.abs" [-42]; +io.out absResult; + +minResult : io.callJS "Math.min" [10, 5, 8]; +io.out minResult; + +maxResult : io.callJS "Math.max" [10, 5, 8]; +io.out maxResult; + +io.out ""; + +// JSON operations +io.out "JSON Operations:"; +jsonStr : "{\"name\": \"Alice\", \"age\": 30}"; +parseResult : io.callJS "JSON.parse" [jsonStr]; +io.out parseResult; + +// Property access +propResult : when parseResult is + Ok obj then io.getProperty obj "name" + Err msg then Err msg; + +io.out propResult; + +io.out ""; + +// Array operations +io.out "Array Operations:"; +babaList : [1, 2, 3, 4, 5]; +jsArray : io.listToJSArray babaList; +jsonResult : io.callJS "JSON.stringify" [jsArray]; +io.out jsonResult; + +io.out ""; + +// Error handling +io.out "Error Handling:"; +errorResult : io.callJS "invalidFunction" []; +io.out errorResult; + +io.out ""; +io.out "Demo complete!"; |