# Foreign constants

**URL:** <https://community.spritely.institute/t/foreign-constants/663>\
**Category:** Hoot: Guile in WASM\
**Tags:** wasm\
**Created:** [January 17, 2025, 12:20am UTC](https://community.spritely.institute/t/foreign-constants/663 "2025-01-17T00:20:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![teddd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/teddd/32/370_2.png) [@teddd](https://community.spritely.institute/u/teddd)\
**Post date:** [January 17, 2025, 12:20am UTC](https://community.spritely.institute/t/foreign-constants/663/1 "2025-01-17T00:20:42Z")

</div>

I’m trying to use WebGL in Hoot. I’m using `define-foreign` to get access to js functions. I don’t understand how I’m supposed to get access to webgl constants like `COLOR_BUFFER_BIT`. I tried something like

```auto
(define-foreign COLOR_BUFFER_BIT
  "gl" "COLOR_BUFFER_BIT"
  -> (ref extern))

```

without success.

The error I get is

```quote
LinkError: import object field 'COLOR_BUFFER_BIT' is not a Function

```

---

<div class="post-metadata">

**Author:** ![dthompson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/dthompson/32/95_2.png) [@dthompson](https://community.spritely.institute/u/dthompson)\
**Post date:** [January 17, 2025, 2:28am UTC](https://community.spritely.institute/t/foreign-constants/663/2 "2025-01-17T02:28:57Z")

</div>

Hi @teddd, you can’t import a number, only functions. Just define the constant like `(define var val)` directly.

---

<div class="post-metadata">

**Author:** ![teddd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/teddd/32/370_2.png) [@teddd](https://community.spritely.institute/u/teddd)\
**Post date:** [January 17, 2025, 12:40pm UTC](https://community.spritely.institute/t/foreign-constants/663/3 "2025-01-17T12:40:53Z")

</div>

Ok I see. That will do for now. It would be nice not to have to redefine them. Is this planned / possible feature ?

---

<div class="post-metadata">

**Author:** ![dthompson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/dthompson/32/95_2.png) [@dthompson](https://community.spritely.institute/u/dthompson)\
**Post date:** [January 17, 2025, 12:47pm UTC](https://community.spritely.institute/t/foreign-constants/663/4 "2025-01-17T12:47:38Z")

</div>

Not a planned feature. This is the usual case for FFIs. Automating this with a code generation tool would be the way to go.

---

<div class="post-metadata">

**Author:** ![teddd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/teddd/32/370_2.png) [@teddd](https://community.spritely.institute/u/teddd)\
**Post date:** [January 17, 2025, 12:53pm UTC](https://community.spritely.institute/t/foreign-constants/663/5 "2025-01-17T12:53:47Z")

</div>

Makes sense. Maybe it could be part of this [Generate JS for FFI imports (#159) · Issues · spritely / Guile Hoot · GitLab](https://gitlab.com/spritely/guile-hoot/-/issues/159)

---

<div class="post-metadata">

**Author:** ![dthompson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/dthompson/32/95_2.png) [@dthompson](https://community.spritely.institute/u/dthompson)\
**Post date:** [January 17, 2025, 12:57pm UTC](https://community.spritely.institute/t/foreign-constants/663/6 "2025-01-17T12:57:46Z")

</div>

That’s a separate but related thing that you could target with the code generation tool. All the Web APIs have IDL specifications, so you can parse those and generate bindings. This is what Kotlin Wasm does. Here is the WebGL IDL file and specifically a line that defines a constant: [WebGL/specs/latest/1.0/webgl.idl at main · KhronosGroup/WebGL · GitHub](https://github.com/KhronosGroup/WebGL/blob/main/specs/latest/1.0/webgl.idl#L121)

---

<div class="post-metadata">

**Author:** ![teddd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/teddd/32/370_2.png) [@teddd](https://community.spritely.institute/u/teddd)\
**Post date:** [January 17, 2025, 1:08pm UTC](https://community.spritely.institute/t/foreign-constants/663/7 "2025-01-17T13:08:26Z")

</div>

Great! That looks promising. So we need an IDL parser first

---

<div class="post-metadata">

**Author:** ![dthompson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/dthompson/32/95_2.png) [@dthompson](https://community.spritely.institute/u/dthompson)\
**Post date:** [January 17, 2025, 4:04pm UTC](https://community.spritely.institute/t/foreign-constants/663/8 "2025-01-17T16:04:25Z")

</div>

Yup, a Scheme IDL parser would be a great thing to have.

---

<div class="post-metadata">

**Author:** ![teddd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/teddd/32/370_2.png) [@teddd](https://community.spritely.institute/u/teddd)\
**Post date:** [January 17, 2025, 7:38pm UTC](https://community.spritely.institute/t/foreign-constants/663/9 "2025-01-17T19:38:22Z")

</div>

Maybe that could be done using PEGs: [PEG Parsing (Guile Reference Manual)](https://www.gnu.org/software/guile/manual/html_node/PEG-Parsing.html)
