Skip to content

Support nullable UTF-8 string arguments in FFI signatures #1033

Closed

Description

@frostney

Summary

Add an FFI descriptor that accepts either ECMAScript text or null, marshalling strings as temporary NUL-terminated UTF-8 and null as a native null pointer.

Why

Many C APIs use nullable const char * parameters. GocciaScript currently forces a binding to choose between utf8string (convenient text, no null-pointer semantics) and pointer (null-capable, rejects JavaScript strings). GocciaScript-Raylib therefore emits seven additional Raw bindings for nullable C-string parameters; see the merged binding documentation.

Current behavior

On current main (34cc32f), using the existing FFI fixture:

const lib = FFI.open("./fixtures/ffi/libfixture" + FFI.suffix);
const strlen = lib.bind("string_length", {
  args: ["utf8string"],
  returns: "i32",
});
console.log(strlen(null));

This prints 4: null is coerced to the text "null" and native code receives that string, not NULL.

Current-source evidence:

The fresh-main FFI suite passes in interpreted and bytecode modes (92 tests, 337 assertions); a direct fresh-main stdin reproduction produced 4.

Expected behavior

A nullable UTF-8 string descriptor should marshal strings with the existing strict UTF-8/NUL validation and marshal null as a null pointer. Plain utf8string behavior may remain unchanged for compatibility if the nullable contract is explicit.

Scope notes

Activity

  1. added
    new featureNew feature or request
    runtimeTGocciaRuntime: optional host extensions (console, fetch, JSON5, FFI, test assertions, etc.)
    on Jul 24, 2026
  2. added this to the 0.11.0 milestone on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    new featureNew feature or requestruntimeTGocciaRuntime: optional host extensions (console, fetch, JSON5, FFI, test assertions, etc.)

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions