# Search results

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
9. ### Sets please

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
11. ### How to loadstring()?

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?
16. ### RISC OS LUAJIT

A friend has pointed out where uname appears in the makefile. It comes in a swathe of stuff to determine what platform is being used, so I can simply comment it all out and insert the answer. This exposes the next layer of the problem for me: the confusion caused by the overlapping of...
17. ### RISC OS LUAJIT

RISC OS uses '.' as directory separator symbol. So anybody translating between Unix and RISC OS filenaming is faced with certain problems. The usual, and simplest arrangement, is simply to exchange the symbols '.' and '/'. So change foo.c to foo/c. However, back in the mists of Acorn's early...
18. ### RISC OS LUAJIT

Many thanks for your heroic efforts. Floating point was always a weak point for Acorn. Early ARM CPUs simply did not have it. RISC OS does not use it, I think. So matters like saving and restoring FP contexts are murky corners. By contrast gcc is super finicky on these things. Compilers need to...
19. ### RISC OS LUAJIT

In that case I expect you browse OSNews. I always found Thom Holwerda's pieces interesting. Have you come across linear logic? The linear lambda calculus does for operating systems what the ordinary one does for general programming - that is to say it restricts to resource-preserving...
20. ### RISC OS LUAJIT

Well, RISC OS was designed for dilettantes. The OS consists of a kernel, plus independently replaceable modules (what an overloaded word that is!) which provide *commands and software interrupts, which user software can exploit. If you don't like the way something works, replace the relevant...