Everything you need to know about FFI in Gleam

Ғылым және технология

Gleam is a great language, but sometimes you just need to access the underlying platform, be it JavaScript, Erlang or Elixir. This video will teach you just how to do that using the power of foreign function interfaces, or FFIs!
Resources:
Externals in Gleam: tour.gleam.run/externals
gleam_javascript: hexdocs.pm/gleam_javascript/
gleam_erlang: hexdocs.pm/gleam_erlang/
__________________________________________
Check out my other socials!
🎮 Discord ▶ discordapp.com/invite/bWrctJ7
🐦 Twitter ▶ / isaacharrisholt
🖥️ Portfolio ▶ ihh.dev
📝 Blog ▶ isaacharrisholt.com
__________________________________________
Timestamps:
00:00 - Introduction and explanation
00:58 - Writing foreign functions
03:13 - Default implementations
04:17 - Erlang-specific FFI
05:59 - JavaScript-specific FFI
08:23 - When to use FFI
#gleam #softwareengineer #erlang #javascript #elixir

Пікірлер: 38

  • @IsaacHarrisHolt
    @IsaacHarrisHolt24 күн бұрын

    ERRATA: 6:45 - Gleam lists use a custom type for JS which can be switched to/from using custom `toList` and `fromList` functions NOTES: - You can FFI into Elixir, too! Just specify the `erlang` target and use the module name as you would in Erlang (thanks @JLarky!)

  • @zakariabenhadi4637
    @zakariabenhadi463724 күн бұрын

    Nice video again. Do you plan on doing one about hosting a gleam backend app? I struggle with finding info about that - I suppose a server running erlang vm is enough but a deep dive would be so nice

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    Ooh good idea! Yeah any Erlang server would do, and I believe there are also some deployment guides on the Gleam website

  • @zakariabenhadi4637

    @zakariabenhadi4637

    24 күн бұрын

    @@IsaacHarrisHolt Oh my god you're right, thanks !

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    No worries!

  • @JLarky
    @JLarky24 күн бұрын

    Fun fact, you can also ffi into Elixir :)

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    Yes! This is true, but I managed to miss it out of the video

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    I've added this to the pinned comment :)

  • @JLarky

    @JLarky

    23 күн бұрын

    @@IsaacHarrisHolt yeah, the best part is that it allows you to install Elixir dependencies from hex, which makes it really easy to use

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    23 күн бұрын

    Yes! Though I've been informed that you can just use the Elixir module name :)

  • @costinel57
    @costinel5723 күн бұрын

    But how are js classes represented by gleam? 🤔

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    23 күн бұрын

    They're generally not. You shouldn't be writing enough JS to the point where you need classes, honestly. However, if you NEED to return a class instance, you can, but you shouldn't try to introspect it on the Gleam side. In this case I would create a type with 0 constructors, like I did with the Date type.

  • @costinel57

    @costinel57

    23 күн бұрын

    @@IsaacHarrisHolt I guess that makes sense, thanks!

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    23 күн бұрын

    No worries!

  • @prethammuthappabs2241
    @prethammuthappabs224124 күн бұрын

    Thinking of getting into gleam , the syntax kinda looks look like rust and i kinda had a bit tough time with it , so is gleam easy? Or same as rust?

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    Syntax and language difficulty are not correlated! Gleam is really easy to pick up, and I'd recommend giving it a go

  • @TheddunTOSS
    @TheddunTOSS24 күн бұрын

    Third!

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    Whyyy 😭😭

  • @lpil
    @lpil24 күн бұрын

    First!

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    Ffs Lewis 😂

  • @xfldiazx
    @xfldiazx24 күн бұрын

    Fourth!

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    I give up

  • @devyb-cc
    @devyb-cc22 күн бұрын

    man, i wish python ffi is coming next...

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    22 күн бұрын

    That's kinda unlikely. Gleam doesn't compile to Python, so it wouldn't make a lot of sense. You'd have to spin up a whole new Python process just to execute the code

  • @devyb-cc

    @devyb-cc

    21 күн бұрын

    @@IsaacHarrisHolt fair enough hhh

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    21 күн бұрын

    What's the reason for wanting a Python backend?

  • @devyb-cc

    @devyb-cc

    21 күн бұрын

    @@IsaacHarrisHolt no particular reason, but i do some research on fastapi this week

  • @devyb-cc

    @devyb-cc

    21 күн бұрын

    tbh it's still better to use a microservice approach if the project needs to be written in multi language

  • @raccoonteachesyou
    @raccoonteachesyou24 күн бұрын

    Fifth ?

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    I don't know how I feel anymore

  • @renefrusco2691
    @renefrusco269124 күн бұрын

    nth!

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    I wonder if people ever leave real comments these days...

  • @johtso1
    @johtso124 күн бұрын

    Second!

  • @IsaacHarrisHolt

    @IsaacHarrisHolt

    24 күн бұрын

    Congrats!

Келесі