Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you access a JavaScript global variable using the Idris JavaScript FFI?

I'm trying to use Idris with Nativescript, by using the Idris JavaScript FFI and using JavaScript as the codegen target. However, it seems like Nativescript makes use of global variables, such as an object called global. How would I be able to work with that object from within Idris?

like image 332
zenten Avatar asked Mar 07 '26 19:03

zenten


1 Answers

You can write separate getter and setter functions using FFI (both in JS_IO of course), and then you can start coming up with whatever abstractions you want to build on top of it:

getVar : JS_IO String
getVar = foreign FFI_JS "globalVar" (JS_IO String)

setVar : String -> JS_IO ()
setVar = foreign FFI_JS "globalVar = %0"  (String -> JS_IO ())
like image 83
Cactus Avatar answered Mar 10 '26 08:03

Cactus