罗技 G-Hub 的最新更新中缺少数学库 [英] math library is missing in the latest update of Logitech G-Hub
问题描述
局部延迟 = math.random(25, 50)
[string "LuaVM"]:5: 尝试索引一个 nil 值(全局数学")
我不能再使用 math.random 有什么办法可以解决这个问题吗?
如果缺少 math
库,您可以在脚本的开头插入以下代码块.
它不会修复整个 math
库,只会修复一些最常用的函数(包括 math.random
).
它还将修复以下错误:
'Sleep' 的错误参数 #1(数字没有整数表示)
<块引用>
尝试调用一个 nil 值(字段 'getn')
做本地 state_8, state_45, cached_bits, cached_bits_qty = 2, 0, 0, 0本地 prev_width, prev_bits_in_factor, prev_k = 0for c in GetDate():gmatch".";做state_45 = state_45 % 65537 * 23456 + c:byte()结尾本地函数 get_53_random_bits()本地值53 = 0对于 shift = 26, 27 做局部 p = 2^shiftstate_45 = (state_45 * 233 + 7161722017421) % 35184372088832重复 state_8 = state_8 * 76 % 257 直到 state_8 ~= 1本地 r = state_8 % 32本地 n = state_45/2^(13 - (state_8 - r)/32)n = (n - n%1) % 2^32/2^rvalue53 = value53 * p + ((n%1 * 2^32) + (n - n%1)) % p结尾返回值53结尾对于 j = 1, 10 执行 get_53_random_bits() 结束本地函数 get_random_bits(number_of_bits)本地 pwr_number_of_bits = 2^number_of_bits本地结果如果 number_of_bits <= cached_bits_qty 那么结果 = cached_bits % pwr_number_of_bitscached_bits = (cached_bits - 结果)/pwr_number_of_bits别的本地 new_bits = get_53_random_bits()结果 = new_bits % pwr_number_of_bitscached_bits = (new_bits - result)/pwr_number_of_bits * 2^cached_bits_qty + cached_bitscached_bits_qty = 53 + cached_bits_qty结尾cached_bits_qty = cached_bits_qty - number_of_bits返回结果结尾table = table 或 {}table.getn = table.getn 或 function(x) return #x end数学 = 数学或 {}math.huge = math.huge 或 1/0math.abs = math.abs 或 function(x) 返回 x <0 和 -x 或 x 结束math.floor = math.floor 或 function(x) 返回 x - x%1 结束math.ceil = math.ceil 或 function(x) return x + (-x)%1 endmath.min = math.min 或 function(x, y) 返回 x y 和 x 或 y 结束math.sqrt = math.sqrt 或 function(x) 返回 x^0.5 结束math.pow = math.pow 或 function(x, y) return x^y endmath.frexp = math.frexp 或函数(x)本地 e = 0如果 x == 0 那么返回 x, e结尾局部符号 = x <0 和 -1 或 1x = x * 符号而 x >= 1 做x = x/2e = e + 1结尾当 x <0.5 做x = x * 2e = e - 1结尾返回 x * 符号,e结尾math.exp = math.exp 或函数(x)本地 e, t, k, p = 0, 1, 1重复 e, t, k, p = e + t, t * x/k, k + 1, e直到 e == p返回 e结尾math.log = math.log 或函数(x)断言(x > 0)局部 a, b, c, d, e, f = x <1 和 x 或 1/x, 0, 0, 1, 1重复重复c, d, e, f = c + d, b * d/e, e + 1, c直到 c == fb, c, d, e, f = b + 1 - a * c, 0, 1, 1, b直到 b <= f返回 a == x 和 -f 或 f结尾math.log10 = math.log10 或函数(x)返回 math.log(x)/2.3025850929940459结尾math.random = math.random 或函数(m, n)如果 m 那么如果不是 n 那么米,n = 1,米结尾本地 k = n - m + 1如果 k<1 或 k >2^53 然后错误(函数'随机()'的无效参数",2)结尾局部宽度,bits_in_factor,modk如果 k == prev_k 那么宽度,bits_in_factor = prev_width,prev_bits_in_factor别的本地 pwr_prev_width = 2^prev_width如果 k >pwr_prev_width/2 and k <= pwr_prev_width 然后宽度 = prev_width别的宽度 = 53局部宽度_低 = -1重复局部 w = (width_low + width)/2w = w - w%1如果 k <= 2^w 那么宽度 = w别的宽度_低 = w结尾直到宽度 - width_low == 1prev_width = 宽度结尾bits_in_factor = 0本地 bits_in_factor_high = 宽度 + 1而 bits_in_factor_high - bits_in_factor >1 做本地 bits_in_new_factor = (bits_in_factor + bits_in_factor_high)/2bits_in_new_factor = bits_in_new_factor - bits_in_new_factor%1如果 k % 2^bits_in_new_factor == 0 那么bits_in_factor = bits_in_new_factor别的bits_in_factor_high = bits_in_new_factor结尾结尾prev_k, prev_bits_in_factor = k, bits_in_factor结尾本地因子、saved_bits、saved_bits_qty、pwr_saved_bits_qty = 2^bits_in_factor、0、0、2^0k = k/因子宽度 = 宽度 - bits_in_factor本地 pwr_width = 2^width局部间隙 = pwr_width - k重复modk = get_random_bits(width - saved_bits_qty) * pwr_saved_bits_qty + saved_bits本地 modk_in_range = modk <克如果不是 modk_in_range 那么局部间隔 = 间隙saved_bits = modk - ksaved_bits_qty = 宽度 - 1pwr_saved_bits_qty = pwr_width/2重复Saved_bits_qty = saved_bits_qty - 1pwr_saved_bits_qty = pwr_saved_bits_qty/2如果 pwr_saved_bits_qty <= 间隔然后如果saved_bits
local delay = math.random(25, 50)
[string "LuaVM"]:5: attempt to index a nil value (global 'math')
I can't use math.random anymore is there any way to fix this ?
If math
library is missed you can insert the following code block at the beginning of your script.
It will not fix the whole math
library, but only some of the most frequently used functions (including math.random
).
It will also fix the following errors:
bad argument #1 to 'Sleep' (number has no integer representation)
attempt to call a nil value (field 'getn')
do
local state_8, state_45, cached_bits, cached_bits_qty = 2, 0, 0, 0
local prev_width, prev_bits_in_factor, prev_k = 0
for c in GetDate():gmatch"." do
state_45 = state_45 % 65537 * 23456 + c:byte()
end
local function get_53_random_bits()
local value53 = 0
for shift = 26, 27 do
local p = 2^shift
state_45 = (state_45 * 233 + 7161722017421) % 35184372088832
repeat state_8 = state_8 * 76 % 257 until state_8 ~= 1
local r = state_8 % 32
local n = state_45 / 2^(13 - (state_8 - r) / 32)
n = (n - n%1) % 2^32 / 2^r
value53 = value53 * p + ((n%1 * 2^32) + (n - n%1)) % p
end
return value53
end
for j = 1, 10 do get_53_random_bits() end
local function get_random_bits(number_of_bits)
local pwr_number_of_bits = 2^number_of_bits
local result
if number_of_bits <= cached_bits_qty then
result = cached_bits % pwr_number_of_bits
cached_bits = (cached_bits - result) / pwr_number_of_bits
else
local new_bits = get_53_random_bits()
result = new_bits % pwr_number_of_bits
cached_bits = (new_bits - result) / pwr_number_of_bits * 2^cached_bits_qty + cached_bits
cached_bits_qty = 53 + cached_bits_qty
end
cached_bits_qty = cached_bits_qty - number_of_bits
return result
end
table = table or {}
table.getn = table.getn or function(x) return #x end
math = math or {}
math.huge = math.huge or 1/0
math.abs = math.abs or function(x) return x < 0 and -x or x end
math.floor = math.floor or function(x) return x - x%1 end
math.ceil = math.ceil or function(x) return x + (-x)%1 end
math.min = math.min or function(x, y) return x < y and x or y end
math.max = math.max or function(x, y) return x > y and x or y end
math.sqrt = math.sqrt or function(x) return x^0.5 end
math.pow = math.pow or function(x, y) return x^y end
math.frexp = math.frexp or
function(x)
local e = 0
if x == 0 then
return x, e
end
local sign = x < 0 and -1 or 1
x = x * sign
while x >= 1 do
x = x / 2
e = e + 1
end
while x < 0.5 do
x = x * 2
e = e - 1
end
return x * sign, e
end
math.exp = math.exp or
function(x)
local e, t, k, p = 0, 1, 1
repeat e, t, k, p = e + t, t * x / k, k + 1, e
until e == p
return e
end
math.log = math.log or
function(x)
assert(x > 0)
local a, b, c, d, e, f = x < 1 and x or 1/x, 0, 0, 1, 1
repeat
repeat
c, d, e, f = c + d, b * d / e, e + 1, c
until c == f
b, c, d, e, f = b + 1 - a * c, 0, 1, 1, b
until b <= f
return a == x and -f or f
end
math.log10 = math.log10 or
function(x)
return math.log(x) / 2.3025850929940459
end
math.random = math.random or
function(m, n)
if m then
if not n then
m, n = 1, m
end
local k = n - m + 1
if k < 1 or k > 2^53 then
error("Invalid arguments for function 'random()'", 2)
end
local width, bits_in_factor, modk
if k == prev_k then
width, bits_in_factor = prev_width, prev_bits_in_factor
else
local pwr_prev_width = 2^prev_width
if k > pwr_prev_width / 2 and k <= pwr_prev_width then
width = prev_width
else
width = 53
local width_low = -1
repeat
local w = (width_low + width) / 2
w = w - w%1
if k <= 2^w then
width = w
else
width_low = w
end
until width - width_low == 1
prev_width = width
end
bits_in_factor = 0
local bits_in_factor_high = width + 1
while bits_in_factor_high - bits_in_factor > 1 do
local bits_in_new_factor = (bits_in_factor + bits_in_factor_high) / 2
bits_in_new_factor = bits_in_new_factor - bits_in_new_factor%1
if k % 2^bits_in_new_factor == 0 then
bits_in_factor = bits_in_new_factor
else
bits_in_factor_high = bits_in_new_factor
end
end
prev_k, prev_bits_in_factor = k, bits_in_factor
end
local factor, saved_bits, saved_bits_qty, pwr_saved_bits_qty = 2^bits_in_factor, 0, 0, 2^0
k = k / factor
width = width - bits_in_factor
local pwr_width = 2^width
local gap = pwr_width - k
repeat
modk = get_random_bits(width - saved_bits_qty) * pwr_saved_bits_qty + saved_bits
local modk_in_range = modk < k
if not modk_in_range then
local interval = gap
saved_bits = modk - k
saved_bits_qty = width - 1
pwr_saved_bits_qty = pwr_width / 2
repeat
saved_bits_qty = saved_bits_qty - 1
pwr_saved_bits_qty = pwr_saved_bits_qty / 2
if pwr_saved_bits_qty <= interval then
if saved_bits < pwr_saved_bits_qty then
interval = nil
else
interval = interval - pwr_saved_bits_qty
saved_bits = saved_bits - pwr_saved_bits_qty
end
end
until not interval
end
until modk_in_range
return m + modk * factor + get_random_bits(bits_in_factor)
else
return get_53_random_bits() / 2^53
end
end
local orig_Sleep = Sleep
function Sleep(x)
return orig_Sleep(x - x%1)
end
end
这篇关于罗技 G-Hub 的最新更新中缺少数学库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!