Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### 1. You really don't need to be worrying about "lag and performance." At this point you're misusing these terms.
- # 2. There are no different "types" of functions in Lua.
- Functions are their own data type, kind of like how strings and tables and so on are their own data type.
- The only differences of course would be how they're being used.
- Your first example is syntactic sugar (a nicer way to write something else) for
- ```lua
- local This
- This = function(x)
- print(x)
- end
- ```
- This makes `This` (no pun intended) an upvalue (external local variable) inside the function scope. This also allows for recursion. Your second example would not allow recursion.
- Let me use a famous example of recursion
- ```lua
- local function fact(num)
- if (rawequal(num, 0)) then
- return 1; --// 0! = 1
- end
- return num*fact(num - 1);
- end
- print(fact(5)); --> 120
- ```
- But if we wrote it in your second example's format:
- ```lua
- local fact = function(num)
- if (rawequal(num, 0)) then
- return 1; --// 0! = 1
- end
- return num*fact(num - 1);
- end
- print(fact(5));
- --> attempt to call a nil value (global 'fact')
- ```
- There is an "attempt to call a nil value" error.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement