I use this loop at end of my script to detect if I have still modules open :
for module_in_database in database do
{
logResult = logResult "INFO: open modules at the end the script are " fullName(module_in_database) "\n"
}
Then at the end of my (quite complex script), I still have those module open :
INFO: open modules at the end the script are /spec_fpga/spec_fpga
INFO: open modules at the end the script are /spec produit/spec_produit
INFO: open modules at the end the script are /spec produit/spec_produit
INFO: open modules at the end the script are /spec_fpga/_conf/OBJ_satisfies_OBJ
INFO: open modules at the end the script are /spec_fpga/_conf/OBJ_satisfies_OBJ
What could I do to close those and even better to understand why there are still open (identify the name of variable that are linked to them ?)
Is it normal to have a link module open ? I don't open such link module. Are they open automatically with the downstream module ?
I don't even know if it is a module that is open or a baseline of a module.
I am unsure why spec_produit and OBJ_satisfies_OBJ appear twice, one of spec_produit (formal module?) might be separate baselines, but for link modules like OBJ_satisfies_OBj, it is rare to have baselines.
You might get to know when your modules are opened by starting "Tools→Manage open modules" and regarding the list while your script runs. Perhaps you want to use a DXL Debugger for this.
Generally, link modules are opened automatically when a formal module that contains out links is opened, but usually they are closed again automatically when the formal module closes. Formal modules can be opened when they contain in links and an out link to this module is opened. You might have one module with a (default) view that follows all its out links. Or there might be a trigger or DXL attribute in a module that does something similar.
You might want to check isBaseline moduleVersion module_in_database and versionString moduleVersion module_in_database to get more information.
To close them, just use close module_in_database.
on a side note: in DXL it is never a good idea to close something that you currently loop over, so you want to use a temporary skip list like this:
Skip closeMe = create
for module_in_database in database do {
logResult = logResult "INFO: currently open: " (fullName module_in_database) ((isBaseline (moduleVersion module_in_database)) ? " Baseline " (versionString moduleVersion module_in_database) : " (current version)") "\n"
put (closeMe, module_in_database, module_in_database)
}
Module m
for m in closeMe do {
if open (module m) then {
logResult = logResult "INFO: closing " fullName m "\n"
close m
} }
delete closeMe
Related
After implementing a type checker in Rascal using TypePal, how do I hook it up to the Eclipse IDE? Any resources or repositories to the solution to this problem would be appreciated, Thanks.
in Eclipse search path of the Rascal Navigator view in your project you will find the rascal_eclipse library which contains a good example: demo::lang::Pico::Plugin
in this module you see how to register a language with Eclipse:
registerLanguage("Pico Language", "pico", parsePico); where parsePico is a function reference. Pass your own parameters here. The registerLanguage function comes from util::IDE.
now you can open files with the "IMP editor" in Eclipse and they will use your parser and show syntax highlighting.
next up is registering other effects with the IDE. The library function to call is registerAnnotator. You pass it a function that takes a parse tree for your language and annotates it with error messages:
the messages may be distributed over the tree, using #message or
using a list of #messages at the top of the tree
the error messages will be added as annotations in the editor and registered with the Problem View automatically.
So you have to wire the output of TypePal into the annotator function yourself. Which should be a one-liner.
Alternatively, running type-checks can also be useful after a "save" action. In this case you can register another type of contribition (also in the Pico demo), called builder: builder(set[Message] ((&T<:Tree) tree) messages), and register that with the registerContributions function.
The Message ADT is the same for the annotator and the builder. Both have the effect of adding editor annotations and problems in the view.
Here is some example code taken from an older open-source DSL project called "Bird", https://github.com/SWAT-engineering/bird:
Tree checkBird(Tree input){
model = birdTModelFromTree(input, pathConf = config(input#\loc)); // your function that collects & solves
types = getFacts(model);
return input[#messages={*getMessages(model)}]
[#hyperlinks=getUseDef(model)]
[#docs=(l:"<prettyPrintAType(types[l])>" | l <- types)]
;
}
birdTModelFromTree calls collectAndSolve from TypePal and returns the TModel
getMessage comes from TypePal's Utilities and extracts a list[Message] from the TModel that can be directly communicated to Eclipse via the #messages annotation.
The entire checkBird function is registered as an annotator using the util::IDE function registerAnnotator.
This code hasn't been used for a while, so if you run into trouble, please contact again?
I'm working on a personal project and I'm trying to get Lua to work on my embedded device.
I have my own simple file system that works with the the flash drive, and now I'm trying to use modules for the lua scripts that I run on the device.
I have edited linit.c, to make it also load the modules that are existing in the flash drive, and it works for a few modules, but for most of them it just gives me a syntax error when it parses the contents of the module. I have a lua interpreter running on my Windows machine and the code I'm writing is syntactically correct and works, and the Lua API that I use is of the same version 5.4 on the device.
These are the arguments I pass to
luaL_loadbufferx(L, luaCFunction, sizeOfModule, moduleName, "t")
where, L is the lua state, luaCFunction is the lua module wrapped in a C-style return statement, sizeOfModule, moduleName and t is selfexplanatory.
Right now luaL_loadbufferx is called in a loop for every module in my flash-drive, I have overwritten the openf function from the Lua API for these external modules.
This below is one of the examples of a module that gives me
"Syntax Error: PANIC, unprotected error in call to Lua API
[string "module"]:3: '(' expected near 'writeobj'"
File: module.lua
Contents:
function writeobj()
print('Hello World')
end
File: run.lua
Contents:
require ('module')
writeobj()
Does anyone know why this happens or did I not provide sufficient information? Please let me know.
The problem was that I thought the modules passed to the buffer had to be of the LuaToC form, i.e. "return { ...luamodule...}", but changing it to pass the module only to loadbuffer was sufficient enough because it covers the case of it not being in a C style return format.
I'd like to write a very simple plugin for VLC that makes web requests when a media is played, paused, or stopped. It is a very similar to a scrobbling plugin .
I saw that VLC supports plugin and extensions (which are very simple Lua scripts) but I haven't been able to find any information on how to do this.
I guess I'd need to write a plugin that registers some callbacks -- am I right? Any idea on how I could accomplish this? It seems to be quite an uphill battle figuring this out. Can I do this using Python?
I'm using VLC 2.2.1 on Windows.
Here's a simple Lua plugin that recognizes play/pause/stop events:
function descriptor()
return {
title = "VLC Dummy Extension",
capabilities = { "playing-listener" }
}
end
function activate()
end
function deactivate()
end
function meta_changed()
end
function playing_changed()
vlc.msg.dbg("[Dummy] Status: " .. vlc.playlist.status())
end
Notes:
VLC will call activate(), deactivate(), meta_changed() at some point in the plugin life cycle. You're not required to include them, but VLC will fill up your debug log with useless "function not found" messages.
If the plugin's capabilities contain playing-listener, VLC will expect the playing_changed() hook and call it when appropriate (even though the code comment says the hook name is "status_changed").
vlc.playlist.status() returns "stopped", "playing", "paused" or "unknown".
Run:
Save the plugin in a .lua file, then drop it in VLC's extensions folder: %APPDATA%\vlc\lua\extensions\ (Windows) or ~/.local/share/vlc/lua/extensions/ (Linux).
Load it by Tools > Plugins and extensions, Reload extensions (restarting VLC is unnecessary).
Activate it (there's an option under View, named after title in the plugin descriptor); activate() will be called.
To view all logs (vlc.msg calls), open Tools > Messages (Ctrl+M), set the level to debug and filter by "lua".
To do something whenever a new item plays:
Add input-listener to the plugin's capabilities.
Add the corresponding hook input_changed().
Use vlc.input.item() to get the current item (name, URI, metadata, etc).
You can post what's playing to an HTTP server. VLC offers vlc.net, which means you have to program for sockets. Fortunately, the extension vlsub, shipped with VLC by default, has utility methods for sending GET requests. We can steal those.
In this example, I'm just sending a threadbare GET:
http://127.0.0.1:5000/?name=MMFR.2015.720p.mp4
If I don't care about redirects or reading responses, get() is a lot simpler than the vlsub's version:
function descriptor()
return {
title = "VLC Dummy Extension",
capabilities = { "input-listener" }
}
end
function activate()
end
function deactivate()
end
function meta_changed()
end
function input_changed()
if vlc.input.is_playing() and vlc.playlist.status() == "playing" then
local item = vlc.input.item()
if item then
vlc.msg.dbg("[Dummy] Now playing: " .. item:name())
get("http://127.0.0.1:5000/?name=" .. item:name())
end
end
end
function get(url)
local u = vlc.net.url_parse(url)
local host, port, path = u["host"], u["port"], u["path"]
local header = {
"GET "..path.." HTTP/1.1",
"Host: "..host,
"",
""
}
local request = table.concat(header, "\r\n")
http_req(host, port, request)
end
function http_req(host, port, request)
local fd = vlc.net.connect_tcp(host, port)
if not fd then return false end
local pollfds = {}
pollfds[fd] = vlc.net.POLLIN
vlc.net.send(fd, request)
vlc.net.poll(pollfds)
local chunk = vlc.net.recv(fd, 2048)
while chunk do
vlc.net.poll(pollfds)
chunk = vlc.net.recv(fd, 1024)
end
vlc.net.close(fd)
end
You have two options: write a lua module (check the MSN notification plugin for sample code) or write a C plugin (similar to the scrobbler you already found).
I'd suggest the lua way, since it's cross-platform compatible and it's a way easier language. Additionally, compiling C plugins for VLC is a real pain unless you use Linux or OS X.
Python is only supported for client apps on top of VLC at the moment, but we don't support its use internal to VLC.
I'm trying to script a lua file to check if a certain file is open. Then I want it to close that file if it is open. I know how to check if the file exist but I need to know how to check if the file is open, meaning the file is running.
Lua, like C, C++, and pretty much every other language, can only close files that it opens itself. You cannot close files open by other people (not with standard Lua calls); this would be incredibly rude.
So you can't test to see if a file is opened by someone else. Nor can you close their file. There may be system API calls you could make to do this, but you would have to give Lua scripts access to those APIs yourself. Lua's standard libraries can't do this.
Sounds like you want to check which if any programs have a given file open.
first thing that comes to mind is parsing the output of lsof on linux.
fd = io.popen("lsof path/to/my/file")
fileopened = (#fd:read("a*") > 0)
Kind of a hacky way to do it, but it works:
processname = "process_name_here.exe"
filedata = io.popen("tasklist /NH /FO CSV /FI \"IMAGENAME eq "..processname.."\"")
output = filedata:read()
filedata:close()
if output ~= "INFO: No tasks are running which match the specified criteria." then
-- Program is running. Close the program
os.execute("taskkill -im "..processname)
else
-- Program is not running
end
Just make sure to replace "process_name_here.exe" with the process name that shows up in task manager
Alternatively you can just use this to close it without checking if it was actually running:
os.execute("taskkill -im process_name_here.exe")
What I need to do is have a C# 2005 GUI app call a .bat and several VBScript files at user's request. This is just a stop-gap solution until the end of the holidays and I can write it all in C#. I can get the VBScript files to execute with no problem but I am unable to execute the .bat file. When I "click" in the C# app to execute the .bat file a DOS window opens up and closes very fast and the test .bat file does not execute - "Windows does not recognize bat as an internal or external command" is the error returned in the DOS box. If I simply doubl-click the .bat file or manually run it from the command prompt it does execute. I also need the .bat file to execute silently unless a user interaction is required - this script copies 11k+ files to folders on a networked machine and occasionally Windows "forgets" if the destination is a file or directory and asks for the user to tell it what it is (this is a whole other issue not for discussion here...needless to say I am annoyed by it).
So far in my C# source I have this :
Process scriptProc = new Process();
if (File.Exists("c:\\scripts\\batchfile1.bat"))
{
scriptProc.StartInfo.FileName = #"cscript";
scriptProc.StartInfo.Arguments = ("cmd.exe", "/C C:\\scripts\\batchfile1.bat"); // Wacky psuedo code //
scriptProc.Start();
scriptProc.WaitForExit(1500000);
scriptProc.Close();
}
if (!File.Exists("c:\\scripts\\batchfile1.bat"))
{
}
I am aware that this code does not work - but it is essentially what I want it to do. What I am looking at is something like this for .bat files. I assume I have to tell the system to use cmd to run the .bat. I am at a loss as to how to do this. I have checked out this site which is for C# 2003. Not much help for me as I am very green with C#.
EDIT: Using Kevin's post I attempted it again. Same solution script from that post but modified for me since I do not need to redirect:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "C:\\scripts\\batchfile1.bat";
proc.StartInfo.RedirectStandardError = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();
Here is what you are looking for:
Service hangs up at WaitForExit after calling batch file
It's about a question as to why a service can't execute a file, but it shows all the code necessary to do so.
For the problem you're having about the batch file asking the user if the destination is a folder or file, if you know the answer in advance, you can do as such:
If destination is a file:
echo f | [batch file path]
If folder:
echo d | [batch file path]
It will essentially just pipe the letter after "echo" to the input of the batch file.