Skip to content

Conversation

green-real
Copy link
Contributor

@green-real green-real commented Aug 4, 2025

This is the first PR for Lute’s FFI branch, which will eventually hold a stable and feature-complete foreign function interface to be merged into the main branch. I’ve already implemented a rough prototype and have some ideas about how the library might look, but the user-facing API and exposed internals are still open for discussion as I build.

This PR includes:

  • The libffi dependency file and CMake support, which tries to replicate libffi's build system, which is using GNU Autotools, as close as possible.
  • An empty FFI library, only containing a field for the C interface. For now contains a function which simply adds two numbers to test if libffi is working correctly, will probably be removed soon enough.

No real functionality yet, but next up I plan to implement C types as userdata objects, accessible via the FFI library's C interface. Here’s what I have in mind for the API so far:

local ffi = require("@lute/ffi")
local ffi_c = ffi.c

local int = ffi_c.int
local void = ffi_c.void

local voidptr = void:ptr()

local int_array = int:array(5)

local vec3 = ffi_c.struct({
    {x = float},
    {y = float},
    {z = float}
})

local add_function = ffi_c.func({int, int}, int)

If that API seems reasonable I'll get started on the next PR after this one gets reviewed.

Copy link
Contributor

@bjcscat bjcscat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise this looks good

@aatxe aatxe merged commit b073ba9 into luau-lang:ffi Sep 16, 2025
aatxe added a commit that referenced this pull request Sep 16, 2025
This is the first PR for Lute’s FFI branch, which will eventually hold a
stable and feature-complete foreign function interface to be merged into
the main branch. I’ve already implemented a rough prototype and have
some ideas about how the library might look, but the user-facing API and
exposed internals are still open for discussion as I build.

This PR includes:
* The libffi dependency file and CMake support, which tries to replicate
libffi's build system, which is using GNU Autotools, as close as
possible.
* An empty FFI library, only containing a field for the C interface. For
now contains a function which simply adds two numbers to test if libffi
is working correctly, will probably be removed soon enough.

No real functionality yet, but next up I plan to implement C types as
userdata objects, accessible via the FFI library's C interface. Here’s
what I have in mind for the API so far:
```luau
local ffi = require("@lute/ffi")
local ffi_c = ffi.c

local int = ffi_c.int
local void = ffi_c.void

local voidptr = void:ptr()

local int_array = int:array(5)

local vec3 = ffi_c.struct({
    {x = float},
    {y = float},
    {z = float}
})

local add_function = ffi_c.func({int, int}, int)
```

If that API seems reasonable I'll get started on the next PR after this
one gets reviewed.

---------

Co-authored-by: ariel <[email protected]>
aatxe added a commit that referenced this pull request Sep 16, 2025
This is the first PR for Lute’s FFI branch, which will eventually hold a
stable and feature-complete foreign function interface to be merged into
the main branch. I’ve already implemented a rough prototype and have
some ideas about how the library might look, but the user-facing API and
exposed internals are still open for discussion as I build.

This PR includes:
* The libffi dependency file and CMake support, which tries to replicate
libffi's build system, which is using GNU Autotools, as close as
possible.
* An empty FFI library, only containing a field for the C interface. For
now contains a function which simply adds two numbers to test if libffi
is working correctly, will probably be removed soon enough.

No real functionality yet, but next up I plan to implement C types as
userdata objects, accessible via the FFI library's C interface. Here’s
what I have in mind for the API so far:
```luau
local ffi = require("@lute/ffi")
local ffi_c = ffi.c

local int = ffi_c.int
local void = ffi_c.void

local voidptr = void:ptr()

local int_array = int:array(5)

local vec3 = ffi_c.struct({
    {x = float},
    {y = float},
    {z = float}
})

local add_function = ffi_c.func({int, int}, int)
```

If that API seems reasonable I'll get started on the next PR after this
one gets reviewed.

---------

Co-authored-by: ariel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants