[PD] Lua: request for 'require'...
claudiusmaximus at goto10.org
Mon May 19 15:15:51 CEST 2008
Mike McGonagle wrote:
> Over the weekend I was working with PDLua and found that I can only use
> 'require' to load things from a specific location that is NOT in the PD
> path. Basically, I am trying to use some objects that I wrote using the
> standalone lua interpreter, so I figured that I would be able to include
> them in the same directory as the referencing .pd_lua file, but I guess I
> was wrong in that assumption.
> Is there some reason why 'require' won't load a .lua file like this?
Yes, require from Lua doesn't know where the .pd_lua file was loaded
from. I'll have to research if it's possible to work like you suggest -
I guess before running the .pd_lua script I could add the path to Lua's
path then remove it again after it's loaded.
> only other method I can think of is to include all of my .lua files into the
> same source file for my .pd_lua objects.
There is support for one-off execution of .lua scripts found via Pd's
path (relative to the object instance, not the original source file),
use it like self:dofile("myscript.lua").
Alternatively, you could make mylib.pd_lua that registers multiple
objects and contains the common support code, and use it like:
pd -lib lua -lib mylib
Neither of these are ideal, though.
More information about the Pd-list