# Recent content by GavinW

1. ### Help Lua code

Looks like you made two typos and upped the case of 'l' and 'i' in function luai_244288.
2. ### How works _G and _ENV and what can I do with them?

Herly, I recommend that you buy Programming in Lua (Fourth Edition) by Roberto Ierusalimschy, if you do not yet have it. You won't regret it. Chapter 22 (The Environment) is what you need. All variables in Lua are either keys in a table or are local to a chunk. So-called global variables are...
3. ### Can an anonymus function call itself?

Thanks. I thought it was something like that. My personal preference for the unsugared syntax is because the sugar seems to me to be unnecessarily apologetic. It is just because many Lua users come from a first-order background, rather than a higher-order one, that they should perhaps be...
4. ### Can an anonymus function call itself?

The Y combinator as given above provides a means of doing this. Its crucial property is that Y(f) reduces to f(Y(f)) - the fixed-point property. Using it makes it possible to rewrite definitions without explicit recursion. Thus, in the remarks above, Y(F) does the same as fact. You get F from...
5. ### Can an anonymus function call itself?

OK. The factorial function imay be given by (function (g) return ( function (f) f = g ( function (x) return (f (x)) end) return f end) end ) ( function (h) return function (n) return (n<2) and n or n*h(n-1) end end)There are no named functions here. But naming is only a way of making...
6. ### Can an anonymus function call itself?

It looks like my first suggestion does not work. I think what you are asking for is how to do a calculation likefunction fact (n) return (n<2) and n or n*fact(n-1) end print (fact(4)) --> 24without using a recursive function definition. What about this?local Y = function (g) return (function...
7. ### Can an anonymus function call itself?

You could use a fixed-point combinator. For example Y = function (f) local g = function (x) return f ( x (x)) end return g(g) end
8. ### How does an operation that relates to a value relate to a table that is in order.

t = { val = 3, func = function (self) print (self.val) end, } t:func ( ) -- > 3

If you find yourself writing a program with sets (as opposed to ordered sets) in it, then you probably have the wrong algorithm.
10. ### Lua 'end' syntax

comment For the sake of two hyphens you can have your cake and eat it end -- comment

You cannot. In Lua 5.2 loadstring is replaced by load which can take an environment as its fourth argument, but that will not help you with using a local variable.
12. ### metatables do not work!

Change the first line from local CLASS = { to local CLASS; CLASS = { The variable CLASS is not in scope when you use it in line 6.
13. ### How would I create a Lua interface so the user can write his/her code in a startup() method and a runloop() method

Forgive me, but I find this very opaque. Finish what? To do the same as what? Please remember that us mortals are not telepathic. I use an operating system in which the window manager is the task-manager and user-applications have to co-operate with it if they want to use the graphical user...
14. ### How do i overwrite an variable inside an if loop

What about this? function (xmid, im) local top_margin = 1 for y = 0, xhalf do local c1 = im.get_pixel (xmid, y) if c1.alpha < 20 then top_margin = y + 1 end -- if end -- for return top_margin end -- function
15. ### Roblox How to use tonumber, but with text instead of numbers?

Use a local variable? Look up automagic on the Lua wiki?