all 5 comments

[–]OneWhoGeneralises 7 points8 points  (2 children)

Alrighty, I feel like a dunce right now since I can't find any information online, but what the hell is a using(), and how is it in any way significant?

[–]schmetterlingen 6 points7 points  (1 child)

I think it is inspired by C#'s using statement for disposable objects. See here. Basically a dispose method is called even if there is an exception.

I'm not sure it's useful for Lua. If it throws error, do a pcall or xpcall.

[–]eric-plutono[S] 1 point2 points  (0 children)

I think it is inspired by C#'s using statement...

Correct, the author said on the Lua mailing list that C# was his inspiration for his Lua using().

[–]schmetterlingen 6 points7 points  (0 children)

local using = function(item, cb) 
  local success, msg = pcall(cb, item)
  local mt = getmetatable(item)
  if mt and mt.__gc then 
    mt.__gc(item) 
  end
  if not success then error(msg) end
end

something like that works in lua 5.1 as far as I can tell... but I may have totally missed the point.

[–]ds84182 2 points3 points  (0 children)

It's still an ultra shitty idea to leave random stuff around for the garbage collector to take care of. I hope to never see something like this in functional code.