Installation/starting directory
Installation/starting directory
Would be fine to have a NewLisp function to get the running executable directory of newlisp.exe.
The trick to query the environment variable PROGRAMFILES to get the installation directory, as shown in newlisp-edit.lsp, does not work if I install
(for example) on another disk.
Then it would be fine to update all the gs examples to use
such a new function.
Regards
Maurizio
The trick to query the environment variable PROGRAMFILES to get the installation directory, as shown in newlisp-edit.lsp, does not work if I install
(for example) on another disk.
Then it would be fine to update all the gs examples to use
such a new function.
Regards
Maurizio
You can check against a directory pattern for the newlisp directory using this env syntax from the docs:
You could write a simple function definition to iterate through a list of possibilities and evaluate to the first that is true, but that might not help if you don't know the possibilities ahead of time (such as newLisp running from a dynamically mapped drive in Windows).
In Windows, you could write a batch script that sets the current working directory as an environment variable and then read env for that variable in newLisp. Something like:
batch file:
newlisp:
Code: Select all
(println (env "NEWLISPDIR" "/usr/bin/"))
In Windows, you could write a batch script that sets the current working directory as an environment variable and then read env for that variable in newLisp. Something like:
batch file:
Code: Select all
set WORKING_DIR=%CD%
%CD%\newlisp.exe somescript.lsp
Code: Select all
(set 'working_dir (env "WORKING_DIR"))
years ago I did something like this:
this is the C prototype of the function:
I don't have access to a Windows machine at the moment, and I am not sure if kernel32.exe is the right library (consult a Win32 SDK reference or ask HPW), but I remember it worked well.
Lutz
Code: Select all
(import "kernel32.exe" "GetModulePath")
(set 'path (dup "\000" 256))
(GetModulePath 0 path 256)
path -> "C:\\Progamm Files\newlisp\newlisp.exe"
Code: Select all
DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize );
Lutz
Take a look here:
http://www.alh.net/newlisp/phpbb/viewto ... t=kernel32
Or:
http://www.alh.net/newlisp/phpbb/viewto ... t=kernel32
Or:
Code: Select all
(import "kernel32.dll" "GetModuleFileNameA")
GetModuleFileNameA <77E90AA8>
> (set 'path (dup "\000" 256))
"\000\000\000\000 ..."
> (GetModuleFileNameA 0 path 256)
32
> (string path)
"C:\\Programme\\newlisp\\newlisp.exe"
>
Hans-Peter
There are really two directories, one is the executable path and the other the path where the modules and util are located. Which is the path we want to have present in an environment variable?
On Windows they are the same, but not on UNIX. On UNIX almost always a newLISP program is started from a script, and then the bin path is present in (main-args).
It seems, the only thing we need then is NEWLISPDIR for the path to modules and util, which is the same for the executable on Windows.
Lutz
On Windows they are the same, but not on UNIX. On UNIX almost always a newLISP program is started from a script, and then the bin path is present in (main-args).
It seems, the only thing we need then is NEWLISPDIR for the path to modules and util, which is the same for the executable on Windows.
Lutz
What would be great is a set of variables to cover all of them. One to say where the newlisp executable is, one for the execution directory (albeit the same in Windows), and perhaps one for the global modules directory.
The initialization could check for default environmental variables that may be user set and if they do not exist, set them to the current environment. That way, in a custom configuration (such as a custom modules directory, whatever), the user could override them.
A lot of scripting languages do that or something similar to that.
The initialization could check for default environmental variables that may be user set and if they do not exist, set them to the current environment. That way, in a custom configuration (such as a custom modules directory, whatever), the user could override them.
A lot of scripting languages do that or something similar to that.