syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
Lua has what data types?

The types are listed at this URL:

http://www.lua.org/pil/2.html

We have these:

  • number
  • string
  • nil
  • boolean
  • function
  • table
  • thread
  • userdata

In Lua what is the thread type?

In Lua what is the userdata type?

Since we have a type named function, it seems natural to set a variable to the name of a function and then see if that variable can then act as a function:
dan@hp ~/ks/b/lua $
dan@hp ~/ks/b/lua $
dan@hp ~/ks/b/lua $ lua
Lua 5.3.0  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> myprint = print
> type(myprint)
function
> myprint(44)
44
>
dan@hp ~/ks/b/lua $
dan@hp ~/ks/b/lua $
dan@hp ~/ks/b/lua $
Yay! it looks like that idea works well.

This ability to have a variable act as a function leads to meta-programming opportunities.

syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me