Use a startup hook if you want code run every time Factor starts up. Probably 
necessary for most init calls. 

Top level code like your example would only run the first time the vocabulary 
is USE'd. You could also have every word call something like a `maybe-init` 
before doing what they would do with the library.



> On Mar 1, 2017, at 9:13 AM, Alexander Ilin <ajs...@yandex.ru> wrote:
> 
> Hello!
> 
>  What's the proper way of making sure an external library is initialized?
> 
>  I'm making bindings for libsodium, and it wants `int sodium_init()` to be 
> called before any other functions are used.
> 
>  I'm thinking about simply adding the following code at the end of my FFI 
> vocab:
> 
> ```
> ERROR: sodium-init-fail ;
> 
> ! Call this on library load, may be called multiple times.
> sodium_init 0 < [ sodium-init-fail ] when
> ```
> 
>  There is no penalty in calling it multiple times, it'll simply return 1 in 
> those cases. So, that means we can skip adding a variable preventing multiple 
> calls, and simply do the call when we think we may need one (the variable is 
> already implemented by the library itself).
> 
>  Is that the best way to do it? Do I have to do anything additional with 
> `add-startup-hook` and such? What if Factor loads an image with the vocab 
> already loaded? Won't that skip the `sodium_init` call?
> 
>  Is there anything else I should take care of?
> 
> ---=====--- 
> Александр
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to