lua-users home
lua-l archive

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


While there has been endless chatter about modules and the proper way
to write them, I don't think I've seen anyone discuss binary modules
with require'able sub-modules.  This is something I've gone back and
forth on a couple of times and in the end I think the deciding factor
is what is considered standard v. non-standard behavior, which is why
I'm labeling this as a poll.

Let's say I have a compiled binary module space.so with some
sub-modules.  I'm curious as to which of the following do people
consider "standard" as in cause the least surprise:

local space = require("space"
local vec3 = require("space.vec3")
print(table.concat(vec3.add({1, 0, 0}, {0, 1, 0}), " "))

or

local space = require("space"
local vec3 = space.vec3
print(table.concat(vec3.add({1, 0, 0}, {0, 1, 0}), " "))


In other words, should an embedded binary sub-module have to be
required before use or not?  As a comparison, Lua script modules can
be required this way, but they live is distinct files and are thus
visible in the file system this way.  This makes a big difference to
how require works, since for binary modules, I can't
require("space.vec3") without first requiring space since
space.vec3.so or some variation thereof doesn't actually exist and Lua
won't load the module just to check for a function pointer.  Any
thoughts?



wes