Skip to content

Commit

Permalink
Chnage naming naturally (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwreey committed Nov 13, 2024
1 parent 7a51bc9 commit 8f248ff
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/lune-std-ffi/src/c/fn_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::{
use crate::{
data::{CallableData, ClosureData, RefData, RefFlag},
ffi::{
association, bit_mask::*, libffi_helper::SIZE_OF_POINTER, FfiArg, FfiData, FfiResult,
association, bit_field::*, libffi_helper::SIZE_OF_POINTER, FfiArg, FfiData, FfiResult,
FfiSignedness, FfiSize,
},
};
Expand Down
2 changes: 1 addition & 1 deletion crates/lune-std-ffi/src/data/box_data/flag.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ffi::bit_mask::*;
use crate::ffi::bit_field::*;

pub enum BoxFlag {
Leaked,
Expand Down
2 changes: 1 addition & 1 deletion crates/lune-std-ffi/src/data/box_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mlua::prelude::*;
use super::helper::method_provider;
use crate::{
data::{association_names::REF_INNER, RefBounds, RefData, RefFlag},
ffi::{association, bit_mask::*, FfiData},
ffi::{association, bit_field::*, FfiData},
};

mod flag;
Expand Down
1 change: 1 addition & 0 deletions crates/lune-std-ffi/src/data/callable_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use mlua::prelude::*;
use super::{GetFfiData, RefData};
use crate::ffi::{FfiArg, FfiData, FfiResult};

// A function pointer that luau can call. it stores libffi cif for calling convention.
pub struct CallableData {
cif: *mut ffi_cif,
arg_info_list: Vec<FfiArg>,
Expand Down
1 change: 1 addition & 0 deletions crates/lune-std-ffi/src/data/closure_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::ffi::{
FfiArg, FfiData, FfiResult,
};

// A closure that can be created with lua function.
pub struct ClosureData {
lua: *const Lua,
closure: *mut ffi_closure,
Expand Down
2 changes: 1 addition & 1 deletion crates/lune-std-ffi/src/data/ref_data/flag.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ffi::bit_mask::*;
use crate::ffi::bit_field::*;

pub enum RefFlag {
Leaked,
Expand Down
2 changes: 1 addition & 1 deletion crates/lune-std-ffi/src/data/ref_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mlua::prelude::*;
use super::helper::method_provider;
use crate::{
data::association_names::REF_INNER,
ffi::{association, bit_mask::*, FfiData},
ffi::{association, bit_field::*, FfiData},
};

mod bounds;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(unused)]

// Simple bit field library for handling data flags

pub const U8_MASK1: u8 = 1;
pub const U8_MASK2: u8 = 2;
pub const U8_MASK3: u8 = 4;
Expand Down
2 changes: 1 addition & 1 deletion crates/lune-std-ffi/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cell::Ref;
use mlua::prelude::*;

pub mod association;
pub mod bit_mask;
pub mod bit_field;
mod cast;
pub mod libffi_helper;

Expand Down
5 changes: 2 additions & 3 deletions tests/ffi/external_closure/callClosure.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ local lib = require("../utils/compile")("./tests/ffi/external_closure/lib.c")
local c = ffi.c

-- Create closure
local closureInfo = c.fn({ c.int, c.int }, c.int)
local closure = closureInfo:closure(function(ret, a, b)
local closure = c.fn({ c.int, c.int }, c.int):closure(function(ret, a, b)
c.int:writeData(ret, c.int:readData(a) + c.int:readData(b))
end)

local callClosure = callableWrapper(lib:find("call_closure"), { closureInfo }, c.int)
local callClosure = callableWrapper(lib:find("call_closure"), { c.void:ptr() }, c.int)
local result = callClosure(closure:ref())
assert(result == 72, `callClosure failed. result expected 20000, got {result}`)
10 changes: 5 additions & 5 deletions tests/ffi/external_closure/callClosureWithPointer.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ local lib = require("../utils/compile")("./tests/ffi/external_closure/lib.c")
local c = ffi.c

-- Create closure
local closureWithPointerInfo = c.fn({ c.int, c.int:ptr() }, c.int)
local closureWithPointer = closureWithPointerInfo:closure(function(returnRef, aRef, bRef)
c.int:writeData(returnRef, c.int:readData(aRef) + c.int:readData(bRef:deref()))
end)
local closureWithPointer = c.fn({ c.int, c.int:ptr() }, c.int)
:closure(function(returnRef, aRef, bRef)
c.int:writeData(returnRef, c.int:readData(aRef) + c.int:readData(bRef:deref()))
end)

local callClosureWithPointer =
callableWrapper(lib:find("call_closure_with_pointer"), { closureWithPointerInfo }, c.int)
callableWrapper(lib:find("call_closure_with_pointer"), { c.void:ptr() }, c.int)
local result = callClosureWithPointer(closureWithPointer:ref())
assert(result == 72, `closureWithPointer failed. result expected 20000, got {result}`)
5 changes: 2 additions & 3 deletions tests/ffi/external_closure/callHelloWorld.luau
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ local lib = require("../utils/compile")("./tests/ffi/external_closure/lib.c")
local c = ffi.c

-- Create closure
local helloWorldInfo = c.fn({}, c.void)
local helloWorld = helloWorldInfo:closure(function()
local helloWorld = c.fn({}, c.void):closure(function()
print("Hello world in lua closure!")
end)

local callHelloWorld = c.fn({ helloWorldInfo }, c.void):callable(lib:find("call_hello_world"))
local callHelloWorld = c.fn({ c.void:ptr() }, c.void):callable(lib:find("call_hello_world"))
callHelloWorld(nil, helloWorld:ref())
6 changes: 5 additions & 1 deletion types/ffi.luau
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ export type CPtrInfo<T> = {
--[=[
@class CArrInfo
A c sized array type information.
A c sized array type information. It can be used for sturct field.
For function arguments, use CPtr instead.
]=]
export type CArrInfo<T, R> = {
--[=[
Expand Down Expand Up @@ -682,6 +684,8 @@ export type CArrInfo<T, R> = {
@class CFnInfo
A C function pointer type information, with function signature.
For struct field, array element, or function arguments, use `void:ptr()` instead.
]=]
export type CFnInfo = {
--[=[
Expand Down

0 comments on commit 8f248ff

Please sign in to comment.