lua-users home
lua-l archive

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


To understand what is happening here, try the following

 

-- define func

local function func()

    return 10, 11

end

 

-- use func

b, c = func()

print("use original func ", b, c)

 

-- redefine func

local func = function() end

 

-- use new definition of func

b, c = func()

print("use redefined func ", b, c)

 

 

From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On Behalf Of Marius Booysen
Sent: 29 July 2013 13:43
To: lua-l@lists.lua.org
Subject: functions is lua

 

Just starting with lua and I wanted to test multiple return values from a function. I then ran into forward declaring issues (which I still am not clear on how it works), so I ended up with this code:

Code: [Select]

#!/usr/bin/lua


local func = function() end

b, c = func()

print(b, c)

local function func()
    return 10, 11
end

When I execute is, it prints nil nil for the b and c.

Do all functions need to be complete before I can call it in Lua?

Thanks!

**************************************************************************************** Note: If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. ****************************************************************************************