lua-users home
lua-l archive

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


It uses arbitrary strings as identifiers, so:

    import "lua.io.InputStream"

Speaking of which, bundles are basically directories (MacOS X defines them
more specifically, but for these purposes directories will do). We include a
special "info.lua" file in the directory that says something like:

info.lua:

    return {
        exports = {
            [ "com.baymoon.Stack" ] = "collections.lua",
            [ "com.baymoon.Queue" ] = "collections.lua",
                -- two exports from one file
            [ "com.baymoon.Matrix" ] = "C:load_matrix"
                -- assumes a single library DLL in which we
                -- will find the symbol load_matrix
        }
    }

Bundles can load piecemeal. If we import stacks or queues but not matrices,
then load_matrix won't get called.

If while loading a Lua file, it wants to make use of other code, for
example, we might have some shared utilities that were used by multiple
files in the bundle but not to be exported themselves, we make use of the
bundle-specific require. Thus, collections.lua can say:

    require "utilities.lua"

Or

    require "C:load_utilities"

This will use something much like the existing require mechanism to see that
the code runs exactly once and will run the appropriate code from within the
bundle. It does not go through the mapping provided by info.lua but just
uses filenames.

I'm not sure keeping the name "require" was entirely the right thing to do
but my replacement seemed more or less in keeping with the spirit of the
existing code.

Mark

on 7/25/04 3:56 AM, Vijay Aswadhati at wyseman@pacbell.net wrote:

> 
>> We've also built an import mechanism in which one issues a call:
>> 
>>    import "name"
>> 
> 
> Cool. Does your "import" feature handle hierarchy?
> As in Java: 
> <code>
> import java.io.InputStream;
> </code>
> 
> Assuming the "bundle" has InputStream among other resources.
> 
> --v.a
> 
>