@@ -56,6 +56,7 @@ function TCData<|T: ConstructorArgument, ...: ...any|>
5656 return {
5757 T = T,
5858 @MetaTable = self,
59+ @TypeOverride = "cdata",
5960 __is_cdata_number = type(T) == "number",
6061 __tostring = function(self: self)
6162 return "cdata<" .. tostring(T) .. (is_pointer and " *" or "") .. ">"
@@ -84,18 +85,21 @@ function TCData<|T: ConstructorArgument, ...: ...any|>
8485
8586 return TCData<|obj|>
8687 end,
87- __le = function <|self: self, other: self | number | any|>
88+ __le = function <|a: any, b: number | any|>
8889 return boolean
8990 end,
90- __lt = function <|self: self, other: self | number | any|>
91+ __lt = function <|a: any, b: number | any|>
9192 return boolean
9293 end,
93- __add = function <|self: self, other: self | number | any|>
94+ __add = function <|a: any, b: number | any|>
9495 return TCData<|T|>
9596 end,
96- __sub = function <|self: self, other: self | number | any|>
97- return TCData<|T|>
97+ __sub = function <|a: any, b: number | any|>
98+ if type(b) == "number" then return TCData<|T|> end
99+
100+ return number
98101 end,
102+ __newindex = function <|self: self, key: string | number, value: any|> end,
99103 }
100104end
101105
@@ -104,6 +108,7 @@ function TCType<|T: ConstructorArgument|>
104108 local type is_pointer = type(T) == "table" and keysof<|T|> == number
105109 return {
106110 T = T,
111+ @TypeOverride = "cdata",
107112 @MetaTable = self,
108113 __is_pointer = is_pointer,
109114 __tostring = function <|self: self|>
@@ -127,6 +132,11 @@ function TCType<|T: ConstructorArgument|>
127132 __sub = function <|self: self, other: self | number|>
128133 return TCType<|T|>
129134 end,
135+ -- TODO, __newindex is assigned and used while other fields are being assigned
136+ -- so it has to be done at the end to prevent ie __add = from erroring
137+ __newindex = function <|self: self, key: any, value: any|>
138+ error<|"ctype does not support newindex", 2|>
139+ end,
130140 }
131141end
132142
@@ -154,8 +164,7 @@ function FFIArray<|size: number, T: any|>
154164 return {[0 .. size - 1] = T}
155165end
156166
157- type cdata = FFIPointer<|number|>
158- type cdata.@TypeOverride = "cdata"
167+ type cdata = TCData<|any|>
159168type Modules["ffi"] = {
160169 errno = function=(nil | number)>(number),
161170 os = "Windows" | "Linux" | "OSX" | "BSD" | "POSIX" | "Other",
@@ -323,8 +332,8 @@ analyzer function ffi.load(lib: string, global: boolean | nil)
323332 return cdecl_parser.load(lib)
324333end
325334
326- analyzer function ffi.gc(ctype: ctype , callback: Function): ctype
327- return ctype
335+ analyzer function ffi.gc(obj: cdata , callback: Function)
336+ return obj
328337end
329338
330339function FFIType<|str: string|>
0 commit comments