lua-users home
lua-l archive

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


Vineet Jain wrote:
I need to find out (dynamically) if a certain lua module has some functions and variables defined. I also need to set some module variables (dynamically).

If your module follows 5.1 package system...


local mod = require 'mymodule'

if mod.somefunction~=nil then
    print("Module has somefunction")
end

if mod.someattr == "MagicKey" then
    print("Module has the secret. Don't tell anyone")
    mod.GotThePower = true
end



By "if your module follows 5.1 package system" I mean:

-- mymodule.lua

module("mymodule")

someattr = "MagicKey"

function somefunction(...)
end

function conspiracy()
    if (GotThePower) then
        print ":D"
    end
end

-- end of mymodule.lua


A module is, usually, a table with functions and other values inside it. That Simple(tm).

Good luck,
me.