Lua中似乎不能引用,只能使用值

我正在获取保存在表中的组件(我使用一个特殊的系统以提高内存效率)。然后我使用 unpack 语句将它们作为参数传递给给定的函数(我已经检查过它不是原因)。到目前为止一切顺利,我获得了保存在表中的值。但是,如果我改变它,表中的组件的值不会改变。简而言之:我想通过引用传递组件,但我却通过值传递组件。我认为Lua总是通过引用给出保存在表中的值。如果您需要任何其他资源,请随时询问 : )。提前感谢

function pool:run(dt)-- 运行所有活动系统
local sprite = self.img
for i, method in ipairs(self.mPool) do
    if method[1] then
        --找到具有所需组件的实体
        local matches = {}
        for x=1, #self.ePool do
            if band(self.ePool[x][1], method[2]) == method[2] then
                matches[#matches+1] = x
            end
        end
        --获取实体的组件
        local components = {}
        for x=1, #method[3] do
            components[x] = {}
            local marker=1
            local savePosition = 1
            for Eid=1, matches[#matches] do-- Eid = 实体 id
                if Eid == matches[marker] then
                    components[marker][#components[marker]+1] = self.cPool[method[3][x]][savePosition]
                    marker = marker +1
                end

                if self.cBool[method[3][x]][Eid] then
                    savePosition = savePosition +1
                end
            end
        end
        --重新排序并作为协程或函数运行
        if method[5] then
            for x=1, #components do
                coroutine.wrap(method[4])(matches[x], unpack(components[x]), dt)
            end
        else
            for x=1, #components do
                method[4](matches[x], unpack(components[x]), dt)
            end
        end
    end
end
点赞
用户9150062
用户9150062

问题在于,如果你将一个变量设置为表格内容的值,那么只会设置值而非引用。

2018-10-11 17:34:01