lua-users home
lua-l archive

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


On 01/09/2018 08:52 PM, philippe.castagliola@free.fr wrote:
> Dear Lua users,
> 
> I face a situation I do not understand.
> 
> I wrote a simple file "essai.lua" containing :
> 
> -- 
> function essai1()
>   print(debug.getinfo(1,"n").name)
> end
> 
> essai1()
> -- 
> 
> When I do
> 
> $ lua essai.lua
> essai1
> 
> This is logical to me.
> 
> Now, if I start lua and *copy and paste* the same code as in "essai.lua", I have
> 
> $ lua
> Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
>> function essai1()
>>>   print(debug.getinfo(1,"n").name)
>>> end
>>
>> essai1()
> nil
> 
> [...]
>
> Philippe

Wrap in do-end block. (I dont know why it works either.)

  Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
  > function essai1()
  >>   print(debug.getinfo(1,"n").name)
  >> end
  >
  > essai1()
  nil
  > do
  >> function essai1()
  >>   print(debug.getinfo(1,"n").name)
  >> end
  >>
  >> essai1()
  >> end
  essai1


-- Martin