• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Search results

  1. GavinW

    Help Lua code

    Looks like you made two typos and upped the case of 'l' and 'i' in function luai_244288.
  2. GavinW

    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. GavinW

    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. GavinW

    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. GavinW

    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. GavinW

    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. GavinW

    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. GavinW

    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. GavinW

    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. GavinW

    Lua 'end' syntax

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

    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. GavinW

    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. GavinW

    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. GavinW

    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. GavinW

    Roblox How to use tonumber, but with text instead of numbers?

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


    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. GavinW


    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. GavinW


    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. GavinW


    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. GavinW


    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...