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

Search results

  1. stetre

    Lua HTTP client

    See the doc in the repo, at luasocket/doc/http.html (unfortunately the online version no longer exists).
  2. stetre

    Lua HTTP client

    The de facto standard TCP/IP library for Lua is LuaSocket. It should also be available as a 'rock' (methink... not sure because I don't use LuaRocks).
  3. stetre

    How works _G and _ENV and what can I do with them?

    You can think of _ENV as a table that implicitly holds your global variables. For example, try running the lua shell and executing the following in it (here the > is the shell prompt): > x = "this is x" > print(_ENV.x) > _ENV.x = "this is _ENV.x" > print(x) You'll see that the value of...
  4. stetre

    Instance scripts?

    Concurrent programming is a very important topic, but also very interesting! You will surely encounter it often, since it comes up almost naturally in all sorts of situations. A related and partiallly overlapping topic is parallel programming, which is also very important (and interesting) and...
  5. stetre

    Instance scripts?

    I'm not familiar with CoreGames but I can easily guess the presence of _ENV, here, and of a concurrency model. These are programming models where you have similar entities running concurrently, each in its dedicated context, and possibly with mechanism to synchronize and communicate with each...
  6. stetre

    Is there a way to reffer a table itself inside the same table?

    I honestly don't know. My guess is that it shouldn't be very different, but of course if you are doing really heavy computations the differences could add up to the point of being relevant. To have a more precise idea you should do some measures. In my opinion, however, when you feel the need...
  7. stetre

    Is there a way to reffer a table itself inside the same table?

    They should be faster, but the comparison is meaningful only in the case that the table doesn't have a metatable, in which case they probably aren't that faster since the lack of a metatable is detected almost immediately. On the other hand, if the table has a metatable then their behaviour is...
  8. stetre

    Weight Table issue...

    As the name says, the Lua interpreter is an interpreter, not an oracle. You need an oracle to make sense of expressions like this one: {Item =} z,Min =} {weighttotal+1,Max} = weighttotal + p} Try replacing it with a well-formed expression, and possibly one that results in the value you...
  9. stetre

    Is there a keyword for decrypt ?

    The problem is in how you built the for loop. That's not how it works in Lua (see here). To iterate over the characters of a string you can use utf8.codes, for example: for p, c in utf8.codes("il gatto e la volpe") do print(p, c, utf8.char(c)) end
  10. stetre

    Is there a keyword for decrypt ?

    It's not a keyword. There are very few of them, as you can see here. If you'd like people to help you, you should at least post the error message.
  11. stetre

    Is there a way to reffer a table itself inside the same table?

    To chain metatables you have to set the __index field of the metatable of the child, not the metatable of the child. See the example I posted earlier. I know it's a bit confusing. Think like this: when Lua tries to access a non existing field of a table, it looks if it has a metatable, and if...
  12. stetre

    Optional Library

    The mymath.lua module is not in one of the locations where require() looks for modules to load, which are the locations listed in the error message. You have two options, here: either you move mymath.lua in one of those locations (for example in the same directory as the module that requires...
  13. stetre

    Lua compiler

    Even on Windows, once you have Lua installed (see @Sonazuma 's last post) you should be able to execute the Lua interpreter from the Windows prompt, like this: lua.exe yourfile.lua This should work, as long as the path to lua.exe is listed in the PATH variable.
  14. stetre

    Is there a way to reffer a table itself inside the same table?

    I don't like OOP that much. I find that it almost always leads to overly complicated software architectures that are both difficult to understand and hard to maintain. Which is ironic since one of its biggest selling point is (or was) that it helps producing code that is more maintainable. This...
  15. stetre

    Is there a way to reffer a table itself inside the same table?

    That's what inheritance is for: making things hard to understand, with almost none of the heralded benefits (like most oop, btw). However, if you reeeeeally want to do it, you just have to realize that the tables you assign to fields like __index and __newindex are regular tables, so they also...
  16. stetre

    How do I remove an entry from a table by its index?

    Yes, that's also an option. Keep in mind, however, that table.remove changes the keys (the indices) of all the entries that come after the entry you remove.
  17. stetre

    How do I remove an entry from a table by its index?

    Your subsequent entries are still there. However, by removing the entry you insert a hole in the table, so it is no more a sequence and ipairs( ) won't work any more. You have to iterate with pairs( ) instead. See the linked manual entries for more details.
  18. stetre

    Can an anonymus function call itself?

    It's equivalent, I tested it and it works. What you cannot do is this: local f = function(x) if Cond then f(x) end end -- doesn't work: f is nil inside the body func(f) I'm not sure why, but I presume it's because in this case the variable f doesn't exist yet when the the right-hand...
  19. stetre

    Can an anonymus function call itself?

    I may be wrong, but I don't think you can. To call a function you need a reference to it (i.e. a name) even if you do it within the function itself. I'm afraid you have to define the argument function in advance, like in the code below. Is this a problem? local function f(x) if Cond then...
  20. stetre

    Where can I find the values of things like 'LUA_OK'

    The value of LUA_OK is defined in the header file lua.h (it is 0, by the way). As for build instructions, see here under "Building": https://www.lua.org/download.html
Top