-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathac_reftypes.lua
34 lines (28 loc) · 1.08 KB
/
ac_reftypes.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
ffi.cdef [[
typedef struct { bool value; } refbool;
typedef struct { float value; } refnumber;
]]
local ctrefbool = ffi.typeof('refbool')
local ctrefnumber = ffi.typeof('refnumber')
---Stores a boolean value and can be used as a reference to it.
---@class refbool
---@field value boolean @Stored value.
refbool = ffi.metatype(ctrefbool, { __index = {
---@return boolean
isrefbool = function(x) return ffi.istype(ctrefbool, x) end,
---For easier use with UI controls.
---@param newValue boolean
---@return refbool
set = function (s, newValue) s.value = newValue return s end
}, __call = function(s) return s.value end })
---Stores a numerical value and can be used as a reference to it.
---@class refnumber
---@field value number @Stored value.
refnumber = ffi.metatype(ctrefnumber, { __index = {
---@return boolean
isrefnumber = function(x) return ffi.istype(ctrefnumber, x) end,
---For easier use with UI controls.
---@param newValue number
---@return refnumber
set = function (s, newValue) s.value = newValue return s end
}, __call = function(s) return s.value end })