Default action per Operating System

If you want to be able to invoke premake4 without having to provide an action you can add the following function to your premake4 lua file.

function defaultaction(osName, actionName)
	if osName ~= nil and os.is(osName) == false then
		return
	end
 
	if _ACTION == nil then
		_ACTION = actionName
	end
end

You can invoke it with one parameters to provide a default action for any OS.

defaultaction "codeblocks"

Now if you run premake4 without any parameters in the folder where your premake4.lua file is located it will be equivalent to running "premake4 codeblocks".

Alternatively you can call the function with two parameters in order to provide a default action dependent on the OS premake4 is running on.

defaultaction("windows", "vs2010")
defaultaction("linux", "gmake")

Hope that helps,
ppl

Nice, thanks!

I think you can shorten that code a bit:

function defaultaction(osName, actionName)
	if not os.is(osName) then
		return
	end
 
	_ACTION = _ACTION or actionName
end

Does it break if you make it shorter?

function defaultaction(osName, actionName)
   if os.is(osName) then
      _ACTION = _ACTION or actionName
   end
end

That works too. Nice and direct :)

I think this feature deserves integration into Premake