Chaining actions

You can easily run existing action(s) from your custom action :

newaction {
    trigger = 'mytrigger',
    description = 'My description',
    shortname = "myshortname",
    valid_kinds = premake.action.get("gmake").valid_kinds,
    valid_languages = premake.action.get("gmake").valid_languages,
    valid_tools = premake.action.get("gmake").valid_tools,
    execute = function()
        -- Execute some stuff
        premake.action.call("gmake")
        -- You also can conditionally execute different actions, but remember about valid_* stufff
    end
}

You can also add 'onsolution' and 'onproject' handles to your action - they will be processed before function you've set for 'execute'. See function premake.action.call() for more details.

You can use this trick to run some code after baking but before selected action. The next example allows to run custom code before 'gmake' action without being noticed by end user:

--
-- Rename gmake action into _gmake
--
assert(premake.action.list.gmake, "Your Premake does not have gmake action!")
premake.action.list.gmake, premake.action.list._gmake = nil, premake.action.list.gmake
premake.action.list._gmake.trigger = "_gmake"
 
--
-- Add new gmake action
--
newaction {
    trigger     = "gmake",
    description = premake.action.get("_gmake").description,
    shortname   = premake.action.get("_gmake").shortname,
    valid_kinds = premake.action.get("_gmake").valid_kinds,
    valid_languages = premake.action.get("_gmake").valid_languages,
    valid_tools = premake.action.get("_gmake").valid_tools,
 
    onproject = function(prj)
       -- Your code
    end,
 
    execute = function()
        -- Your code
        premake.action.call("_gmake")
    end
}

Update: patch[1] provides easy and flexible building of action chains. You need just to declare actions and specify their dependencies,and Premake will deduce execution order internally.

[1] http://sourceforge.net/tracker/?func=detail&aid=3465239&group_id=71616&a...

Hi,
I'm trying to do something similar for vs20*, creating an alias for vs2008 for example, and I get an error:

Building configurations...
Running action 'msvc'...
Generating Project.sln...
[string "function io.capture()..."]:32: bad argument #2 to 'format' (number expected, got no value)

I tried copying all the parameters (os, onsolution, onproject, onclean*), removing execute (since on* parameters should then mimic the vs2008 action ones), but the result is the same. It works with gmake (I didn't try other actions) but fail for vs20*.

I bet you've forgotten shortname field in newaction

BTW, I have a patch, implementing more general and convenient way to chain action than this one. See [1] for more details. Feel free to ask if you don't understand how to use it.

[1] http://industriousone.com/topic/post-bake-hooks-implementation

No I can assure you that I double checked it (and just tried again just now to be sure) and that's not the problem :) .

I'll take a look at your patch. Thanks. (PS: I'm using a build from premake-stable, is the patch already submitted on it?)

No, but it should apply cleanly to stable. Or you can grab this unofficial "release" (includes binaries):

http://industriousone.com/topic/full-stack-qt-based-development-premake-...

Don't be afraid of word "Qt", it's just the same Premake but with several general-purpose patches applied :)