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
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!)
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
24 күн бұрын
Ooh good idea! Yeah any Erlang server would do, and I believe there are also some deployment guides on the Gleam website
@zakariabenhadi4637
24 күн бұрын
@@IsaacHarrisHolt Oh my god you're right, thanks !
@IsaacHarrisHolt
24 күн бұрын
No worries!
Fun fact, you can also ffi into Elixir :)
@IsaacHarrisHolt
24 күн бұрын
Yes! This is true, but I managed to miss it out of the video
@IsaacHarrisHolt
24 күн бұрын
I've added this to the pinned comment :)
@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
23 күн бұрын
Yes! Though I've been informed that you can just use the Elixir module name :)
But how are js classes represented by gleam? 🤔
@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
23 күн бұрын
@@IsaacHarrisHolt I guess that makes sense, thanks!
@IsaacHarrisHolt
23 күн бұрын
No worries!
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
24 күн бұрын
Syntax and language difficulty are not correlated! Gleam is really easy to pick up, and I'd recommend giving it a go
Third!
@IsaacHarrisHolt
24 күн бұрын
Whyyy 😭😭
First!
@IsaacHarrisHolt
24 күн бұрын
Ffs Lewis 😂
Fourth!
@IsaacHarrisHolt
24 күн бұрын
I give up
man, i wish python ffi is coming next...
@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
21 күн бұрын
@@IsaacHarrisHolt fair enough hhh
@IsaacHarrisHolt
21 күн бұрын
What's the reason for wanting a Python backend?
@devyb-cc
21 күн бұрын
@@IsaacHarrisHolt no particular reason, but i do some research on fastapi this week
@devyb-cc
21 күн бұрын
tbh it's still better to use a microservice approach if the project needs to be written in multi language
Fifth ?
@IsaacHarrisHolt
24 күн бұрын
I don't know how I feel anymore
nth!
@IsaacHarrisHolt
24 күн бұрын
I wonder if people ever leave real comments these days...
Second!
@IsaacHarrisHolt
24 күн бұрын
Congrats!