lua-users home
lua-l archive

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


On Friday 04 February 2011 02:16:44 Axel Kittenberger wrote:
> Maybe its helps when understanding C function pointers better, its no
> magic difference. In Lua its just,that every function is actually a
> function pointer. Maybe this example helps as well:
> 
> function a(arg)
>   print("a prints: "..arg)
> end
> 
> function b(arg)
>   print("b prints: "..arg)
> end
> 
> x = a
> y = b
> 
> function do()
>   x("one")
>   y("two")
>   print()
>   x, y = y, x
> end
> 
> do()
> do()
> do()
> 
> Now guess what it will print (as long I didnt make a typo)

It did what I guessed it would do, but not until after I changed reserved word 
do to doo. Doh!

:-)

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt