Ehm, I was wrong:
> Namely, it seems that each time you switch a tab to a document in
> Scite, it seems that Scite's "current directory" is also changed to
> the directory of the document in the tab.
Nope, correction: it turns out to be more specific than that - if you
turn to a different tab AND execute one of your own lua scripts
(stored in luaSciteFunctions.lua); THEN the problem with changing the
"current directory" of lua occurs (otherwise not by simply changing
tabs).
The most straightforward way to fix that is to simply add the home
directory to lua's package.path; however, since lua is in Scite's case
running as a module, it doesn't have a reference to argv[0]. So this
is what worked for me, as a sort of a "preamble" for
luaSciteFunctions.lua:
---------
-- get home dir from shell
myHomeDir=io.popen("pwd"):read("*a")
-- the returned string contains an enter; remove it
-- (last character on end is -2)
myHomeDir=myHomeDir:sub(1,-2)
-- append myHomeDir to lua package.path
package.path = package.path .. ";" .. myHomeDir .. "/?.lua"
-- print to Output Pane to check if all good
print(package.path)
---------
However, before I figured that out, I was messing with a solution
based on lfs for Lua - which also works, but you have to install a
separate package; and then have lua in Scite use it.. So it is a bit
of work, so I'll dump also some of my notes for that below...
Anyways, hope this helps someone,
Cheers!
---------
Some useful links:
-- Change directory in Lua -
http://forum.luahub.com/index.php?topic=2839.0
-- LuaFileSystem -
http://keplerproject.github.com/luafilesystem/manual.html#reference
-- Lua: Modules: package.loaders -
http://pgl.yoyo.org/luai/i/package.loaders
-- Convenient Lua Features: package.preload « Play With Lua! -
http://www.playwithlua.com/?p=11
-- Programming in Lua : 8 - Compilation, Execution, and Errors -
http://www.lua.org/pil/8.html
-- Re: loading lua scripts relative to an app's path -
http://lua-users.org/lists/lua-l/2006-10/msg00200.html
A separate binary has to installed for lfs (lua-filesystem); on Linux
it is "lfs.so"
-- sudo apt-get install lua-filesystem # not in my old version
-- wget
http://launchpadlibrarian.net/48263173/liblua5.1-filesystem0_1.4.2-3_i386.deb
; sudo dpkg -i *.deb
That package installs in /usr/lib/lua/5.1/lfs.so; have to tell Scite's
lua to find it - by appending its location to package.cpath:
-- append to cpath location of lfs.so
package.cpath = package.cpath .. ";/usr/lib/lua/5.1/?.so"
print(package.cpath) -- for .so stuff
If you don't know this about cpath, one could have also used
package.preload; here is how you would load an .so file (along with
wrong syntax examples)
-- package.preload['lfs'] = "/usr/lib/lua/5.1/lfs.so" # NO; needs to
be function()!
package.preload['lfs'] = function()
------------ return "/usr/lib/lua/5.1/lfs.so" -- no!
local f = assert(loadfile("/usr/lib/lua/5.1/lfs.so"))
return f()
end
Finally, with lfs loaded, one can use lfs.chdir("/absolute/path") to
set the current directory which lua within Scite sees; I ran the
following snippet for debugging purposes:
require"lfs"
print(lfs) -- if ok, should be table: 0x9ffef58
print("pwd")
os.execute("pwd")
print(io.popen("pwd"):read("*a"))
--~ print(os.currentdir()) -- noexist
print(lfs.currentdir())
print("pwd2")
os.execute("cd ~") -- only in subshell; cd nowork back here
print(io.popen("cd ~"):read("*a")) -- only in subshell; cd nowork
back here
os.execute("pwd")
print(lfs.currentdir())
lfs.chdir("~") -- nowork on linux (~ is shell expansion)
print(lfs.currentdir())
lfs.chdir("/home/username") -- works fine
print(lfs.currentdir())
On May 22, 2:01 pm, sdaau <
s...@imi.aau.dk> wrote:
> Just wanted to post back, in response to this thread:
>
> Re: [scite] Startup issue -
>
http://www.mail-archive.com/scite-inter...@lyra.org/msg03855.html