1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/**
* \file fn_solution.c
* \brief Create or select a solution object.
* \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
*/
#include "premake.h"
#include "script_internal.h"
/**
* Create a new solution object, or select an existing one.
*/
int fn_solution(lua_State* L)
{
const char* name;
/* if there are no parameters, return the active solution */
if (lua_gettop(L) == 0)
{
script_internal_get_active_object(L, SolutionObject, IS_OPTIONAL);
return 1;
}
name = luaL_checkstring(L, 1);
/* check to see if a solution with this name already exists */
lua_getglobal(L, SOLUTIONS_KEY);
lua_getfield(L, -1, name);
if (lua_isnil(L, -1))
{
/* solution does not exists, create it */
lua_newtable(L);
/* set the name */
lua_pushstring(L, name);
lua_setfield(L, -2, SolutionFieldInfo[SolutionName].name);
/* set the base directory */
lua_pushstring(L, script_internal_script_dir(L));
lua_setfield(L, -2, SolutionFieldInfo[SolutionBaseDir].name);
/* create an empty list of projects */
lua_newtable(L);
lua_setfield(L, -2, PROJECTS_KEY);
/* configure the initial configuration block list */
lua_newtable(L);
lua_setfield(L, -2, BLOCKS_KEY);
script_internal_create_block(L);
/* use the list of fields to populate the object properties and accessor functions */
script_internal_populate_object(L, SolutionFieldInfo);
/* add it to the master list of solutions, keyed by name */
lua_pushvalue(L, -1);
lua_setfield(L, -4, name);
/* also add with integer key */
lua_pushvalue(L, -1);
lua_rawseti(L, -4, luaL_getn(L, -4) + 1);
}
/* activate and return the solution object */
script_internal_set_active_object(L, SolutionObject);
return 1;
}
|