昨天我和Lua搞混乱,偶然发现了'newproxy'功能.
http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#newproxy
我有点理解它,但我不确定它是如何有用的.我知道它会创建一个附加了元表的空白userdata对象(如果参数为true).
newproxy如何有用?这是我在搞乱它时所做的一个例子:
local proxy = newproxy(true)
local metatable = getmetatable(proxy)
metatable.__index = function(array, key) print(array, key) end
local y = proxy[100]
--[[
OUTPUT:
userdata: 0x443ad4b4 100
]]
Run Code Online (Sandbox Code Playgroud) 我正在创建一个Array类,为表添加更多用法.我有一个metamethod,允许我组合两个表,例如:
数组(5)..数组(6,10)应该给你{5,6,10}
我知道我可以使用两个循环来做到这一点,但我正在努力使我的代码尽可能干净和高效.解压缩我遇到了一个问题.我正在尝试连接两个表,但它不包括所有值.这是我的代码和输出:
local Array = {}
Array.__index = Array
function Array.__concat(self, other)
return Array.new(unpack(self), unpack(other))
end
function Array:concat(pattern)
return table.concat(self, pattern)
end
function Array.new(...)
return setmetatable({...}, Array)
end
setmetatable(Array, {__call = function(_, ...) return Array.new(...) end})
local x = Array(5, 12, 13) .. Array(6, 9) --concatenate two arrays
print(x:concat(", "))
Run Code Online (Sandbox Code Playgroud)
OUTPUT: 5, 6, 9 (I want it to be "5, 12, 13, 6, 9")
我刚刚为我的操作系统完成了一个非常简单的引导加载程序,现在我正在尝试切换到保护模式并跳转到内核.
内核存在于第二个扇区(在引导加载程序之后)并且打开.
任何人都可以帮我解决我的代码吗?我添加了评论,以显示我的困惑在哪里.
谢谢.
BITS 16
global start
start:
; initialize bootloader and stack
mov ax, 0x07C0
add ax, 288
mov ss, ax
mov sp, 4096
mov ax, 0x07C0
mov ds, ax
call kernel_load
hlt
kernel_load:
mov si, k_load
call print
mov ax, 0x7C0
mov ds, ax
mov ah, 2
mov al, 1
push word 0x1000
pop es
xor bx, bx
mov cx, 2
mov dx, 0
int 0x13
jnc .kjump
mov si, k_fail
call print
ret
.kjump:
mov si, …Run Code Online (Sandbox Code Playgroud) 据Lua说,我注意到了 2 ~= math.sqrt(2) ^ 2
print(2 == math.sqrt(2) ^ 2) --> false
print(2, math.sqrt(2) ^ 2) --> 2 2
Run Code Online (Sandbox Code Playgroud)
为什么会这样?