#External Types implementation

1 messages · Page 1 of 1 (latest)

neon mica
#

Just a sample of how external types are defined. If I have a pre-existing erlang library/repo, what do I need to do to get it to function/bind correctly?

I understand the syntax, but is there some configuration I need to set in the gleam toml file, or is it literally just getting the src files and referencing their relative path?

wooden barn
#

External types are “gleam doesnt know anything about this”. When you define an external type its representation is totally arbitrary because gleam code cant inspect or construct that type.

Its not external in the sense that the type is defined somewhere else and must be imported its external in the sense that the type represents values external to gleam

neon mica
#

It's more a question of "how."

If I have a library of types and functions, what is the process to actually define the dependency/binding in gleam?

wooden barn
#

There isnt one

#

Its a question that doesn’t make sense

#

A library of external functions makes sense, but types dont

neon mica
#

so when I do this:

@external(erlang, "<what is this supposed to be?", "foo")
pub fn do_foo(input: Int) -> Nil
wooden barn
#

The erlang module

neon mica
#

so I need to add the erlang module as a dependency in the TOML file/

#

?

wooden barn
#

Depends where its coming from? If its erlang stdlib or your own ffi then no, if its a package on hex then yes

neon mica
#

and then reference them by their relative path?

#

Its a touch confusing. In the example JS bindings are by path and the Erlang is done by absolute references to the std_lib implementations of erlang

wooden barn
#

Modules are global in erlang

#

So yes its “absolute path” in the sense that you simply refer to modules according to how they are organised the same way you do for importing gleam modules

#

@external(erlang, “eg_pdf”, “line_cap”) for example

neon mica
#

Got it! I’ll try it out.

wooden barn
#

Sorry for terseness, on mobile ^.^

glass tinsel
#

@wooden barn might wanna edit that