comma in coffee script / framerjs - coffeescript

When do we use a comma after function declaration in coffee script?
For eg, in the code below why is there a comma after Events.DragStart?
layerA.on Events.DragStart, ->
print layerA.draggable.layerCursorOffset

The comma is not after the function declaration but after the first argument. Coffeescript is just a syntax for Javascript, so you can always compile it to Javascript to see what it does.
E.g. pasting your code snippet into the js2.coffee web service yields this Javascript:
layerA.on(Events.DragStart, function() {
return print(layerA.draggable.layerCursorOffset);
});

Related

Electron second instance's command line arguments are corrupted?

I am following the example for requestSingleInstanceLock() in the Electron's documentation. For some reason the second instance's command line arguments seem corrupted if the arguments have quoted values with spaces inside. The initial process.argv looks just fine, however the argv parameter in the second-instance event comes split at the spaces adding additional argument values, all values are transformed to lower case, and somewhat presorted.
Is there a way to disable this processing, and eventually pass/get the command line of the second instance as is?
NOTE: I have used app.makeSingleInstance() in previous Electron versions, however this API has been removed.
Here's an excerpt from the test app I use:
console.log(process.argv);
if (!app.requestSingleInstanceLock()) {
app.exit();
}
app.on('second-instance', (event, argv, workingDirectory) => {
console.log('second-instance', argv);
});
Here's the result:
C:\electron-app-win32-x64>electron-app.exe "/Arg1 Value1" "/Arg2 Value2"
C:\electron-app-win32-x64>
[
'C:\\electron-app-win32-x64\\electron-app.exe',
'/Arg1 Value1',
'/Arg2 Value2'
]
second-instance [ <--- from the same command in another console
'electron-app.exe',
'/arg1',
'/arg2',
'--allow-file-access-from-files',
'--original-process-start-time=13232862957593703',
'value1',
'value2'
]
It's
Chromium's command-line parsing logic. Chromium treats "switches"
(things like --foo or --foo=bar) and "arguments" (things that don't
begin with --) separately
You can find links to Chromium source and some hacks to get around this logic in this github issue.
https://github.com/electron/electron/issues/20322

Passing file path with spaces and forward slashes as argument to TCL command

I have a TCL script that is run by Libero using a file path provided as an argument to open a project. The file path is C:\Users\me\Documents\FPGA projects\file.prjx
I am running the script according to Libero TCL Reference Guide (pages 51 - 52) to run the script on the command line. On page 47, the doc outlines how to work with filenames with spaces; using braces or in the case where it is used as an argument use double quotes.
The command I am trying to execute is:
Path\to\libero SCRIPT:export.tcl SCRIPT_ARGS:""C:\Users\me\Documents\FPGA projects\file.prjx""
The outer set of double quotes is to follow the syntax outlined in page 52 of the document for providing arguments and the inner set of double quotes is to handle the white space in the first argument. I had expected $argv 0 to be C:\Users\me\Documents\FPGA projects\file.prjx, but instead $argv 0 is actually C:\Users\me\Documents\FPGA.
I added a print statement to the script to print $argv:
puts $argv
This gives a result of C:\Users\me\Documents\FPGA so the rest of the file path is not being interpreted as even being a second argument.
My assumption is that the conventions outlined in the document are just standard TCL conventions for providing a file path containing forward slashes and spaces as an argument. I have not been able to find an example of passing a similarly formatted argument in TCL. Any ideas?
I'm not sure it's the same issue but, having MagicSplat tclsh.exe and wish.exe linked to *.tcl and *.tk files in Windows (7 to 11), calling scripts this way:
processDIR.tcl "c:\My directory\subdir"
evals arguments only till first space, becoming "c:\My" BUT calling scripts like this:
tclsh.exe processDIR.tcl "c:\My directory\subdir"
trespasses complete argument.
Could you give it a try?

CoffeeScript: calculate parse tree (like coffee -n) in a program

Is there a way to compute the CoffeeScript parse tree of a program (provided as a string) inside CoffeeScript without calling an external program?
For example, let's say I have a string 'square=(n)->n*n' inside a CoffeeScript program. I want to get the same output as storing this string in a file square.coffee and calling on the command line coffee -n square.coffee --- but without creating another process:
Block
Assign
Value "square"
Code
Param "n"
Block
Op *
Value "n"
Value "n"
Please, provide with your solution a link to documentation how to interpret the resulting data structure.
Just look in the source: the -n flag invokes (require 'coffee-script).nodes. The result is a syntax tree which corresponds to grammar.coffee and would be interpreted with nodes.coffee.
So this:
(require 'coffee-script').nodes 'square = (n)->n*n'
Will give you a syntax tree. Before you print it, you could use its toString method to get the same output as the coffee CLI.
For the filesystem operations, just use node's readFile or readFileSync from the fs library:
{readFileSync} = require 'fs'
{nodes} = require 'coffee-script'
nodes readFileSync('squares.coffee').toString()

mcc function can't return value,why?

I use matlab mcc to create a standalone application exe file, then I use php to call the exe file. but I can't get the function return value,it's always empty!! here is my test example in m file
function result=mysum(in)
if nargin<1
in=[1,2,3];
else
in=str2num(in);
end
result=sum(in);
end
then I use the command mcc -m mysum.m to create exe file(I have already configured the matlab compiler).
here is the php file
<html>
<head>
<title>test</title>
</head>
<body>
<?php
exec('F:\myevm\apache\htdocs\shs.exe [2,2,3,3,3] [4,4,4,4,4] 356 1567 1678',$ars);
echo '<br>';
echo $ars[0];
?>
</body>
</script>
</html>
however ,the $ars[0] is always empty!!
I tried to find answer by myself or through the Internet,but failed . give me a help, thanks.
Note two things:
You have your function set up to accept a single input argument.
When you run an application from the Windows command line, arguments are passed in as strings.
So if you type mysum 1 (either in MATLAB on the uncompiled program, and I would guess also if you do this from the Windows command line on the compiled program, although I haven't tested this) it will work, giving the answer 1, and if you type mysum [1,2] it will work, giving the answer 3. Note that mysum [1,2] is different from mysum([1,2]), as it is being passed the string '[1,2]', not the array of doubles [1,2].
But if you type mysum 1 2 it will fail, as you are now passing two string input arguments in, and your function is set up to only accept one.
Rewrite your function so that it accepts a variable number of input arguments (take a look at varargin to achieve that), applies str2num in turn to each of the inputs (which will be varargin{1} to varargin{n} if you've used varargin), and then sums them individually.

Why does powershell automatically append my strings together and pass it as the first argument?

I've got the following code:
function printVars($var1, $var2)
{
Write-Host "var1: $var1"
Write-Host "var2: $var2"
}
printVars ('asdf', 'qwer')
It produces this result:
var1: asdf qwer
var2:
I am expecting this:
var1: asdf
var2: qwer
Why is it doing that and how do I get it to do what I want?
Because ('asdf','qwer') gets treated as an array, so $var1 gets the array and $var2 is empty.
Do printVars 'asdf' 'qwer'
Even if you don't have the parantheses and have just the comma, it is an array.
Try this:
$b ="one","two"
$b.GetType()
The correct answer has already been provided but for those looking for further information I tore this off my PowerShell quick reference chart. This assumes function f's signature is f($a, $b, $c):
Thus, one can call a function with space-separated positional parameters or order-independent named parameters. The other pitfalls reveal that you need to be cognizant of commas, parentheses, and white space.
For further reading see my recent article Down the Rabbit Hole- A Study in PowerShell Pipelines, Functions, and Parameters just published on Simple-Talk.com. The article contains a link to the quick reference/wall chart as well.
I see now. I'm calling the function wrong.
It should be this:
printVars 'asdf' 'qwer'
The quotes could be removed too.
Although it looks like the brace-languages like Perl and C calling a function is like calling another command using most shells.
When I put the comma in there it appends the strings together into one string and passes that as the first argument.