lua-users home
lua-l archive

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

Hello there,

I have several module files on disk which begin with the line:
module ("MODULENAME",package.seeall)

The MODULENAME values have no relationship to the filenames of these modules. Each file contains one module.

I have the filenames of these modules in an array and I need to call specific function (let's say "test_function()") in each of these modules.

I load the modules using "require" but "require" only returns "true" and I have no idea what is the real name of module which was just loaded.

I know I can return the module name from the module but the problem is, I am not allowed to modify these modules' source files in any way.

I thought about comparing the "package.loaded" table before and after each "require" and finding what was added but this doesn't work because each of the modules can in turn "require" other modules so there can be several modules added at once in this way.

Another possibility was to simply "require" all the modules and then iterate through the whole package.loaded table, finding all tables which have item with key "test_function" whose value is function (I know other modules don't contain this function). But this also doesn't work because the order is significant. I have to call the test_function() functions in exactly the same order their filenames are present in the original array.

Can this be done in pure Lua?

Frantisek Fuka
(yes, that IS my real name)
(and it's pronounced "Fran-tjee-shek Foo-kah")

Jabber/GoogleTalk ID: