似乎没有得到lua的参考,但只有价值

时间:2018-10-11 14:50:15

标签: lua love2d luajit

我正在获取保存在表中的组件(我使用特殊的系统来提高内存效率)。然后我给它们作为给定函数中的参数(使用unpack语句(我已经检查过这不是原因))。到目前为止,我已经获得了保存在表中的值。但是,如果我更改它,表中的组件不会更改值。简而言之:我想通过引用给出组件,但我通过值给出。我以为Lua总是通过引用提供存储在表中的值。任何帮助,将不胜感激。如果您需要任何其他资源,请询问:)。预先谢谢你

function pool:run(dt)-- runs all active systems
local sprite = self.img
for i, method in ipairs(self.mPool) do
    if method[1] then
        --finds entities with required components
        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
        --get components of entities
        local components = {}
        for x=1, #method[3] do
            components[x] = {}
            local marker=1
            local savePosition = 1
            for Eid=1, matches[#matches] do-- Eid = entity 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
        --reorder and run as coroutine or function
        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

结束

1 个答案:

答案 0 :(得分:0)

问题是,如果将变量设置为表内容的值,则将设置值而不是引用。