lua-users home
lua-l archive

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


I know. The background of my question was: I like to hide functions inside functions hided inside functions. :) This helps me to make excessive use of code folding in ZBS and keeps things as local as possible.

But i was not sure, it slows down something.
Question answered :)

Ulrich.

Am 18.04.2016 um 16:04 schrieb Victor Bombi:
Yes but notice that:

function f1(val)
    local function f2()
        print val
    end;
    return f2
end;

aa = f1(2)
aa() -->prints 2
bb = f1(3)
bb() -> prints 3

----- Original Message ----- From: "Eduardo Ochs" <eduardoochs@gmail.com>
To: "Lua mailing list" <lua-l@lists.lua.org>
Sent: Monday, April 18, 2016 11:35 AM
Subject: Re: Question about local functions inside functions.


Function f2 becomes compiled ones when F1 becomes compiled?
yes.

Function f2 will be compiled every time i call f1?
no.

Btw, you can run this and then look at the output...

cd /tmp/

cat > test.lua <<'%%%'
function f1()
 local function f2()
   return "test";
 end;
 return f2()
end;
%%%

luac -p -l -l test.lua

 Cheers,
   E. =)

On Mon, Apr 18, 2016 at 6:21 AM, Ulrich Schmidt <u.sch.zw@gmx.de> wrote:
Hi all.

Imagine the following lua code:

--8<------------------------------------------------
function f1()
     local function f2()
       return "test";
     end;
     return f2()
end;
--8<------------------------------------------------

Question:
Function f2 becomes compiled ones when F1 becomes compiled?
or:
Function f2 will be compiled every time i call f1?

tia.
Ulrich.