Claude, 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? The 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.
Mike
Mike McGonagle wrote:
Claude, 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.
The 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.
Mike
On 5/19/08, Claude Heiland-Allen claudiusmaximus@goto10.org wrote:
Mike McGonagle wrote: 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").
So, can I assume that this would effectively be the same as using "require"? I am sure there will be differences, but I am not trying to load a compiled binary, just curious if this has the same effect for .lua files...
Thanks a lot for all your work, Claude (et al), but I will say that this weekend was kind of frustrating, if not educational...
Oh, and obviously, I didn't have any trouble compiling from your sources that I got. Do you have a regular release schedule? Or do you post to the list when you make an update? I am just hoping to keep surfing this bleeding edge so I can have more weekends like this last... (just trying to be funny there...)
Mike
Hallo, Mike McGonagle hat gesagt: // Mike McGonagle wrote:
On 5/19/08, Claude Heiland-Allen claudiusmaximus@goto10.org wrote:
Mike McGonagle wrote: 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").
So, can I assume that this would effectively be the same as using "require"? I am sure there will be differences, but I am not trying to load a compiled binary, just curious if this has the same effect for .lua files...
As a workaround for now you could modify the Lua search path manually using something like:
package.path = "/my/pdlua/files/?.lua;" .. package.path
before any requires. This adds the pattern "/my/pdlua/files/?.lua" to the path require() searches for modules. Lua doesn't know about directories, so you cannot us something like "pwd" instead here, of course.
Do you think it would make sense to push the directory of a *.pd_lua file to the front of package.path automatically? I guess I think it would.
Frank Barknecht _ ______footils.org__
On Tue, May 20, 2008 at 1:18 AM, Frank Barknecht fbar@footils.org wrote:
Hallo, Mike McGonagle hat gesagt: // Mike McGonagle wrote:
On 5/19/08, Claude Heiland-Allen claudiusmaximus@goto10.org wrote:
Mike McGonagle wrote: 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").
So, can I assume that this would effectively be the same as using "require"? I am sure there will be differences, but I am not trying to load a compiled binary, just curious if this has the same effect for .lua files...
As a workaround for now you could modify the Lua search path manually using something like:
package.path = "/my/pdlua/files/?.lua;" .. package.path
Cool, I will check it out...
before any requires. This adds the pattern "/my/pdlua/files/?.lua" to the path require() searches for modules. Lua doesn't know about directories, so you cannot us something like "pwd" instead here, of course.
Do you think it would make sense to push the directory of a *.pd_lua file to the front of package.path automatically? I guess I think it would.
Yes, I think that something like this would be taken care of by the "environment", as this would force any and all code used in PD to be specific to PD, having to add code that is only used in PDLua. Also considering that PD allows you to load something from the same directory, then PDLua I would think should too. How is Vessel handling 'require'?
Mike
Ciao
Frank Barknecht _ ______footils.org__
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
self:dofile("myscript.lua").
I tried this as the following:
dofile("/absolute/path/to/myfile.lua")
and this works...
package.path = "/my/pdlua/files/?.lua;" .. package.path
I also tried this as follows
package.path = "/absolute/path/to/?.lua;" .. package.path require "myfile.lua"
and this works...
Thanks for your help.
Mike
Well, I also tried
require "/absolute/path/to/myfile"
and this worked, also... do note that there is no '.lua' at the end of the path/file name
Mike
On Wed, May 21, 2008 at 12:28 PM, Mike McGonagle mjmogo@gmail.com wrote:
self:dofile("myscript.lua").
I tried this as the following:
dofile("/absolute/path/to/myfile.lua")
and this works...
package.path = "/my/pdlua/files/?.lua;" .. package.path
I also tried this as follows
package.path = "/absolute/path/to/?.lua;" .. package.path require "myfile.lua"
and this works...
Thanks for your help.
Mike
-- Peace may sound simple—one beautiful word— but it requires everything we have, every quality, every strength, every dream, every high ideal. —Yehudi Menuhin (1916–1999), musician
Frank Barknecht wrote:
Do you think it would make sense to push the directory of a *.pd_lua file to the front of package.path automatically? I guess I think it would.
Yes, I guess I think I might be inclined to agree.
Now implemented in SVN head, tested very briefly. Untested with .pd_luax, probably needs a different mechanism there.
See "examples/complex*"