[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [poll] require & binary module interfaces
- From: Wesley Smith <wesley.hoke@...>
- Date: Wed, 20 Oct 2010 21:12:27 -0700
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