lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Diego - Red Baires wrote:

Hi everyone, my name is Diego and i am a newbie trying to
learn LUA. the following are some questions because i couldnt
f¡nd information about it. could you help me pls ?

1) does LUA accept some kind of try/catch structures ? any example ?

you could use pcall (it's in the manual) : I use it to invoke user-supplied "callback" routines.


2) will GC free this NIL assignments ?

t = {}
i = 10;
t[1] = "diego";
t[2] = "martin";

-- do something...

t = nil;
i = nil;
collectgarbage("collect")

Yes

3) is there a way to create an array of a structured type ? something like this

mytype = struct {
  s : string;
  i : int;
}

var myarray : mytype;

myarray [1].s = "diego";
myarray [1].i = 10;
myarray [2].s = "martin";
myarray [2].i = 2;


There are many OO frameworks around for Lua involving metatables, but as the simplest case :

local myarray = {}
myarray[1] = {s="diego",i=10}
myarray[2] = {s="martin",i=2}



4) suppose this scenario: i run a LUA script inside a process.
the process receives a finish-application message.
does it exists any "terminated" flag to know this "terminating process"

i mean, how do i have to do to exit an infinit loop ?

while not(lua.terminating)
  -- do loop
end

I'll leave that for someone else.

Adrian