lua-users home
lua-l archive

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


On Thu, Dec 20, 2012 at 11:47 AM, Geoff Leyland
<geoff_leyland@fastmail.fm> wrote:
> function expression.__add(a, b)
>   return add:new{a, b}  -- I could 'require("add")' it here?
> end

This will work, and keeping a local module ref and setting it if not
already set is probably the most efficient solution:

local add

function expression:__add(a,b)
   if not add then add = require 'add' end
   return add:new(a,b)
end