[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Path and CPath Question
- From: Gaspard Bucher <gaspard@...>
- Date: Wed, 22 Dec 2010 18:08:04 +0100
I use a pure lua approach to deal with shared objects dependency:
1. change package.path and package.cpath to point to where you store
code and lua files
2. use lua files to manage dependency. For example this is the
"mdns.Browser" file:
[=========
require 'mdns.Browser_core' --- contains the "C" code and creates the
mdns.Browser table.
require 'worker' -- other dependency (also a Lua file)
--- rewrite "new" method
local worker = worker
local constr = mdns.Browser
function mdns.Browser(service_type, func)
return constr(worker, service_type, func)
end
==========]
And this is the "mdns.lua" file
[=========
mdns = Autoload('mdns')
require 'mdns.core' -- most of the code shared by all classes for mdns.
==========]
All this works transparently for the user with the Autoload module so
that when the user writes:
[=========
require 'rubyk' --- this alters the load path and installs autoload
browser = mdns.Browser(...) --- first autoload "mdns", then "mdns.Browser"
==========]
G.
2010/12/22 "J.Jørgen von Bargen" <jjvb.primus@gmx.de>:
> Am 22.12.2010 16:43, schrieb Terry Bayne:
>>
>> The context is Lua embedded in a host program. Various modules and
>> additional Lua files are stored in a subdirectory (/HostAppDir/modules and
>> /HostAppDir/LuaFiles) located at the root directory of the the host program.
>>
>> Given the directory names shown, what would be the proper way to set the
>> PATH and CPATH so that the require statement works correctly for locating
>> DLLs and additional Lua files?
>>
>> And I assume I should set those values in the Lua Environment BEFORE
>> loading my main Lua file.
>>
>> Am I even close?
>
> There are different issues in this topic.
>
> * package.path is used, when require searches for a lua-module.
> * package.cpath is used, when require searches for a dll/shared lib.
>
> BUT
>
> * when the dll/shared lib depends on other dlls/shared libs, the search path
> for these are completely outside the control of lua. For windows the
> environmentvariable PATH is used, for linux LD_LIBRARY_PATH may be used (see
> man ld.so)
>
> So you might have to set these environment variables for the process either
> before calling it or inside the main program before using require or
> similar.
>
> Regards, Jørgen
>
>
>