Search code examples
luapremake

Syntax of premake scripts


Can somebody explain to me what the syntax of a premake script means? A premake script is a valid lua script. Then what are solution, configurations, project in the below code? Variables? keywords?

-- A solution contains projects, and defines the available configurations
solution "MyApplication"
   configurations { "Debug", "Release" }

   -- A project defines one build target
   project "MyApplication"
      kind "ConsoleApp"
      language "C++"
      files { "**.h", "**.cpp" }

      configuration "Debug"
         defines { "DEBUG" }
         flags { "Symbols" }

      configuration "Release"
         defines { "NDEBUG" }
         flags { "Optimize" }

Edit: They are function calls. So Then how is this part

      configuration "Debug"
         defines { "DEBUG" }
         flags { "Symbols" }

      configuration "Release"
         defines { "NDEBUG" }
         flags { "Optimize" }

executed? the defines and flags calls are to be called according to the context of configuartion?


Solution

  • Functions

    If function takes only one argument that is a table or a string the parentheses can be omitted. Refer to 3.4.10 - Function Calls.

    Additionally, in your example indention is arbitrary. You could write:

    project("MyApplication")
    kind("ConsoleApp")
    language("C++")
    files({"**.h", "**.cpp"})
    

    And it would be as good as the original.

    Regarding the second matter. Most likely configuration and related defines and flags operate on some hidden local state. When you call configuration it changes this local state to refer to e.g. "Debug" configuration and so all following calls also refer to this local state. As in:

    do
       local state
       function set_state (name)
          state = name
       end
       function print_with_suffix (suffix)
          print(state, suffix)
       end
    end
    set_state("hello")
    print_with_suffix("world") --> hello  world