the python in codea (in lua)

hello,
im pretty new to codea (its soo great!) and i pretty much know my way around programming.
im coming from the pythonn language and i was thinking that its too bad that lua doesn’t have the dir() help() etc. function python has for every object

now i realize in lua not EVERTHING is an object like in python, but i came across a need to implicate a special iterable for my class or wanted to know which functions are avalable in the table class (without having to go to the manuals)

are those possible in lua or more specific in codea?

Hi @shachaf,

in fact, lua does not have classes at all. The class() function provided by codea is an add-on. table is not a class but in fact the only compound data structure available in lua. I suggest you don’t avoid reading the manual, it is really concise and has a nice overview of the functions. If I understand correctly what you want, you are probably looking for pairs() or ipairs().

im not avoiding from reading the manual, in fact i think its quite good
i guess im just used to python too much.

i had problems with the table.remove function (i didnt want to just “= nil”) so i decided to wrap table in my own class, but then i couldn’t iter it.

but i guess im just used to a different language (if you say lua doesn’t have classes even)

by the way, sorry for postting in the general, forgot to set it up to Questions

Well, you can make your own iterator function, for example:

t = {'a', 'b', 'c'}

function iter(tbl)
  local i = 0
  return function()
    i = i + 1
    return tbl[i]
  end
end

for i in iter(t) do
  print(i)
end

Some nitpicking: Not absolutely everything is a class in Python, plain numbers are plain numbers, so for example "1. _ _ doc _ _ " doesn’t work (you have to write "(1). _ _ doc _ _ ").

Apart from that, there’s a lot of imperative programming going on in Python, so you will not suffer from a total paradigm clash when using Lua.

Lua has classes (I hope you didn’t misunderstand gunnar_z) but simply not in the core. Lua has tables and especially meta tables which allow the construction of classes in the Lua language itself, but this is a detail that no “regular” programmer has to care much about. You have classes, feel good.

By the way, Tcl for example also only got objects in the core recently, most Tcl object systems to date are written in Tcl itself (the Tk in Tcl/Tk is a great example of what you can do without core support for such things). See, Lua is in good company.

@codeslinger nope, lua does not have classes. It does have mechanisms for you to create your own OO system, if you want. And there are quite a few of those around… so the correct phrase would be “there are libraries available for lua, that implement classes, and codea comes with one of those”. If you want to see codea’s implementation, it is here:

https://github.com/TwoLivesLeft/Codea-Runtime/blob/master/CodeaTemplate/Codify/Resources/Lua/Class.lua

Information about classes in Lua and Codea can also be found on this page on the wiki.