diff --git a/crates/lune-std-ffi/README.md b/crates/lune-std-ffi/README.md index f842af6f..4470901c 100644 --- a/crates/lune-std-ffi/README.md +++ b/crates/lune-std-ffi/README.md @@ -31,6 +31,8 @@ See [tests/ffi](../../tests/ffi/README.md) - Array argument in cfn +- Ref boundary fix + ## Code structure ### /c @@ -84,12 +86,11 @@ Implememt type-casting for all CTypes - **Trait `FfiSize`** - **Trait `FfiSignedness`** -- **Trait `FfiConvert`:** Provide read LuaValue from FfiData or write LuaValue into FfiData -**Traits:** Provide call information trait +**Structs:** Provide call information trait -- **Trait `FfiArg`:** Used for argument boundary checking and callback argument ref flag -- **Trait `FfiResult`:** Used for result boundary checking +- **Struct `FfiArg`:** Used for argument boundary checking and callback argument ref flag +- **Struct `FfiResult`:** Used for result boundary checking **Trait `FfiData`:** Provide common data handle, including methods below @@ -97,6 +98,14 @@ Implememt type-casting for all CTypes - **Method `get_inner_pointer`:** returns raw pointer `*mut ()` - **Method `is_writable`** - **Method `is_readable`** +- **Method `copy_from`** copy data from another data + +- **Trait `FfiConvert`:** Provide methods for read LuaValue from FfiData or write LuaValue into FfiData + +- **Method `value_into_data`:** set data with lua value +- **Method `value_from_data`:** get lua value from data +- **Method `copy_data`:** copy sized data into another data +- **Method `stringify_data`:** stringify data with specific type > Note: `GetFfiData` trait in `data/mod.rs` provides `AnyUserData.get_data_handle() -> FfiData` method @@ -108,6 +117,7 @@ Implememt type-casting for all CTypes - **Function `num_cast(from: FfiData, from: FfiData)`:** Cast number type value inno another number type - [**Mod `libffi_helper.rs`:**](./src/ffi/libffi_helper.rs) - - **Const `FFI_STATUS_NAMES`:** Used for ffi_status stringify - - **Function `get_ensured_size`:** Returns ensured ffi_type size + - **Const `FFI_STATUS_NAMES`:** Used for `ffi_status` stringify + - **Function `get_ensured_size`:** Returns ensured `ffi_type` size - **Const `SIZE_OF_POINTER`:** Platform specific pointer size (Compile time known) + - **Function `ffi_status_assert`:** Convert `ffi_status` to `LuaResult<()>` diff --git a/crates/lune-std-ffi/src/c/types/mod.rs b/crates/lune-std-ffi/src/c/types/mod.rs index d778874a..672279e4 100644 --- a/crates/lune-std-ffi/src/c/types/mod.rs +++ b/crates/lune-std-ffi/src/c/types/mod.rs @@ -115,7 +115,7 @@ where into: &Ref, ) -> LuaResult<()> { define_cast_num!( - From, self, into_info, from_info, from, into, + From, self, from_info, into_info, from, into, u8 u16 u32 u64 u128 i8 i16 i32 i64 i128 f32 f64 usize isize ) } diff --git a/tests/ffi/README.md b/tests/ffi/README.md index b1e5e5b6..8f911d31 100644 --- a/tests/ffi/README.md +++ b/tests/ffi/README.md @@ -16,22 +16,20 @@ gcc for library compiling (for external-\*) **Luau-side** +- [x] [isInteger](./isInteger) +- [x] [cast](./cast.luau) + - [ ] [pretty_print](./pretty_print) > need box, ref test -- [x] [isInteger](./isInteger) -- [ ] [into_boundary](./into_boundary) - - > need assertion - -- [ ] [from_boundary](./from_boundary) +- [ ] [write_boundary](./write_boundary.luau) - > need assertion + > Failed, need fix -- [ ] [cast](./cast) +- [ ] [read_boundary](./read_boundary.luau) - > need assertion + > Failed, need fix ## Benchmark Results diff --git a/tests/ffi/cast.luau b/tests/ffi/cast.luau index e69de29b..9c4d5361 100644 --- a/tests/ffi/cast.luau +++ b/tests/ffi/cast.luau @@ -0,0 +1,13 @@ +local ffi = require("@lune/ffi") + +local floatBox = ffi.f32:box(1.2) +local intBox = ffi.box(ffi.i32.size) + +ffi.f32:cast(ffi.i32, floatBox, intBox) + +local castedInt = ffi.i32:readData(intBox) + +assert( + castedInt == 1 and ffi.isInteger(castedInt), + "castedInt == 1 and ffi.isInteger(castedInt) assersion failed" +) diff --git a/tests/ffi/isInteger.luau b/tests/ffi/isInteger.luau index 1084b8f0..a856df0c 100644 --- a/tests/ffi/isInteger.luau +++ b/tests/ffi/isInteger.luau @@ -1,10 +1,7 @@ ---!nocheck ---!nolint - local ffi = require("@lune/ffi") local int = 0b1 local float = 0.5 -assert(ffi.isInteger(int) == true, "ffi.isInteger(int) == true failed") -assert(ffi.isInteger(float) == false, "ffi.isInteger(float) == false failed") +assert(ffi.isInteger(int) == true, "ffi.isInteger(int) == true assersion failed") +assert(ffi.isInteger(float) == false, "ffi.isInteger(float) == false assersion failed")