I have a simple script that I want to import into another with require, but when I run it from Notepad++ I get the usual error that require produces.
The funny thing is that it worked an hour ago and I did not restart the computer since then.
The files are in the same directory, so the simple file name (without .lua) worked and should still work. (relative path)
Lua runs the script just fine.
this is what I entered in Notepad:
cmd /k lua "$(FULL_CURRENT_PATH)"
Earlier I also had a problem with Penlight, maybe there is some connection, so here it is:
I tried to require"pl" but it failed to find the module. (ran from SciTE, worked prevously)
I tried it in the Lua command line and it worked like a charm.
Tried again in SciTE and voila it worked again.
I have no idea what causes any of them.
ps.: using the lfs module and os.execute("cd /d ...path...") did not work
Lua is searching for your required module in the folders of LUA_PATH. In the script you run via F5, put this statement:
print('current path is:')
os.execute('cd')
require 'someModuleThatDoesntExist'
After printing the "working" forlder (Program Files/Notepad++), it tries to find the required module and fails. The traceback shows that Lua looks through many different folders, none of them being the one containing FULL_CURRENT_PATH, so it can't find the module.
You have several choices:
put your scripts in one of the listed paths
set LUA_PATH in your environment to contain the folder name where your scripts are located
change package.path from your script so it knows where to look for other modules. You could do this by either:
including an extra parameter to your F5, namely CURRENT_DIRECTORY, and make your script take its first command line param (CURRENT_DIRECTORY) to add it to package.path
parse arg[0] when your script starts, to get the folder containing script, and extend package.path
For example with #3, first option, you would use
cmd /k lua "$(FULL_CURRENT_PATH)" "$(CURRENT_DIRECTORY)"
in notepad++ and in your Lua module you would use
thisModuleDir = arg[1]
package.path = thisModuleDir .. ";" .. package.path
require 'yourmodule'
Related
recently i have been trying to run a script in lua that through os.execute() will execute a script in C# compiled into an executablethat is in the same directory as my script.
In my first attempt adding the entire directory until the executable worked:
os.execute("C:\\ServerTest\\test\\tex\\testcode.exe")
however I need this script to work on other computers, which means I can't add the entirely path to the file.I tried countless methods to execute the .exe file inside the same directory without using the entire path and none of the methods worked
os.execute("./testcode")
os.execute [[".\testcode.exe"]]
os.execute(".\\testcode.exe")
os.execute "testcode.exe"
I even tried to create an environment variable and run the entire directory from it xD
os.execute("set wTest=%cd%")
os.execute("%wTest%\\testcode.exe")
but nothing worked. I also tried to use io.popen() but didn't get results either (because the executable will close a computer process, it does not give any output :V)
does anyone know how I can do this?????
Title says it all really.
I have a setup that requires the use of environment variables when setting these kind of assignments. Most seem to work, but when it comes to QIP_FILE assignments in a tcl script, Quartus errors.
Using an explicit path in the .qsf project file works. Is there any way of using environment variables in a .qsf file, or am I doing something wrong in my .tcl script?
The line I am using is:
set_global_assignment -name QIP_FILE $::env(MY_VAR_PATH)/my/path/my.qip
Any help on this would be great,
Thanks in advance
EDIT: The error I get when attempting to use the .tcl script is:
------------------------------------------------
ERROR: Can't open project: flash_leds
while executing
"project_open $project_name -cmp $ap_name"
(file "/opt/altera/15.0/quartus/common/tcl/internal/qsh_smart.tcl" line 60)
------------------------------------------------
So I managed to find a solution!
I was calling this .tcl script as source in the .qsf file (as it included other scripts which also needed sourcing. Turns out, for some reason, that the
set_global_assignment -name QIP_FILE ...
command doesn't work when the .tcl file is called using source (but other set_global_assignment calls do work... I don't really know whats happening there!).
To solve this I had to create another .tcl file and move all of the set_global_assignment calls to there, leaving the other file with only the other sourced scripts. This new file then has to be included in the .qsf file in the following way:
set_global_assignment -name SOURCE_TCL_SCRIPT_FILE <filename>
This seemed to solve my issue, and the QIP file was correctly found using the environment variable path.
I am trying to figure out how to use relative paths for Powershell scripts. I have dot sourced with absolute paths, but the scripts that I am writing may end up in a different base directory so I need to make sure the path is relative so it can be picked up. How can I do that?
So far I have tried:
. .\scripts\variables.ps1
That always throws this exception:
The term '.\scripts\variables.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program...
That lets me know it can't find my script? So, what am I doing wrong?
You can use : . $PSScriptRoot\scripts\variables.ps1
Here $PSScriptRoot is the path of directory of the running script.
This is not what the OP asked for but may be useful for others who are searching:
If you need to traverse up, you can use . $PSScriptRoot\..\scripts\variables.ps1
This works for structures such as:
root
scripts/shared directory
directory your script is executing in
If you know that your script directory structure is going to remain the same, you could use $PWD; eg:
. "$PWD\scripts\variables.ps1"
The above assumes that your script (the calling script) is in the same directory that contains the scripts directory.
Also, the assumption made here is that you're checking out/downloading all your scripts in the same structure, but as you put it, they may end up being in a different base directory.
I am using Lua for Windows.
I am trying a sample script from the wxLua website; however, when I run the script, it fails on the first line, which is require 'wx' with:
lua: cannot open wx: No such file or directory
However, when executing require 'wx' in the REPL/interpreter, it works OK.
I have done another script to output print(package.cpath) and print(package.path), and they seem the same to me as in the REPL.
Why, when running the script, is it not able to find 'wx'?
In this instance, I am running both the script and the shell/REPL from the same folder.
The value of package.cpath (produced by test script and Lua shell):
.\?.dll;.\?51.dll;C:\Program Files (x86)\Lua\5.1\?.dll;C:\Program Files (x86)\Lu a\5.1\?51.dll;C:\Program Files (x86)\Lua\5.1\clibs\?.dll;C:\Program Files (x86)\ Lua\5.1\clibs\?51.dll;C:\Program Files (x86)\Lua\5.1\loadall.dll;C:\Program File s (x86)\Lua\5.1\clibs\loadall.dll
and package.path (again, the same from the script and Lua shell):
;.\?.lua;C:\Program Files (x86)\Lua\5.1\lua\?.lua;C:\Program Files (x86)\Lua\5.1\lua\?\init.lua;C:\Program Files (x86)\Lua\5.1\?.lua;C:\Program Files (x86)\Lua\5.1\?\init.lua;C:\Program Files (x86)\Lua\5.1\lua\?.luac
There is a wx.dll in C:\Program Files (x86)\Lua\5.1\clibs which is referenced by the cpath value above.
OK, this was my own stupidity: I named the file wx.lua, so obviously require was trying to pick up the script itself.
By simply renaming the file, it works fine.
I downloaded LuaEdit to use as an IDE and debug tool however I'm having trouble using it for even the simplest things. I've created a solution with 2 files in it, all of which are stored in the same folder. My files are as follows:
--startup.lua
require("foo")
test("Testing", "testing", "one, two, three")
--foo.lua
foo = {}
print("In foo.lua")
function test(a,b,c) print(a,b,c) end
This works fine when in my C++ compiler when accessed through some embed code, however when I attempt to use the same code in LuaEdit, it crashes on line 3 require("foo") with an error stating:
module 'foo' not found:
no field package.preload['foo']
no file 'C:\Program Files (x86)\LuaEdit 2010\lua\foo.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\lua\foo\init.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\foo.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\foo\init.lua'
no file '.\foo.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\foo.dll'
no file 'C:\Program Files (x86)\LuaEdit 2010\loadall.dll'
no file '.\battle.dll'
I have also tried creating these files prior to adding them to a solution and still get the same error. Is there some setting I'm missing? It would be great to have an IDE/debugger but it's useless to me if it can't run linked functions.
The issue is probably that your Lua files are not on the path in package.path (for C files this is package.cpath).
My guess is that the LuaEdit program is not launched in the directory you have your files in, and hence does not have a match for eg .\foo.lua.
You have 3 simple solutions to this (from dumb to smarter):
Find out what path LuaEdit considers as ./ and put your files there.
Open up a terminal in the right directory (the one containing your files), and run LuaEdit from there.
Add the path the files are on to package.path and package.cpath before doing any require's
You may need to put:
lua
package.path = package.path..";c:/path/to/my/files/?.lua"
at the beginning of your files before any require (as jpjacobs indicated). I couldn't find any way to provide this from LuaEdit itself. It appears it runs the script using its full path, but keeps its current dir set to whatever it was when the IDE was started. If you run LuaEdit using full path from your application folder, it should work fine even without package.path changes.
While the IDE itself works fine with its own modules/libraries, it doesn't mean it makes them available to the application it runs.
(shameless plug) If you're still not happy with LuaEdit, I'd offer ZeroBrane Studio Lua IDE as an alternative, It's based on the same wxLua framework, but provides a bit more functionality and doesn't have this particular issue you're facing. It also supports remote debugging, so you should be able to debug your Lua scripts directly from your application.