Update Files
This commit is contained in:
48
Kha/Tools/linux_x64/std/lua/_lua/_hx_anon.lua
Normal file
48
Kha/Tools/linux_x64/std/lua/_lua/_hx_anon.lua
Normal file
@ -0,0 +1,48 @@
|
||||
local function _hx_obj_newindex(t,k,v)
|
||||
t.__fields__[k] = true
|
||||
rawset(t,k,v)
|
||||
end
|
||||
|
||||
local _hx_obj_mt = {__newindex=_hx_obj_newindex, __tostring=_hx_tostring}
|
||||
|
||||
local function _hx_a(...)
|
||||
local __fields__ = {};
|
||||
local ret = {__fields__ = __fields__};
|
||||
local max = select('#',...);
|
||||
local tab = {...};
|
||||
local cur = 1;
|
||||
while cur < max do
|
||||
local v = tab[cur];
|
||||
__fields__[v] = true;
|
||||
ret[v] = tab[cur+1];
|
||||
cur = cur + 2
|
||||
end
|
||||
return setmetatable(ret, _hx_obj_mt)
|
||||
end
|
||||
|
||||
local function _hx_e()
|
||||
return setmetatable({__fields__ = {}}, _hx_obj_mt)
|
||||
end
|
||||
|
||||
local function _hx_o(obj)
|
||||
return setmetatable(obj, _hx_obj_mt)
|
||||
end
|
||||
|
||||
local function _hx_new(prototype)
|
||||
return setmetatable({__fields__ = {}}, {__newindex=_hx_obj_newindex, __index=prototype, __tostring=_hx_tostring})
|
||||
end
|
||||
|
||||
function _hx_field_arr(obj)
|
||||
res = {}
|
||||
idx = 0
|
||||
if obj.__fields__ ~= nil then
|
||||
obj = obj.__fields__
|
||||
end
|
||||
for k,v in pairs(obj) do
|
||||
if _hx_hidden[k] == nil then
|
||||
res[idx] = k
|
||||
idx = idx + 1
|
||||
end
|
||||
end
|
||||
return _hx_tab_array(res, idx)
|
||||
end
|
3
Kha/Tools/linux_x64/std/lua/_lua/_hx_apply_self.lua
Normal file
3
Kha/Tools/linux_x64/std/lua/_lua/_hx_apply_self.lua
Normal file
@ -0,0 +1,3 @@
|
||||
_hx_apply_self = function(self, f, ...)
|
||||
return self[f](self,...)
|
||||
end
|
14
Kha/Tools/linux_x64/std/lua/_lua/_hx_bind.lua
Normal file
14
Kha/Tools/linux_x64/std/lua/_lua/_hx_bind.lua
Normal file
@ -0,0 +1,14 @@
|
||||
_hx_bind = function(o,m)
|
||||
if m == nil then return nil end;
|
||||
local f;
|
||||
if o._hx__closures == nil then
|
||||
_G.rawset(o, '_hx__closures', {});
|
||||
else
|
||||
f = o._hx__closures[m];
|
||||
end
|
||||
if (f == nil) then
|
||||
f = function(...) return m(o, ...) end;
|
||||
o._hx__closures[m] = f;
|
||||
end
|
||||
return f;
|
||||
end
|
16
Kha/Tools/linux_x64/std/lua/_lua/_hx_bit.lua
Normal file
16
Kha/Tools/linux_x64/std/lua/_lua/_hx_bit.lua
Normal file
@ -0,0 +1,16 @@
|
||||
-- require this for lua 5.1
|
||||
pcall(require, 'bit')
|
||||
if bit then
|
||||
_hx_bit_raw = bit
|
||||
_hx_bit = setmetatable({}, { __index = _hx_bit_raw });
|
||||
else
|
||||
_hx_bit_raw = _G.require('bit32')
|
||||
_hx_bit = setmetatable({}, { __index = _hx_bit_raw });
|
||||
-- lua 5.2 weirdness
|
||||
_hx_bit.bnot = function(...) return _hx_bit_clamp(_hx_bit_raw.bnot(...)) end;
|
||||
_hx_bit.bxor = function(...) return _hx_bit_clamp(_hx_bit_raw.bxor(...)) end;
|
||||
end
|
||||
-- see https://github.com/HaxeFoundation/haxe/issues/8849
|
||||
_hx_bit.bor = function(...) return _hx_bit_clamp(_hx_bit_raw.bor(...)) end;
|
||||
_hx_bit.band = function(...) return _hx_bit_clamp(_hx_bit_raw.band(...)) end;
|
||||
_hx_bit.arshift = function(...) return _hx_bit_clamp(_hx_bit_raw.arshift(...)) end;
|
26
Kha/Tools/linux_x64/std/lua/_lua/_hx_bit_clamp.lua
Normal file
26
Kha/Tools/linux_x64/std/lua/_lua/_hx_bit_clamp.lua
Normal file
@ -0,0 +1,26 @@
|
||||
if _hx_bit_raw then
|
||||
_hx_bit_clamp = function(v)
|
||||
if v <= 2147483647 and v >= -2147483648 then
|
||||
if v > 0 then return _G.math.floor(v)
|
||||
else return _G.math.ceil(v)
|
||||
end
|
||||
end
|
||||
if v > 2251798999999999 then v = v*2 end;
|
||||
if (v ~= v or math.abs(v) == _G.math.huge) then return nil end
|
||||
return _hx_bit_raw.band(v, 2147483647 ) - math.abs(_hx_bit_raw.band(v, 2147483648))
|
||||
end
|
||||
else
|
||||
_hx_bit_clamp = function(v)
|
||||
if v < -2147483648 then
|
||||
return -2147483648
|
||||
elseif v > 2147483647 then
|
||||
return 2147483647
|
||||
elseif v > 0 then
|
||||
return _G.math.floor(v)
|
||||
else
|
||||
return _G.math.ceil(v)
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
|
7
Kha/Tools/linux_x64/std/lua/_lua/_hx_box_mr.lua
Normal file
7
Kha/Tools/linux_x64/std/lua/_lua/_hx_box_mr.lua
Normal file
@ -0,0 +1,7 @@
|
||||
_hx_box_mr = function(x,nt)
|
||||
res = _hx_o({__fields__={}})
|
||||
for i,v in ipairs(nt) do
|
||||
res[v] = x[i]
|
||||
end
|
||||
return res
|
||||
end
|
7
Kha/Tools/linux_x64/std/lua/_lua/_hx_classes.lua
Normal file
7
Kha/Tools/linux_x64/std/lua/_lua/_hx_classes.lua
Normal file
@ -0,0 +1,7 @@
|
||||
local _hxClasses = {}
|
||||
local Int = _hx_e();
|
||||
local Dynamic = _hx_e();
|
||||
local Float = _hx_e();
|
||||
local Bool = _hx_e();
|
||||
local Class = _hx_e();
|
||||
local Enum = _hx_e();
|
7
Kha/Tools/linux_x64/std/lua/_lua/_hx_dyn_add.lua
Normal file
7
Kha/Tools/linux_x64/std/lua/_lua/_hx_dyn_add.lua
Normal file
@ -0,0 +1,7 @@
|
||||
_hx_dyn_add = function(a,b)
|
||||
if (_G.type(a) == 'string' or _G.type(b) == 'string') then
|
||||
return Std.string(a)..Std.string(b)
|
||||
else
|
||||
return a + b;
|
||||
end;
|
||||
end;
|
9
Kha/Tools/linux_x64/std/lua/_lua/_hx_func_to_field.lua
Normal file
9
Kha/Tools/linux_x64/std/lua/_lua/_hx_func_to_field.lua
Normal file
@ -0,0 +1,9 @@
|
||||
_hx_funcToField = function(f)
|
||||
if type(f) == 'function' then
|
||||
return function(self,...)
|
||||
return f(...)
|
||||
end
|
||||
else
|
||||
return f
|
||||
end
|
||||
end
|
1
Kha/Tools/linux_x64/std/lua/_lua/_hx_print.lua
Normal file
1
Kha/Tools/linux_x64/std/lua/_lua/_hx_print.lua
Normal file
@ -0,0 +1 @@
|
||||
_hx_print = print or (function() end)
|
1
Kha/Tools/linux_x64/std/lua/_lua/_hx_random_init.lua
Normal file
1
Kha/Tools/linux_x64/std/lua/_lua/_hx_random_init.lua
Normal file
@ -0,0 +1 @@
|
||||
_G.math.randomseed(_G.os.time());
|
13
Kha/Tools/linux_x64/std/lua/_lua/_hx_static_to_instance.lua
Normal file
13
Kha/Tools/linux_x64/std/lua/_lua/_hx_static_to_instance.lua
Normal file
@ -0,0 +1,13 @@
|
||||
_hx_staticToInstance = function (tab)
|
||||
return setmetatable({}, {
|
||||
__index = function(t,k)
|
||||
if type(rawget(tab,k)) == 'function' then
|
||||
return function(self,...)
|
||||
return rawget(tab,k)(...)
|
||||
end
|
||||
else
|
||||
return rawget(tab,k)
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
23
Kha/Tools/linux_x64/std/lua/_lua/_hx_tab_array.lua
Normal file
23
Kha/Tools/linux_x64/std/lua/_lua/_hx_tab_array.lua
Normal file
@ -0,0 +1,23 @@
|
||||
local _hx_hidden = {__id__=true, hx__closures=true, super=true, prototype=true, __fields__=true, __ifields__=true, __class__=true, __properties__=true, __fields__=true, __name__=true}
|
||||
|
||||
_hx_array_mt = {
|
||||
__newindex = function(t,k,v)
|
||||
local len = t.length
|
||||
t.length = k >= len and (k + 1) or len
|
||||
rawset(t,k,v)
|
||||
end
|
||||
}
|
||||
|
||||
function _hx_is_array(o)
|
||||
return type(o) == "table"
|
||||
and o.__enum__ == nil
|
||||
and getmetatable(o) == _hx_array_mt
|
||||
end
|
||||
|
||||
|
||||
|
||||
function _hx_tab_array(tab, length)
|
||||
tab.length = length
|
||||
return setmetatable(tab, _hx_array_mt)
|
||||
end
|
||||
|
12
Kha/Tools/linux_x64/std/lua/_lua/_hx_table.lua
Normal file
12
Kha/Tools/linux_x64/std/lua/_lua/_hx_table.lua
Normal file
@ -0,0 +1,12 @@
|
||||
_hx_table = {}
|
||||
_hx_table.pack = _G.table.pack or function(...)
|
||||
return {...}
|
||||
end
|
||||
_hx_table.unpack = _G.table.unpack or _G.unpack
|
||||
_hx_table.maxn = _G.table.maxn or function(t)
|
||||
local maxn=0;
|
||||
for i in pairs(t) do
|
||||
maxn=type(i)=='number'and i>maxn and i or maxn
|
||||
end
|
||||
return maxn
|
||||
end;
|
114
Kha/Tools/linux_x64/std/lua/_lua/_hx_tostring.lua
Normal file
114
Kha/Tools/linux_x64/std/lua/_lua/_hx_tostring.lua
Normal file
@ -0,0 +1,114 @@
|
||||
|
||||
function _hx_print_class(obj, depth)
|
||||
local first = true
|
||||
local result = ''
|
||||
for k,v in pairs(obj) do
|
||||
if _hx_hidden[k] == nil then
|
||||
if first then
|
||||
first = false
|
||||
else
|
||||
result = result .. ', '
|
||||
end
|
||||
if _hx_hidden[k] == nil then
|
||||
result = result .. k .. ':' .. _hx_tostring(v, depth+1)
|
||||
end
|
||||
end
|
||||
end
|
||||
return '{ ' .. result .. ' }'
|
||||
end
|
||||
|
||||
function _hx_print_enum(o, depth)
|
||||
if o.length == 2 then
|
||||
return o[0]
|
||||
else
|
||||
local str = o[0] .. "("
|
||||
for i = 2, (o.length-1) do
|
||||
if i ~= 2 then
|
||||
str = str .. "," .. _hx_tostring(o[i], depth+1)
|
||||
else
|
||||
str = str .. _hx_tostring(o[i], depth+1)
|
||||
end
|
||||
end
|
||||
return str .. ")"
|
||||
end
|
||||
end
|
||||
|
||||
function _hx_tostring(obj, depth)
|
||||
if depth == nil then
|
||||
depth = 0
|
||||
elseif depth > 5 then
|
||||
return "<...>"
|
||||
end
|
||||
|
||||
local tstr = _G.type(obj)
|
||||
if tstr == "string" then return obj
|
||||
elseif tstr == "nil" then return "null"
|
||||
elseif tstr == "number" then
|
||||
if obj == _G.math.POSITIVE_INFINITY then return "Infinity"
|
||||
elseif obj == _G.math.NEGATIVE_INFINITY then return "-Infinity"
|
||||
elseif obj == 0 then return "0"
|
||||
elseif obj ~= obj then return "NaN"
|
||||
else return _G.tostring(obj)
|
||||
end
|
||||
elseif tstr == "boolean" then return _G.tostring(obj)
|
||||
elseif tstr == "userdata" then
|
||||
local mt = _G.getmetatable(obj)
|
||||
if mt ~= nil and mt.__tostring ~= nil then
|
||||
return _G.tostring(obj)
|
||||
else
|
||||
return "<userdata>"
|
||||
end
|
||||
elseif tstr == "function" then return "<function>"
|
||||
elseif tstr == "thread" then return "<thread>"
|
||||
elseif tstr == "table" then
|
||||
if obj.__enum__ ~= nil then
|
||||
return _hx_print_enum(obj, depth)
|
||||
elseif obj.toString ~= nil and not _hx_is_array(obj) then return obj:toString()
|
||||
elseif _hx_is_array(obj) then
|
||||
if obj.length > 5 then
|
||||
return "[...]"
|
||||
else
|
||||
local str = ""
|
||||
for i=0, (obj.length-1) do
|
||||
if i == 0 then
|
||||
str = str .. _hx_tostring(obj[i], depth+1)
|
||||
else
|
||||
str = str .. "," .. _hx_tostring(obj[i], depth+1)
|
||||
end
|
||||
end
|
||||
return "[" .. str .. "]"
|
||||
end
|
||||
elseif obj.__class__ ~= nil then
|
||||
return _hx_print_class(obj, depth)
|
||||
else
|
||||
local buffer = {}
|
||||
local ref = obj
|
||||
if obj.__fields__ ~= nil then
|
||||
ref = obj.__fields__
|
||||
end
|
||||
for k,v in pairs(ref) do
|
||||
if _hx_hidden[k] == nil then
|
||||
_G.table.insert(buffer, _hx_tostring(k, depth+1) .. ' : ' .. _hx_tostring(obj[k], depth+1))
|
||||
end
|
||||
end
|
||||
|
||||
return "{ " .. table.concat(buffer, ", ") .. " }"
|
||||
end
|
||||
else
|
||||
_G.error("Unknown Lua type", 0)
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
function _hx_error(obj)
|
||||
if obj.value then
|
||||
_G.print("runtime error:\n " .. _hx_tostring(obj.value));
|
||||
else
|
||||
_G.print("runtime error:\n " .. tostring(obj));
|
||||
end
|
||||
|
||||
if _G.debug and _G.debug.traceback then
|
||||
_G.print(debug.traceback());
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,11 @@
|
||||
_hx_wrap_if_string_field = function(o, fld)
|
||||
if _G.type(o) == 'string' then
|
||||
if fld == 'length' then
|
||||
return _G.string.len(o)
|
||||
else
|
||||
return String.prototype[fld]
|
||||
end
|
||||
else
|
||||
return o[fld]
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user