Skip to content
Jason Perkins edited this page Apr 1, 2015 · 3 revisions

Home > [Scripting With Premake](Scripting With Premake) > A Bit Of Meta


A Bit Of Meta

Let me start with a bit of general information that you will need to know to begin scripting.

Files and File Names

Premake will look for a file named premake4.lua by default, much like make looks for a file named Makefile. So that's the name you want to give your project script files, generally.

You can specify a different file name using the file argument, like so:

premake4 --file=myfilename.lua

You can define your entire project in one script file if you want, or you can split up the projects into their own files, or any other organization you can dream up. Use the include() function or Lua's dofile() to link all the files together.

I personally like to use just one file for simple projects, and one-file-per-project for more complex builds.

Project Functions and Arguments

You define your software project by calling a sequence of functions, such as solution, project, and defines. These functions set up the project state and take care of error checking and the like.

When calling a function with a single string constant for an argument, Lua allows you to drop the parenthesis that would normally appear around the argument list. So these two statements are functionally identical:

#!lua
solution("MySolution")
solution "MySolution"

I find the latter form a bit more readable. The same goes with a single list argument:

#!lua
defines({"DEBUG", "TRACE"})
defines {"DEBUG", "TRACE"}

If you want to use a variable as an argument, or the result of a calculation, then you must use the parenthesis:

#!lua
local lang = "C++"
language (lang)   -- need the parenthesis here

location ("build/" .. _ACTION)  -- and here too

Values and Lists

Many of Premake's functions accept a list of values as a parameter. For instance, a list of source code files, or defined symbols, or build flags. When defining a list of values you need to surround them in curly brackets, Lua's syntax for a list. If you only want to set a single value, you can leave off the brackets if you like.

#!lua
defines { "DEBUG", "TRACE" }  -- defines multiple values
defines "NDEBUG"              -- defines a single value

There are also functions that only accept a single value, such as solution and project names, the project kind and language, and so on. If you try to pass a list to these function you'll get an error. These string values may be delimited with single (') or double (") quotes.

#!lua
language "C++"
kind 'ConsoleApp'

For more information on Lua programming, see the Lua website or Programming in Lua. If you get stuck, post a question over in the forums and I will do my best to help you out.

Clone this wiki locally