AWS VPNConnection using PowerShell - aws-powershell

I am trying to setup a new vpn connection with the AWS transit gateway using PowerShell. I need some assistance on how to setup tunnel options. AWS has very limited documentation with examples. Here is the link to the documentation: VPNTunnelSpecifications.
Here is my script:
foreach ($v in $vpn) {
$name = $v.vpnname
$peer = $v.peerip
$psk = $v.psk
$type = 'ipsec.1'
$tgwid = 'tgw-07b5dbf2e29'
$agency = $v.Agency
$program = $v.Program
$poc = $v.poc
$ph1dh = #(14, 15, 16, 17, 18, 22, 23, 24)
$ph1ike = #("ikev2")
$ph1enc = #("AES256")
$ph1int = #("SHA2-256")
$ph2dh = #(14, 15, 16, 17, 18, 22, 23, 24)
$ph2enc = #("AES256")
$ph2int = #("SHA2-256")
$TunnelOptions = #( #{key = "dpdtimeoutseconds"; value = 30 }, `
#{key = "IKEVersions"; value = $ph1ike }, `
#{key = "Phase1DHGroupNumbers"; value = $ph1dh }, `
#{key = "Phase1EncryptionAlgorithms"; value = $ph1enc }, `
#{key = "Phase1IntegrityAlgorithms"; value = $ph1int }, `
#{key = "Phase1LifetimeSeconds"; value = 28800 }, `
#{key = "Phase2DHGroupNumbers"; value = $ph2dh }, `
#{key = "Phase2EncryptionAlgorithms"; value = $ph2enc }, `
#{key = "Phase2IntegrityAlgorithms"; value = $ph2int }, `
#{key = "Phase2LifetimeSeconds"; value = 3600 }, `
#{key = "PreSharedKey"; value = $psk }
)
##create customer gateway
$cg = New-EC2CustomerGateway -type $type -PublicIp $peer -DeviceName $name
$cg
$cgid = $cg.CustomerGatewayId
$cgid
$vpngateway = New-EC2VpnConnection -CustomerGatewayId $cgid -TransitGatewayId $tgwid -Options_TunnelOption $TunnelOptions
$vpngateway
$VGWid = $vpngateway.VpnGatewayId
$VGWid
}
If I run the script, I get on the line
$vpngateway = New-EC2VpnConnection -CustomerGatewayId $cgid -TransitGatewayId $tgwid -Options_TunnelOption $TunnelOptions
The following error:
New-EC2VpnConnection : Cannot bind parameter 'Options_TunnelOption'.
Cannot create object of type
"Amazon.EC2.Model.VpnTunnelOptionsSpecification". The key property was
not found for the Amazon.EC2.Model.VpnTunnelOptionsSpecification
object. The available property is: [DPDTimeoutSeconds <System.Int32>]
, [IKEVersions
<System.Collections.Generic.List`1[[Amazon.EC2.Model.IKEVersionsRequestListValue,
AWSSDK.EC2, Version=3.3.0.0, Culture=neutral,
PublicKeyToken=885c28607f98e604]]>] , [Phase1DHGroupNumbers
<System.Collections.Generic.List`1[[Amazon.EC2.Model.Phase1DHGroupNumbersRequestListValue,
AWSSDK.EC2, Version=3.3.0.0, Culture=neutral,
PublicKeyToken=885c28607f98e604]]>] , [Phase1EncryptionAlgorithms
<System.Collections.Generic.List`1[[Amazon.EC2.Model.Phase1EncryptionAlgorithmsRequestListValue,
AWSSDK.EC2, Version=3.3.0.0, Culture=neutral,
PublicKeyToken=885c28607f98e604]]>] , [Phase1IntegrityAlgorithms
<System.Collections.Generic.List`1[[Amazon.EC2.Model.Phase1IntegrityAlgorithmsRequestListValue,
AWSSDK.EC2, Version=3.3.0.0, Culture=neutral,
PublicKeyToken=885c28607f98e604]]>] , [Phase1LifetimeSeconds
<System.Int32>] , [Phase2DHGroupNumbers
<System.Collections.Generic.List`1[[Amazon.EC2.Model.Phase2DHGroupNumbersRequestListValue,
AWSSDK.EC2, Version=3.3.0.0, Culture=neutral,
PublicKeyToken=885c28607f98e604]]>] , [Phase2EncryptionAlgorithms
<System.Collections.Generic.List`1[[Amazon.EC2.Model.Phase2EncryptionAlgorithmsRequestListValue,
AWSSDK.EC2, Version=3.3.0.0, Culture=neutral,
PublicKeyToken=885c28607f98e604]]>] , [Phase2IntegrityAlgorithms
<System.Collections.Generic.List`1[[Amazon.EC2.Model.Phase2IntegrityAlgorithmsRequestListValue,
AWSSDK.EC2, Version=3.3.0.0, Culture=neutral,
PublicKeyToken=885c28607f98e604]]>] , [Phase2LifetimeSeconds
<System.Int32>] , [PreSharedKey <System.String>] ,
[RekeyFuzzPercentage <System.Int32>] , [RekeyMarginTimeSeconds
<System.Int32>] , [ReplayWindowSize <System.Int32>] ,
[TunnelInsideCidr <System.String>] At line:1 char:108
+ ... d $cgid -TransitGatewayId $tgwid -Options_TunnelOption $TunnelOptions
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-EC2VpnConnection], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Amazon.PowerShell.Cmdlets.EC2.NewEC2VpnConnectionCmdlet

I was able to fix the script with following code. I could not get the DH values as a list, however, single value worked.
$dpd = 30
$ph1lt = 28800
$ph2lt = 3600
$ph1ike = new-object Amazon.EC2.Model.IKEVersionsRequestListValue
$ph1ike.Value = #("ikev2")
$ph1dh = new-object Amazon.EC2.Model.Phase1DHGroupNumbersRequestListValue
$ph1dh.Value = 14 ##( 14, 15, 16, 17, 18, 22, 23, 24)
$ph1enc = new-object Amazon.EC2.Model.Phase1EncryptionAlgorithmsRequestListValue
$ph1enc.Value = #("AES256")
$ph1int = new-object Amazon.EC2.Model.Phase1IntegrityAlgorithmsRequestListValue
$ph1int.Value = #("SHA2-256")
$ph2dh = new-object Amazon.EC2.Model.Phase2DHGroupNumbersRequestListValue
$ph2dh.Value = 14 ##(14, 15, 16, 17, 18, 22, 23, 24)
$ph2enc = new-object Amazon.EC2.Model.Phase2EncryptionAlgorithmsRequestListValue
$ph2enc.Value = #("AES256")
$ph2int = new-object Amazon.EC2.Model.Phase2IntegrityAlgorithmsRequestListValue
$ph2int.Value = #("SHA2-256")
$TunnelOptions = New-Object Amazon.EC2.Model.VpnTunnelOptionsSpecification
$TunnelOptions.DPDTimeoutSeconds = $dpd
$TunnelOptions.IKEVersions = $ph1ike
$TunnelOptions.PreSharedKey = $psk
$TunnelOptions.Phase1DHGroupNumbers = $ph1dh
$TunnelOptions.Phase1EncryptionAlgorithms = $ph1enc
$TunnelOptions.Phase1IntegrityAlgorithms = $ph1int
$TunnelOptions.Phase1LifetimeSeconds = $ph1lt
$TunnelOptions.Phase2DHGroupNumbers = $ph2dh
$TunnelOptions.Phase2EncryptionAlgorithms = $ph2enc
$TunnelOptions.Phase2IntegrityAlgorithms = $ph2int
$TunnelOptions.Phase2LifetimeSeconds = $ph2lt

Related

Iterate through multiple lists using locals in Terraform code

I have the following list of Resource Group names and Virtual Machine Names, I will like to create a map using locals so I can iterate through it using each.key and each.value in my code.
VARIABLES:
variable "vm_names" {
default = [
"vm1",
"vm2",
"vm3",
"vm4",
"vm5"
]
variable "rg_names" {
default = [
"rg1",
"rg2",
"rg3",
"rg4",
"rg5"
]
LOCALS:
locals {
vm = var.vm_names
rg = var.rg_names
vmrg=[for k,v in zipmap(local.vm, local.rg):{
vm = k
rg = v
}]
}
RESULT:
+ vmrg = [
+ {
+ rg = "rg1"
+ vm = "vm1"
},
+ {
+ rg = "rg2"
+ vm = "vm2"
},
+ {
+ rg = "rg3"
+ vm = "vm3"
},
+ {
+ rg = "rg4"
+ vm = "vm4"
},
+ {
+ rg = "rg5"
+ vm = "vm5"
},
]
DESIRED RESULT:
vmrg = {
vm1 = "rg1"
vm2 = "rg2"
vm3 = "rg3"
vm4 = "rg4"
vm5 = "rg5"
}
Actually, it is much simpler and you were already close to figuring it out. The only thing you need is the zipmap built-in function:
vmrg = zipmap(local.vm, local.rg)
will yield:
> local.vmrg
{
"vm1" = "rg1"
"vm2" = "rg2"
"vm3" = "rg3"
"vm4" = "rg4"
"vm5" = "rg5"
}

why is this error coming out in Corona sdk?

12:39:31.002 ERROR: Runtime error
12:39:31.002 C:\Users\User\Documents\Corona Projects\MATH FOR CHILDREN\level1.lua:207: attempt to call method 'setFillColor' (a nil value)
12:39:31.002 stack traceback:
12:39:31.002 C:\Users\User\Documents\Corona Projects\MATH FOR CHILDREN\level1.lua:207: in function 'listener'
12:39:31.002 D:\a\corona\corona\subrepos\timer\timer.lua:331: in function 'method'
12:39:31.002 D:\a\corona\corona\platform\resources\init.lua:220: in function <D:\a\corona\corona\platform\resources\init.lua:189>
This is my code
local composer = require("composer");
local scene = composer.newScene();
local widget = require( "widget" )
local json = require("json")
display.setDefault("background", 55/255, 50/255, 47/255);
------------------------------------------------------------------------------------
local tapText
local casi = display.newText( "a", display.contentCenterX, 700, "Myfontilqar-Regular.ttf", 42 )
casi:setFillColor(0/255,196/255,253/255,1)
local yes = display.newText( "c", display.contentCenterX, 700, "Myfontilqar-Regular.ttf", 46 )
yes:setFillColor(6/255,204/255,36/255,1)
local no = display.newText( "b", display.contentCenterX, 700, "Myfontilqar-Regular.ttf", 44 )
no:setFillColor(219/255,26/255,15/255,1)
local bal
local balpl
local vrem
local scetcikBal = 0
local scetcikBalpl = 0
local scetcikLevel = 0
local settings = {
yesJ = 0, noJ = 0, procent = 0, procent2 = 0
}
local function saveSettings()
local path = system.pathForFile( "itoq.json", system.DocumentsDirectory )
local file = io.open( path, "w" )
if (file) then
local contents = json.encode(settings)
file:write( contents )
io.close( file )
return true
end
end
local secondL = 20
local function obnovVr( event )
secondL = secondL - 1
vrem.text = secondL
if secondL == 0 then
settings.yesJ = scetcikBal
settings.noJ = scetcikBalpl
settings.procent = (scetcikBal * 10)
saveSettings()
composer.gotoScene( "Level1Score")
end
end
local kor = {
{display.contentCenterX - 66, display.contentCenterY + 120},
{display.contentCenterX + 70, display.contentCenterY + 120},
{display.contentCenterX - 66, display.contentCenterY + 200},
{display.contentCenterX + 70, display.contentCenterY + 200}
}
local tb = {
{"1 + 2 = ?",{"3","2","4","1"},"1 + 2 = 3"},
{"2 + 3 = ?",{"5","4","6","3"},"2 + 3 = 5"},
{"3 + 1 = ?",{"4","3","5","1"},"3 + 1 = 4"},
{"2 + 2 = ?",{"4","2","3","1"},"2 + 2 = 4"},
{"3 + 2 = ?",{"5","3","4","1"},"3 + 2 = 5"},
{"1 + 1 = ?",{"2","5","4","1"},"1 + 1 = 2"},
{"1 + 3 = ?",{"4","1","5","2"},"1 + 3 = 4"},
{"2 + 1 = ?",{"3","2","1","4"},"2 + 1 = 3"},
{"4 + 1 = ?",{"5","3","4","1"},"4 + 1 = 5"},
{"1 + 4 = ?",{"5","4","2","3"},"1 + 4 = 5"}
}
local j
for i = #tb, 2, -1 do
j = math.random( i )
tb[i], tb[j] = tb[j], tb[i]
end
local j1
for i = #kor, 2, -1 do
j1 = math.random( i )
kor[i], kor[j1] = kor[j1], kor[i]
end
local button1
local button2
local button3
local button4
nVoprosa = 1
local t = 2
local function stop1()
button1:setEnabled( false )
button2:setEnabled( false )
button3:setEnabled( false )
button4:setEnabled( false )
tapText.text = tb[nVoprosa][3]
tapText:setFillColor(6/255, 204/255, 36/255, 1)
end
local function stop2()
button1:setEnabled( false )
button2:setEnabled( false )
button3:setEnabled( false )
button4:setEnabled( false )
tapText.text = tb[nVoprosa][3]
tapText:setFillColor(219/255, 26/255, 15/255, 1)
tapText.size = 50
end
local function vb()
t = t - 1
if t == 0 then
scetcikBal = scetcikBal + 1
bal.text = scetcikBal
scetcikLevel = scetcikLevel + 1
if ( scetcikLevel == 10) then
settings.yesJ = scetcikBal
settings.noJ = scetcikBalpl
settings.procent = (scetcikBal * 10)
saveSettings()
composer.gotoScene( "Level1Score")
else
button1:setEnabled( true )
button2:setEnabled( true )
button3:setEnabled( true )
button4:setEnabled( true )
tapText:setFillColor(255/255, 255/255, 255/255, 1 )
nVoprosa = nVoprosa + 1
tapText.text = tb[nVoprosa][1]
button1:setLabel( tb[nVoprosa][2][1] )
button2:setLabel( tb[nVoprosa][2][2] )
button3:setLabel( tb[nVoprosa][2][3] )
button4:setLabel( tb[nVoprosa][2][4] )
local j1
for i = #kor, 2, -1 do
j1 = math.random( i )
kor[i], kor[j1] = kor[j1], kor[i]
end
button1.x = kor[1][1]
button1.y = kor[1][2]
button2.x = kor[2][1]
button2.y = kor[2][2]
button3.x = kor[3][1]
button3.y = kor[3][2]
button4.x = kor[4][1]
button4.y = kor[4][2]
end
t = 2
end
end
local function vbn()
t = t - 1
if t == 0 then
scetcikBalpl = scetcikBalpl + 1
balpl.text = scetcikBalpl
scetcikLevel = scetcikLevel + 1
if ( scetcikLevel == 10) then
settings.yesJ = scetcikBal
settings.noJ = scetcikBalpl
settings.procent = (scetcikBal * 10)
saveSettings()
composer.gotoScene( "Level1Score")
else
button1:setEnabled( true )
button2:setEnabled( true )
button3:setEnabled( true )
button4:setEnabled( true )
tapText:setFillColor(255/255, 255/255, 255/255, 1)
tapText.size = 40
nVoprosa = nVoprosa + 1
tapText.text = tb[nVoprosa][1]
button1:setLabel( tb[nVoprosa][2][1] )
button2:setLabel( tb[nVoprosa][2][2] )
button3:setLabel( tb[nVoprosa][2][3] )
button4:setLabel( tb[nVoprosa][2][4] )
local j1
for i = #kor, 2, -1 do
j1 = math.random( i )
kor[i], kor[j1] = kor[j1], kor[i]
end
button1.x = kor[1][1]
button1.y = kor[1][2]
button2.x = kor[2][1]
button2.y = kor[2][2]
button3.x = kor[3][1]
button3.y = kor[3][2]
button4.x = kor[4][1]
button4.y = kor[4][2]
end
t = 2
end
end
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
stop1()
timer.performWithDelay( 300, vb, t )
--vb()
end
end
local function handleButtonEventN( event )
if ( "ended" == event.phase ) then
stop2()
timer.performWithDelay( 300, vbn, t )
--vbn()
end
end
---------------------------------------------------------------------------------------
function scene:create( event )
local sceneGroup = self.view
timer.performWithDelay( 1000, obnovVr, secondL )
tapText = display.newText("", display.contentCenterX, display.contentCenterY - 80, "Lato-Regular.ttf", 40 )
tapText.text = tb[1][1]
button1 = widget.newButton(
{
id = "button1",
label = tb[nVoprosa][2][1],
onEvent = handleButtonEvent,
labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
fontSize = 36,
font = "Lato-Regular.ttf",
emboss = false,
shape = "roundedRect",
width = 120,
height = 60,
cornerRadius = 0,
fillColor = { default={55/255,50/255,47/255,1}, over={31/255,76/255,115/255,1} },
strokeColor = { default={0/255,196/255,253/255,1}, over={0.8,0.8,1,1} },
strokeWidth = 3
}
)
button2 = widget.newButton(
{
id = "button2",
label = tb[nVoprosa][2][2],
onEvent = handleButtonEventN,
labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
fontSize = 36,
font = "Lato-Regular.ttf",
emboss = false,
shape = "roundedRect",
width = 120,
height = 60,
cornerRadius = 0,
fillColor = { default={55/255,50/255,47/255,1}, over={31/255,76/255,115/255,1} },
strokeColor = { default={0/255,196/255,253/255,1}, over={0.8,0.8,1,1} },
strokeWidth = 3
}
)
button3 = widget.newButton(
{
id = "button3",
label = tb[nVoprosa][2][3],
onEvent = handleButtonEventN,
labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
fontSize = 36,
font = "Lato-Regular.ttf",
emboss = false,
shape = "roundedRect",
width = 120,
height = 60,
cornerRadius = 0,
fillColor = { default={55/255,50/255,47/255,1}, over={31/255,76/255,115/255,1} },
strokeColor = { default={0/255,196/255,253/255,1}, over={0.8,0.8,1,1} },
strokeWidth = 3
}
)
button4 = widget.newButton(
{
id = "button4",
label = tb[nVoprosa][2][4],
onEvent = handleButtonEventN,
labelColor = { default={ 1, 1, 1 }, over={ 0, 0, 0, 0.5 } },
fontSize = 36,
font = "Lato-Regular.ttf",
emboss = false,
shape = "roundedRect",
width = 120,
height = 60,
cornerRadius = 0,
fillColor = { default={55/255,50/255,47/255,1}, over={31/255,76/255,115/255,1} },
strokeColor = { default={0/255,196/255,253/255,1}, over={0.8,0.8,1,1} },
strokeWidth = 3
}
)
--
button1.x = kor[1][1]
button1.y = kor[1][2]
button2.x = kor[2][1]
button2.y = kor[2][2]
button3.x = kor[3][1]
button3.y = kor[3][2]
button4.x = kor[4][1]
button4.y = kor[4][2]
casi.x = 240
casi.y = 2
yes.x = 40
yes.y = 2
no.x = 140
no.y = 2
bal = display.newText(scetcikBal, 80, 3, "Lato-Regular.ttf", 30 )
balpl = display.newText(scetcikBalpl, 180, 3, "Lato-Regular.ttf", 30 )
vrem = display.newText("20", 290, 3, "Lato-Regular.ttf", 30 )
sceneGroup:insert(bal)
sceneGroup:insert(balpl)
sceneGroup:insert(yes)
sceneGroup:insert(no)
sceneGroup:insert(vrem)
sceneGroup:insert(casi)
sceneGroup:insert(tapText)
sceneGroup:insert(button1)
sceneGroup:insert(button2)
sceneGroup:insert(button3)
sceneGroup:insert(button4)
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
elseif (phase == "did") then
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
elseif (phase == "did") then
composer.removeScene( "level1" )
end
end
function scene:destroy( event )
local sceneGroup = self.view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
return sceneenter code here
C:\Users\User\Documents\Corona Projects\MATH FOR CHILDREN\level1.lua:207: attempt to call method 'setFillColor' (a nil value)
In line 207 of level1.lua you do this setFillColor() which is not allowed as setFillColor is not a function value but a nil value.
setFillColor is a method of the ShapeObject class. Make sure you're doing using it like this: myShapeObject:setFillColor(myColor)

Tonemap Fuse for Fusion based on Timothy Lottes algorithm (Lua)

I'm trying to build a Fuse (Fusion studio plugin) based on the tone mapper by Timothy Lottes : http://32ipi028l5q82yhj72224m8j.wpengine.netdna-cdn.com/wp-content/uploads/2016/03/GdcVdrLottes.pdf
presented in this algorithm: https://github.com/Opioid/tonemapper/blob/master/tonemapper.py#L14-L42
The Fuse is accepted by Fusion, but crashes when I'm trying to use it. Could anyone give me some feedback please at what I am doing wrong?
Thanks
(Fuses are written in Lua)
--[[
Tone Mapper based on
http://32ipi028l5q82yhj72224m8j.wpengine.netdna-cdn.com/wp-content/uploads/2016/03/GdcVdrLottes.pdf
https://github.com/Opioid/tonemapper/blob/master/tonemapper.py#L14-L42
version 2021 01 05 by Pieter Dumoulin
]]--
FuRegisterClass("ToneMapper", CT_SourceTool, {
REGS_Category = "Fuses",
REGS_Name = "Tone Mapper",
REGS_OpIconString = "TM",
REGS_OpDescription = "Tone Mapper",
REG_OpNoMask = true
})
function Create()
InContrast = self:AddInput("Contrast", "Contrast", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 5,
INP_Default = 1.2,
})
InShoulder = self:AddInput("Shoulder", "Shoulder", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 5,
INP_Default = 0.97,
})
InMidIn = self:AddInput("Middle Grey In", "mid_in", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 1,
INP_Default = 0.4,
})
InMidOut = self:AddInput("Middle Grey Out", "mid_out", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 1,
INP_Default = 0.18,
})
InHdrMax = self:AddInput("HdrMax", "Hdr_Max", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 100,
INP_Default = 64,
})
InImage = self:AddInput("Input", "Input", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
OutImage = self:AddOutput("Output", "Output", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
end
function maxrgbfunc()
if p.R == p.G == p.B then return p.G
elseif p.G == math.max(p.R, p.B) then return p.G
elseif p.B == math.max(p.G, p.R) then return p.B
elseif p.R == math.max(p.G, p.B) then return p.R
else return math.max(p.R, math.max(p.G, p.B))
end
function tonemapfunc()
local peak = math.min(maxRGB, self_hdr_max)
local curve = (peak ^ self_a) / (((peak ^ self_a) ^ self_d) * self_b + self_c)
return curve
end
function Process(req)
local img = InImage:GetValue(req)
local a = InContrast:GetValue(req).Value
local d = InShoulder:GetValue(req).Value
local mid_in = InMidIn:GetValue(req).Value
local mid_out = InMidOut:GetValue(req).Value
local hdr_max = InHdrMax:GetValue(req).Value
local ad = a * d
local midi_pow_a = mid_in ^ a
local midi_pow_ad = mid_in ^ ad
local hdrm_pow_a = hdr_max ^ a
local hdrm_pow_ad = hdr_max ^ ad
local u = hdrm_pow_ad * mid_out - midi_pow_ad * mid_out
local v = midi_pow_ad * mid_out
local self_a = a
local self_d = d
local self_b = -((-midi_pow_a + (mid_out * (hdrm_pow_ad * midi_pow_a - hdrm_pow_a * v)) / u) / v)
local self_c = (hdrm_pow_ad * midi_pow_a - hdrm_pow_a * v) / u
local self_hdr_max = hdr_max
local out = Image({IMG_Like = img})
self:DoMultiProcess(nil, { In = img, Out = out, MaxRGB = maxrgb }, img.Height, function (y)
local p = Pixel()
for x=0,In.Width-1 do
In:GetPixel(x,y, p)
maxRGB = maxrgbfunc(x, y, p)
local peak = tonemapfunc(maxRGB, self_hdr_max, self_a, self_d, self_b, self_c, x, y, p)
local ratioR = p.R / maxRGB
local ratioG = p.G / maxRGB
local ratioB = p.B / maxRGB
p.R = peak * ratioR
p.G = peak * ratioG
p.B = peak * ratioB
Out:SetPixel(x,y, p)
end
end)
end
OutImage:Set(req,out)
end

How to insert rows into TableView in Corona?

I'm trying to render the match results (string.find) in to a Row, with kinda works... but its only displaying the last match. so if I match 'jan' and 'kevin' it will; only list 'kevin'
Is there a way to fix this ?
code:
local MasterData = xml:loadFile( "sample.xml")
local XMLdataTEST = {}
for i=1,#MasterData.child do
XMLdataTEST[i] = MasterData.child[i]
end
inputNumber = 1
check1 = 'jan'
check2 = 'kevin'
for i=1,#XMLdataTEST do
local data1 = XMLdata[i].child[1].value
local data2 = XMLdata[i].child[2].value
local data3 = XMLdata[i].child[3].value
local data4 = XMLdata[i].child[4].value
input1 = string.lower( data1.. "" )
input2 = string.lower(_G['check' .. inputNumber] )
input = input2
if string.find( input1.. "" , input ) then
print(inputNumber.. " match with " ..input)
inputNumber = inputNumber + 1
local function onRowRender( event )
local row = event.row
local number = display.newText( row, "" .. row.index .. " - ", 12, 0, nil, 18 )
number:setReferencePoint( display.CenterLeftReferencePoint )
number.x = 15
number.y = row.height * 0.5
number:setFillColor( 0, 0, 0 )
local name = display.newText(row, input1, 12, 0, nil, 18 )
name:setReferencePoint( display.CenterLeftReferencePoint )
name.x = number.x + number.contentWidth
name.y = row.height * 0.5
name:setFillColor( 0, 0, 0 )
local score = display.newText(row,"testy", 12, 0, nil, 18 )
score:setReferencePoint( display.CenterLeftReferencePoint )
score.x = display.contentWidth - score.contentWidth - 20
score.y = row.height * 0.5
score:setFillColor( 0, 0, 0 )
end
local tableView = widget.newTableView
{
left = 0,
top = 0,
height = display.contentHeight,
width = display.contentWidth,
onRowRender = onRowRender,
onRowTouch = onRowTouch,
listener = scrollListener
}
tableView.x = display.contentWidth + display.contentWidth/2 + 50
transition.to( tableView, { time=500, x=display.contentWidth / 2, transition=easing.inOutExpo } )
for i = 1, 1 do
local isCategory = false
local rowHeight = 40
local rowColor = { 255, 255, 255 }
local lineColor = { 220, 220, 220 }
tableView:insertRow
{
isCategory = isCategory,
rowHeight = rowHeight,
rowColor = rowColor,
lineColor = lineColor,
onRender = onRowRender,
}
end
end
end
Your tableView being declared within the outer loop meant that the first instance of it would be transitioned over by the second instance. And a quick look over the docs indicates that each event.row allows an optional params table to include any data you may need to render the row.
local MasterData = xml:loadFile( "sample.xml")
local XMLdataTEST = {}
for i=1,#MasterData.child do
XMLdataTEST[i] = MasterData.child[i]
end
-- ** moved from loop **
local function onRowRender( event )
local row = event.row
local number = display.newText( row, "" .. row.index .. " - ", 12, 0, nil, 18 )
number:setReferencePoint( display.CenterLeftReferencePoint )
number.x = 15
number.y = row.height * 0.5
number:setFillColor( 0, 0, 0 )
-- ** changed to use params table **
local name = display.newText(row, row.params.input1, 12, 0, nil, 18 )
name:setReferencePoint( display.CenterLeftReferencePoint )
name.x = number.x + number.contentWidth
name.y = row.height * 0.5
name:setFillColor( 0, 0, 0 )
local score = display.newText(row,"testy", 12, 0, nil, 18 )
score:setReferencePoint( display.CenterLeftReferencePoint )
score.x = display.contentWidth - score.contentWidth - 20
score.y = row.height * 0.5
score:setFillColor( 0, 0, 0 )
end
-- ** moved from loop **
local tableView = widget.newTableView {
left = 0,
top = 0,
height = display.contentHeight,
width = display.contentWidth,
onRowRender = onRowRender,
onRowTouch = onRowTouch,
listener = scrollListener
}
tableView.x = display.contentWidth + display.contentWidth/2 + 50
transition.to( tableView, { time=500, x=display.contentWidth / 2, transition=easing.inOutExpo } )
inputNumber = 1
check1 = 'jan'
check2 = 'kevin'
for i=1,#XMLdataTEST do
local data1 = XMLdata[i].child[1].value
local data2 = XMLdata[i].child[2].value
local data3 = XMLdata[i].child[3].value
local data4 = XMLdata[i].child[4].value
input1 = string.lower( data1.. "" )
input2 = string.lower(_G['check' .. inputNumber] )
input = input2
if string.find( input1.. "" , input ) then
print(inputNumber.. " match with " ..input)
inputNumber = inputNumber + 1
local isCategory = false
local rowHeight = 40
local rowColor = { 255, 255, 255 }
local lineColor = { 220, 220, 220 }
tableView:insertRow
{
isCategory = isCategory,
rowHeight = rowHeight,
rowColor = rowColor,
lineColor = lineColor,
-- ** pass input1 to onRowRender **
params = { input1 = input1 }
}
end
end

Lua accessing table stored in external file

I have an external lua file that has a table stored in it that is formatted as follows:
sgeT = {
2535047 = {
{
["account"] = "TG-MCB110105",
["exec"] = "/share/home/00288/tg455591/NAMD_2.8b3/NAMD_2.8b3_Linux-x86_64-MVAPICH-Intel-Ranger/namd2",
["execEpoch"] = 1305825864,
["execModify"] = "Thu May 19 12:24:24 2011",
["execType"] = "user:binary",
["jobID"] = "2535047",
["numCores"] = "128",
["numNodes"] = "8",
pkgT = {
},
["runTime"] = "65125",
["sha1"] = "e157dd510a7be4d775d6ceb271373ea24e7f9559",
sizeT = {
["bss"] = "104552",
["data"] = "192168",
["text"] = "10650813",
},
["startEpoch"] = "1335843433",
["startTime"] = "Mon Apr 30 22:37:13 2012",
["user"] = "guo",
},
},
2535094 = {
{
["account"] = "TG-MCB110105",
["exec"] = "/share/home/00288/tg455591/NAMD_2.8b3/NAMD_2.8b3_Linux-x86_64-MVAPICH-Intel-Ranger/namd2",
["execEpoch"] = 1305825864,
["execModify"] = "Thu May 19 12:24:24 2011",
["execType"] = "user:binary",
["jobID"] = "2535094",
["numCores"] = "128",
["numNodes"] = "8",
pkgT = {
},
["runTime"] = "81635",
["sha1"] = "e157dd510a7be4d775d6ceb271373ea24e7f9559",
sizeT = {
["bss"] = "104552",
["data"] = "192168",
["text"] = "10650813",
},
["startEpoch"] = "1335823028",
["startTime"] = "Mon Apr 30 16:57:08 2012",
["user"] = "guo",
},
}
I want to iterate through the table like an array and return the exec key, value pair, and I am completely new to lua and I am using the following script:
FileStr = "lariatData-sgeT-2012-05-31.lua"
Hnd, ErrStd = io.open(FileStr, "r")
myTable = loadTable(FileStr)
if Hnd then
for Str in Hnd:lines() do
print(Str, "\n")
for exec, val in pairs(myTable) do
print(exec.." "..val, "\n")
end
end
Hnd.close()
else
print(ErrStr, "\n")
end
However, it is returning that the table is nil. What am I doing wrong?
In continuation of comments above:
-- Notice that I've used `[2535047]`
sgeT = {
[2535047] = {
{
["account"] = "TG-MCB110105",
["exec"] = "/share/home/00288/tg455591/NAMD_2.8b3/NAMD_2.8b3_Linux-x86_64-MVAPICH-Intel-Ranger/namd2",
["execEpoch"] = 1305825864,
["execModify"] = "Thu May 19 12:24:24 2011",
["execType"] = "user:binary",
["jobID"] = "2535047",
["numCores"] = "128",
["numNodes"] = "8",
pkgT = {
},
["runTime"] = "65125",
["sha1"] = "e157dd510a7be4d775d6ceb271373ea24e7f9559",
sizeT = {
["bss"] = "104552",
["data"] = "192168",
["text"] = "10650813",
},
["startEpoch"] = "1335843433",
["startTime"] = "Mon Apr 30 22:37:13 2012",
["user"] = "guo",
},
},
}
The above is your file. Then, your Lua program shall be:
FileStr = "lariatData-sgeT-2012-05-31.lua"
Hnd, ErrStr = io.open(FileStr, "r")
if Hnd then
dofile(FileStr)
for Str in Hnd:lines() do
print(Str, "\n")
for exec, val in pairs(sgeT) do
print(exec.." "..val, "\n")
end
end
Hnd.close()
else
print(ErrStr, "\n")
end

Resources