why new RegExp(".. ")({}) equals "ct " - actionscript

My code:
trace(new RegExp(".. ")({}))
and console print "ct "
it's so strange, is there anybody know why call an RegExp instance with a {} will return string "ct "?

{} seems to be an objeCT:
trace(new RegExp('...............')({})); // [object Object]

Related

Getting groovy.lang.MissingPropertyException: No such property: datepart for class: groovy.lang.Binding

I am newbie to jenkins pipeline scripting and i am just trying to concatenate date to string getting below No Such Property exception. Dont know where am doing wrong. Could some one please help me to resolve this
def generateRandomText(){
def temp = ""
try{
Date date = new Date()
String datePart = date.format("ddHHmmssSSS")
temp = "abcde" + datepart
echo "printing ... $temp"
return temp
}
catch(theError){
echo "Error getting while generating random text: {$theError}"
}
return temp
}
MissingPropertyException means the variable wasn't declared.
There were some errors in your code:
You used echo, which doesn't exist in Groovy. Use one of the print functions instead. On the code below I used println
The datePart variable was mispelled
Here's your code fixed:
def generateRandomText(){
def temp = ""
try{
Date date = new Date()
String datePart = date.format("ddHHmmssSSS")
temp = "abcde" + datePart
println "printing ... $temp"
return temp
}
catch(theError){
println "Error getting while generating random text: {$theError}"
}
return temp
}
generateRandomText()
Output on groovyConsole:
printing ... abcde21195603124
Result: abcde21195603124
See Groovy's documentation.

Lua: "attempt to concatenate global" Error in MPV

I am trying to write a little script to output filetags in mpv. My script looks like this:
require 'os'
require 'string'
function displayTrack()
currentTrack = mp.get_property("metadata/by-key/Title")
currentArtist = mp.get_property("metadata/by-key/Artist")
currentAlbum = mp.get_property("metadata/by-key/Album")
print(currentArtist)
print(currentAlbum)
print(currentTrack)
if currentTrack == nil then
os.execute("terminal-notifier -title '" .. currentArtist .. "' -message 'Unknown Title'")
else
os.execute("terminal-notifier -title '" .. currentArtist .. "' -message '" .. currentAlbum .. " - " .. currentTrack .. "'")
end
end
mp.observe_property("eof-reached", "bool", displayTrack)
Catching the tags and printing them works with every tested title. But if i want to uncomment the 5 lines starting with "if currentTrack == nil ..." so it also dislpays a native notification i get the LUA error:
/Users/marcel/.config/mpv/scripts/notification.lua:15: attempt to concatenate global 'currentArtist' (a nil value)
Can somebody tell me why i can print the string but not forward it to the os.execute?
It is not os.execute, it is concatenation - .. - that can't work with nil. And yes, you can print standalone nil just fine. In your case not only currentTrack is nil, but currentArtist too, so you can't build a string with it. Consider if you even need those entries where you don't have value for currentArtist and either skip them, provide alternative if branch to do something else or provide some default in concatenation. Usual idiom is (currentArtist or '') - here your default will be empty string.
if currentTrack == nil then
os.execute("terminal-notifier -title '" .. currentArtist .. "' -message 'Unknown Title'")
If this branch gets executed, currentTrack is nil, thus the concatenation fails as stated by the error message.
Just get rid of the concatenation all together:
if currentTrack == nil then
os.execute("terminal-notifier -title -message 'Unknown Title'")

Table printing nil on Lua

I have this code written in Lua, it's just an example code, because the actual one I'm using is bigger than this, but this is the part I'm having problems.
Does anyone know why when I try to print what's inside the table t I get nil as result?
t = {
{name="John",sex="M",age=19},
{name="Susan",sex="F",age=20}
}
for _ in ipairs(t) do
print("NAME: " .. t.name)
print("SEX: " .. t.sex)
print("AGE: " .. t.age)
print("\n")
end
I mean, this is the result I get when I run the code:
attempt to concatenate field 'name' (a nil value)
Iterating over t doesn't change t. You need to specify where to put the values you are iterating over, and use those variables.
local t = {
{name="John",sex="M",age=19},
{name="Susan",sex="F",age=20}
}
for index, value in ipairs(t) do
print("NAME: " .. value.name)
print("SEX: " .. value.sex)
print("AGE: " .. value.age)
print("\n")
end

Attempt to call field 'defaultName' (a string value) error

I'm getting a strange Attempt to call field 'defaultName' (a string value) when i add " some more text " to my code below:
--
alert = native.showAlert( "saved!", "Your score is saved to " ..defaultName " some more text " ..allScore_txt , { "Done" }, onComplete )
--
any idea how to fix this ?
You missed a .. after defaultName and so Lua thinks you mean a function call, hence the error message. Lua allows function calls in the form identifier"string" as shorthand for identifier("string")`.

Is is possible to have strings evaluate as variables in groovy?

I am playing with grails and groovy. I wondered if its possible to do something like this.
def inbuiltReqAttributes = ['actionName','actionUri','controllerName','controllerUri']
inbuiltReqAttributes.each() { print " ${it} = ? " };
what would i put in the ? to get groovy to evaluate the current iterator value as a variable e.g. to do it the long way
print " actionName = $actionName "
Thanks
I believe off the top of my head, this should work:
print " ${it} = ${this[ it ]}"
Or:
print " ${it} = ${getProperty( it )}"
But i'm not at a computer to 100% verify this atm...
Try this:
inbuiltReqAttributes.each() {
evaluate("value = ${it}")
print "$it = $value"
}

Resources