-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
94 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--!nocheck | ||
--!nolint | ||
|
||
local ffi = require("@lune/ffi") | ||
|
||
local box = ffi.box(ffi.u8:ptr().size) | ||
local ref = box:ref() | ||
ffi.u8:ptr():into(box, ref) | ||
|
||
local wt = setmetatable({}, { __mode = "v" }) | ||
|
||
wt[1] = box | ||
wt[2] = ref | ||
|
||
box = nil | ||
ref = nil | ||
|
||
collectgarbage("collect") | ||
|
||
assert(wt[1] == nil and wt[2] == nil, "Box - ref recursion GC test failed") |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--!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") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--!nocheck | ||
--!nolint | ||
|
||
local ffi = require("@lune/ffi") | ||
local box = ffi.box(ffi.i32.size) | ||
local ref = box:ref() | ||
|
||
local wt = setmetatable({}, { __mode = "v" }) | ||
|
||
wt[1] = box | ||
box = nll | ||
|
||
collectgarbage("collect") | ||
|
||
assert(wt[1] ~= nil, "ref hold box failed") |
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--!nocheck | ||
--!nolint | ||
|
||
local ffi = require("@lune/ffi") | ||
|
||
-- ptr size test | ||
assert( | ||
ffi.i32:ptr().size == ffi.i64:ptr().size, | ||
"All of Ptr.size must be same.\n" .. "ffi.i32:ptr().size == ffi.i64:ptr().size failed" | ||
) | ||
|
||
-- inner test | ||
local i32ptr = ffi.i32:ptr() | ||
assert( | ||
rawequal(ffi.i32, i32ptr.inner), | ||
"Ptr.inner must be same with their parent\n" .. "raweq ffi.i32 == ffi.i32:ptr().inner failed" | ||
) | ||
assert( | ||
rawequal(i32ptr, i32ptr:ptr().inner), | ||
"Ptr.inner must be same with their parent\n" .. "raweq i32ptr == i32ptr:ptr().inner failed" | ||
) | ||
assert( | ||
rawequal(i32ptr, i32ptr:ptr().inner:ptr().inner:ptr().inner), | ||
"Ptr.inner must be same with their parent\n" | ||
.. "raweq i32ptr == i32ptr:ptr().inner:ptr().inner:ptr().inner failed" | ||
) | ||
|
||
-- deep ptr test | ||
local ok, err = pcall(function() | ||
i32ptr:ptr():ptr():ptr():ptr():ptr():ptr():ptr() | ||
end) | ||
assert(ok, `Deep ptr test failed.\n{err}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--!nocheck | ||
--!nolint | ||
|
||
local ffi = require("@lune/ffi") | ||
|
||
local i32ptr = ffi.i32:ptr() | ||
local struct = ffi.struct({ i32ptr, ffi.i32 }) | ||
|
||
assert(rawequal(struct:field(0), i32ptr), "Struct get field failed") | ||
assert(rawequal(struct:field(1), ffi.i32), "Struct get field failed") | ||
|
||
-- offset(2) should fail |