--[[ This Extension shows how to wrap-up an existing trigger, so its logic is reused and so it gets some of the benefits of Extensions, like automatic replication, etc. The trigger is Perl, so it needs its own runtime to be installed, but we could include it inside the Extension if we wanted so it's completely stand-alone without runtime dependencies. https://swarm.workshop.perforce.com/files/guest/jason_gibson/misc/ascii-check.pl?v=1 ]]-- function GlobalConfigFields() return {} end function InstanceConfigFields() return {} end function InstanceConfigEvents() return { ["form-in"] = "change" } end function runcmd( cmd ) local stderr = os.tmpname() local stdout = os.tmpname() -- todo: spaces in path local rc = os.execute( cmd .. ' > ' .. stdout .. ' 2> ' .. stderr ) local sefh = io.open( stderr ) local sofh = io.open( stdout ) local stderr = sefh:read( "*all" ) local stdout = sofh:read( "*all" ) sefh:close() sofh:close() return rc, stdout, stderr end function FormIn() local cmd = "perl " .. Helix.Core.Server.GetArchDirFileName( "ascii-check.pl" ) cmd = cmd .. ' "' .. Helix.Core.Server.GetVar( "formfile" ) .. '"' local rc, stdout, stderr = runcmd( cmd ) if rc == nil or string.len( stderr ) > 0 then Helix.Core.Server.SetClientMsg( "Error running wrapped trigger: " .. stdout .. stderr ) return false end if string.len( stdout ) > 0 then Helix.Core.Server.SetClientMsg( stdout ) end return true end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 30808 | C. Thomas Tyler |
Promoted from 2019.1/... to main/... |
||
//guest/perforce_software/extensions/2019.1/wrap_a_trigger/main.lua | |||||
#1 | 25601 | Jason Gibson |
Import example Extensions. p19.1@1797741 |