[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: extending vs. embedding.
- From: Alexander Gladysh <agladysh@...>
- Date: Wed, 27 Apr 2011 23:32:31 +0400
On Wed, Apr 27, 2011 at 22:46, Javier Guerra Giraldez
<javier@guerrag.com> wrote:
> On Wed, Apr 27, 2011 at 1:32 PM, Emmanuel Oga <emmanueloga@gmail.com> wrote:
>> It talks about python but I'm wondering if it applies also for lua.
>> After reading it I'm thinking the best option will be to write a
>> loadable module that could be used by any lua interpreter
> absolutely.
> not only it's more 'Lua-like', but it allows your module to be used on
> any Lua project. embedding Lua means that any use has to be roughly
> on the terms you've foreseen. a module is _far_ more flexible, others
> will use it in ways you couldn't imagine before.
Also, the "command line tool" to run it could be as simple as
following (you can omit extra_path if you don't need it).
#! /usr/bin/env lua
local extra_path = assert(select(1, ...), "missing extra_path")
local module_name = assert(select(2, ...), "missing module_name")
local function_name = assert(select(3, ...), "missing function_name")
if extra_path ~= "" then
if extra_path:sub(#extra_path) ~= ";" then
extra_path = extra_path .. ";"
end
if package.path:sub(#package.path) ~= ";" then
package.path = package.path .. ";"
end
package.path = extra_path .. package.path
end
local module = require(module_name)
assert(
module[function_name],
"module does not export specified function"
)(select(4, ...))
Alexander.