@noita-ts/wininet 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/asm_link.lua +47 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.lua +457 -0
- package/dist/lualib_bundle.lua +301 -0
- package/dist/thread.d.ts +46 -0
- package/dist/thread.lua +382 -0
- package/package.json +31 -4
- package/readme.md +66 -0
- package/README.md +0 -3
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
local function __TS__ArrayForEach(self, callbackFn, thisArg)
|
|
2
|
+
for i = 1, #self do
|
|
3
|
+
callbackFn(thisArg, self[i], i - 1, self)
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
local function __TS__Class(self)
|
|
8
|
+
local c = {prototype = {}}
|
|
9
|
+
c.prototype.__index = c.prototype
|
|
10
|
+
c.prototype.constructor = c
|
|
11
|
+
return c
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
local function __TS__StringIncludes(self, searchString, position)
|
|
15
|
+
if not position then
|
|
16
|
+
position = 1
|
|
17
|
+
else
|
|
18
|
+
position = position + 1
|
|
19
|
+
end
|
|
20
|
+
local index = string.find(self, searchString, position, true)
|
|
21
|
+
return index ~= nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
local function __TS__New(target, ...)
|
|
25
|
+
local instance = setmetatable({}, target.prototype)
|
|
26
|
+
instance:____constructor(...)
|
|
27
|
+
return instance
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
local function __TS__ClassExtends(target, base)
|
|
31
|
+
target.____super = base
|
|
32
|
+
local staticMetatable = setmetatable({__index = base}, base)
|
|
33
|
+
setmetatable(target, staticMetatable)
|
|
34
|
+
local baseMetatable = getmetatable(base)
|
|
35
|
+
if baseMetatable then
|
|
36
|
+
if type(baseMetatable.__index) == "function" then
|
|
37
|
+
staticMetatable.__index = baseMetatable.__index
|
|
38
|
+
end
|
|
39
|
+
if type(baseMetatable.__newindex) == "function" then
|
|
40
|
+
staticMetatable.__newindex = baseMetatable.__newindex
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
setmetatable(target.prototype, base.prototype)
|
|
44
|
+
if type(base.prototype.__index) == "function" then
|
|
45
|
+
target.prototype.__index = base.prototype.__index
|
|
46
|
+
end
|
|
47
|
+
if type(base.prototype.__newindex) == "function" then
|
|
48
|
+
target.prototype.__newindex = base.prototype.__newindex
|
|
49
|
+
end
|
|
50
|
+
if type(base.prototype.__tostring) == "function" then
|
|
51
|
+
target.prototype.__tostring = base.prototype.__tostring
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
local Error, RangeError, ReferenceError, SyntaxError, TypeError, URIError
|
|
56
|
+
do
|
|
57
|
+
local function getErrorStack(self, constructor)
|
|
58
|
+
if debug == nil then
|
|
59
|
+
return nil
|
|
60
|
+
end
|
|
61
|
+
local level = 1
|
|
62
|
+
while true do
|
|
63
|
+
local info = debug.getinfo(level, "f")
|
|
64
|
+
level = level + 1
|
|
65
|
+
if not info then
|
|
66
|
+
level = 1
|
|
67
|
+
break
|
|
68
|
+
elseif info.func == constructor then
|
|
69
|
+
break
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
if __TS__StringIncludes(_VERSION, "Lua 5.0") then
|
|
73
|
+
return debug.traceback(("[Level " .. tostring(level)) .. "]")
|
|
74
|
+
elseif _VERSION == "Lua 5.1" then
|
|
75
|
+
return string.sub(
|
|
76
|
+
debug.traceback("", level),
|
|
77
|
+
2
|
|
78
|
+
)
|
|
79
|
+
else
|
|
80
|
+
return debug.traceback(nil, level)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
local function wrapErrorToString(self, getDescription)
|
|
84
|
+
return function(self)
|
|
85
|
+
local description = getDescription(self)
|
|
86
|
+
local caller = debug.getinfo(3, "f")
|
|
87
|
+
local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0")
|
|
88
|
+
if isClassicLua or caller and caller.func ~= error then
|
|
89
|
+
return description
|
|
90
|
+
else
|
|
91
|
+
return (description .. "\n") .. tostring(self.stack)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
local function initErrorClass(self, Type, name)
|
|
96
|
+
Type.name = name
|
|
97
|
+
return setmetatable(
|
|
98
|
+
Type,
|
|
99
|
+
{__call = function(____, _self, message) return __TS__New(Type, message) end}
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
local ____initErrorClass_1 = initErrorClass
|
|
103
|
+
local ____class_0 = __TS__Class()
|
|
104
|
+
____class_0.name = ""
|
|
105
|
+
function ____class_0.prototype.____constructor(self, message)
|
|
106
|
+
if message == nil then
|
|
107
|
+
message = ""
|
|
108
|
+
end
|
|
109
|
+
self.message = message
|
|
110
|
+
self.name = "Error"
|
|
111
|
+
self.stack = getErrorStack(nil, __TS__New)
|
|
112
|
+
local metatable = getmetatable(self)
|
|
113
|
+
if metatable and not metatable.__errorToStringPatched then
|
|
114
|
+
metatable.__errorToStringPatched = true
|
|
115
|
+
metatable.__tostring = wrapErrorToString(nil, metatable.__tostring)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
function ____class_0.prototype.__tostring(self)
|
|
119
|
+
return self.message ~= "" and (self.name .. ": ") .. self.message or self.name
|
|
120
|
+
end
|
|
121
|
+
Error = ____initErrorClass_1(nil, ____class_0, "Error")
|
|
122
|
+
local function createErrorClass(self, name)
|
|
123
|
+
local ____initErrorClass_3 = initErrorClass
|
|
124
|
+
local ____class_2 = __TS__Class()
|
|
125
|
+
____class_2.name = ____class_2.name
|
|
126
|
+
__TS__ClassExtends(____class_2, Error)
|
|
127
|
+
function ____class_2.prototype.____constructor(self, ...)
|
|
128
|
+
____class_2.____super.prototype.____constructor(self, ...)
|
|
129
|
+
self.name = name
|
|
130
|
+
end
|
|
131
|
+
return ____initErrorClass_3(nil, ____class_2, name)
|
|
132
|
+
end
|
|
133
|
+
RangeError = createErrorClass(nil, "RangeError")
|
|
134
|
+
ReferenceError = createErrorClass(nil, "ReferenceError")
|
|
135
|
+
SyntaxError = createErrorClass(nil, "SyntaxError")
|
|
136
|
+
TypeError = createErrorClass(nil, "TypeError")
|
|
137
|
+
URIError = createErrorClass(nil, "URIError")
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
local function __TS__ArrayMap(self, callbackfn, thisArg)
|
|
141
|
+
local result = {}
|
|
142
|
+
for i = 1, #self do
|
|
143
|
+
result[i] = callbackfn(thisArg, self[i], i - 1, self)
|
|
144
|
+
end
|
|
145
|
+
return result
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
local function __TS__StringSlice(self, start, ____end)
|
|
149
|
+
if start == nil or start ~= start then
|
|
150
|
+
start = 0
|
|
151
|
+
end
|
|
152
|
+
if ____end ~= ____end then
|
|
153
|
+
____end = 0
|
|
154
|
+
end
|
|
155
|
+
if start >= 0 then
|
|
156
|
+
start = start + 1
|
|
157
|
+
end
|
|
158
|
+
if ____end ~= nil and ____end < 0 then
|
|
159
|
+
____end = ____end - 1
|
|
160
|
+
end
|
|
161
|
+
return string.sub(self, start, ____end)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
local function __TS__ArrayIsArray(value)
|
|
165
|
+
return type(value) == "table" and (value[1] ~= nil or next(value) == nil)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
local __TS__StringSplit
|
|
169
|
+
do
|
|
170
|
+
local sub = string.sub
|
|
171
|
+
local find = string.find
|
|
172
|
+
function __TS__StringSplit(source, separator, limit)
|
|
173
|
+
if limit == nil then
|
|
174
|
+
limit = 4294967295
|
|
175
|
+
end
|
|
176
|
+
if limit == 0 then
|
|
177
|
+
return {}
|
|
178
|
+
end
|
|
179
|
+
local result = {}
|
|
180
|
+
local resultIndex = 1
|
|
181
|
+
if separator == nil or separator == "" then
|
|
182
|
+
for i = 1, #source do
|
|
183
|
+
result[resultIndex] = sub(source, i, i)
|
|
184
|
+
resultIndex = resultIndex + 1
|
|
185
|
+
end
|
|
186
|
+
else
|
|
187
|
+
local currentPos = 1
|
|
188
|
+
while resultIndex <= limit do
|
|
189
|
+
local startPos, endPos = find(source, separator, currentPos, true)
|
|
190
|
+
if not startPos then
|
|
191
|
+
break
|
|
192
|
+
end
|
|
193
|
+
result[resultIndex] = sub(source, currentPos, startPos - 1)
|
|
194
|
+
resultIndex = resultIndex + 1
|
|
195
|
+
currentPos = endPos + 1
|
|
196
|
+
end
|
|
197
|
+
if resultIndex <= limit then
|
|
198
|
+
result[resultIndex] = sub(source, currentPos)
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
return result
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
local function __TS__StringStartsWith(self, searchString, position)
|
|
206
|
+
if position == nil or position < 0 then
|
|
207
|
+
position = 0
|
|
208
|
+
end
|
|
209
|
+
return string.sub(self, position + 1, #searchString + position) == searchString
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
local function __TS__ObjectKeys(obj)
|
|
213
|
+
local result = {}
|
|
214
|
+
local len = 0
|
|
215
|
+
for key in pairs(obj) do
|
|
216
|
+
len = len + 1
|
|
217
|
+
result[len] = key
|
|
218
|
+
end
|
|
219
|
+
return result
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
local function __TS__ArraySort(self, compareFn)
|
|
223
|
+
if compareFn ~= nil then
|
|
224
|
+
table.sort(
|
|
225
|
+
self,
|
|
226
|
+
function(a, b) return compareFn(nil, a, b) < 0 end
|
|
227
|
+
)
|
|
228
|
+
else
|
|
229
|
+
table.sort(self)
|
|
230
|
+
end
|
|
231
|
+
return self
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
local function __TS__ArrayFilter(self, callbackfn, thisArg)
|
|
235
|
+
local result = {}
|
|
236
|
+
local len = 0
|
|
237
|
+
for i = 1, #self do
|
|
238
|
+
if callbackfn(thisArg, self[i], i - 1, self) then
|
|
239
|
+
len = len + 1
|
|
240
|
+
result[len] = self[i]
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
return result
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
local function __TS__ArraySlice(self, first, last)
|
|
247
|
+
local len = #self
|
|
248
|
+
first = first or 0
|
|
249
|
+
if first < 0 then
|
|
250
|
+
first = len + first
|
|
251
|
+
if first < 0 then
|
|
252
|
+
first = 0
|
|
253
|
+
end
|
|
254
|
+
else
|
|
255
|
+
if first > len then
|
|
256
|
+
first = len
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
last = last or len
|
|
260
|
+
if last < 0 then
|
|
261
|
+
last = len + last
|
|
262
|
+
if last < 0 then
|
|
263
|
+
last = 0
|
|
264
|
+
end
|
|
265
|
+
else
|
|
266
|
+
if last > len then
|
|
267
|
+
last = len
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
local out = {}
|
|
271
|
+
first = first + 1
|
|
272
|
+
last = last + 1
|
|
273
|
+
local n = 1
|
|
274
|
+
while first < last do
|
|
275
|
+
out[n] = self[first]
|
|
276
|
+
first = first + 1
|
|
277
|
+
n = n + 1
|
|
278
|
+
end
|
|
279
|
+
return out
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
__TS__ArrayForEach = __TS__ArrayForEach,
|
|
284
|
+
__TS__Class = __TS__Class,
|
|
285
|
+
Error = Error,
|
|
286
|
+
RangeError = RangeError,
|
|
287
|
+
ReferenceError = ReferenceError,
|
|
288
|
+
SyntaxError = SyntaxError,
|
|
289
|
+
TypeError = TypeError,
|
|
290
|
+
URIError = URIError,
|
|
291
|
+
__TS__New = __TS__New,
|
|
292
|
+
__TS__ArrayMap = __TS__ArrayMap,
|
|
293
|
+
__TS__StringSlice = __TS__StringSlice,
|
|
294
|
+
__TS__ArrayIsArray = __TS__ArrayIsArray,
|
|
295
|
+
__TS__StringSplit = __TS__StringSplit,
|
|
296
|
+
__TS__StringStartsWith = __TS__StringStartsWith,
|
|
297
|
+
__TS__ObjectKeys = __TS__ObjectKeys,
|
|
298
|
+
__TS__ArraySort = __TS__ArraySort,
|
|
299
|
+
__TS__ArrayFilter = __TS__ArrayFilter,
|
|
300
|
+
__TS__ArraySlice = __TS__ArraySlice
|
|
301
|
+
}
|
package/dist/thread.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
/**
|
|
3
|
+
* An argument of a call: a number (`0` for NULL), a string (the call gets a
|
|
4
|
+
* pointer to a copy of it on the process heap) or an FFI pointer. Memory that
|
|
5
|
+
* the call uses after the state is closed must come from the `alloc` of the
|
|
6
|
+
* pool; the thread frees such memory if the call is abandoned, so give it to
|
|
7
|
+
* one call at a time.
|
|
8
|
+
*
|
|
9
|
+
* Never `undefined` or `null`: in Lua, they make a hole in the arguments, so
|
|
10
|
+
* the call pushes too few of them, the stdcall callee pops more, and the
|
|
11
|
+
* thread jumps into its own stack.
|
|
12
|
+
*/
|
|
13
|
+
export type Arg = number | string | object;
|
|
14
|
+
/**
|
|
15
|
+
* Memory on the process heap and the calls on threads that use it, released
|
|
16
|
+
* together.
|
|
17
|
+
*/
|
|
18
|
+
export declare class Pool {
|
|
19
|
+
/** The blocks of the pool, by address. */
|
|
20
|
+
private blocks;
|
|
21
|
+
private calls;
|
|
22
|
+
private released;
|
|
23
|
+
/**
|
|
24
|
+
* `size` zeroed bytes on the process heap, as a pointer of type `ctype`.
|
|
25
|
+
* They are freed by `free`, or when the pool is released.
|
|
26
|
+
*/
|
|
27
|
+
alloc<T>(ctype: string, size: number): T;
|
|
28
|
+
/** Frees a block of the pool. Does nothing for anything else. */
|
|
29
|
+
free(mem: unknown): void;
|
|
30
|
+
/**
|
|
31
|
+
* Calls the function `fn` (a function of the FFI) with `args` (at most 8,
|
|
32
|
+
* see {@link Arg}) on a new native thread, and waits for it with
|
|
33
|
+
* `coroutine.yield()`, so only call it from a coroutine that is resumed
|
|
34
|
+
* every frame, like the ones of a scheduler. Returns the result as an
|
|
35
|
+
* unsigned 32-bit number and the `GetLastError` of the call.
|
|
36
|
+
*
|
|
37
|
+
* Throws if the pool is released before the call is done.
|
|
38
|
+
*/
|
|
39
|
+
run(fn: unknown, ...args: Arg[]): [result: number, error: number];
|
|
40
|
+
/**
|
|
41
|
+
* Frees all of the memory of the pool, except that of the calls that still
|
|
42
|
+
* run: their threads free it when they are done. The calls throw when
|
|
43
|
+
* their coroutines are resumed, and the pool takes no new ones.
|
|
44
|
+
*/
|
|
45
|
+
release(): void;
|
|
46
|
+
}
|