lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Greetings!
    I believe I have a straightforward question here :)

In the following code:

===
function create()
    local e
    e.x = 0
    e.update = function(self)    -- mark
        self.x = self.x + 1
    end
    return e
end

e1 = create()
e2 = create()
e3 = create()
===

How many copies are created of the 'update' function at the marked line?
One, shared among e1, e2, and e3, or three, one for each of e1, e2, and e3?

I am planning on doing this sort of thing quite a bit in my current Lua
project and I'm concerned a bit about memory efficiency and such.

Thanks in advance,
~Nick