Merge branch 'master' of git://github.com/BTAxis/naev into testmission
[naev.git] / src / nlua_cli.c
blob0ff43c1912aeeeddfff4394dcf0457e0bd10ddf1
1 /*
2 * See Licensing and Copyright notice in naev.h
3 */
5 /**
6 * @file nlua_cli.c
8 * @brief Contains Lua bindings for the console.
9 */
11 #include "nlua_cli.h"
13 #include "naev.h"
15 #include "lauxlib.h"
17 #include "nlua.h"
18 #include "nluadef.h"
19 #include "log.h"
20 #include "mission.h"
23 /* CLI */
24 static int cli_missionStart( lua_State *L );
25 static int cli_missionTest( lua_State *L );
26 static const luaL_reg cli_methods[] = {
27 { "missionStart", cli_missionStart },
28 { "missionTest", cli_missionTest },
29 {0,0}
30 }; /**< CLI Lua methods. */
33 /**
34 * @brief Loads the CLI Lua library.
36 * @param L Lua state.
37 * @return 0 on success.
39 int nlua_loadCLI( lua_State *L )
41 luaL_register(L, "cli", cli_methods);
42 return 0;
45 /**
46 * @brief CLI generic Lua bindings.
48 * An example would be:
49 * @code
50 * cli.mission("Pirate Bounty") -- Triggers the Pirate Bounty mission.
51 * @endcode
53 * @luamod cli
55 /**
56 * @brief Starts a mission without testing conditionals.
58 * @usage cli.missionStart( "Pirate Bounty" )
60 * @luaparam misn Name of the mission to start.
61 * @luafunc missionStart( misn )
63 static int cli_missionStart( lua_State *L )
65 const char *str;
67 str = luaL_checkstring(L, 1);
68 if (mission_start( str )) {
69 NLUA_ERROR(L,"Failed to start mission.");
70 return 0;
73 return 0;
76 /**
77 * @brief Starts a mission by testing all the conditionals.
79 * @usage cli.missionTest( "Pirate Bounty" )
81 * @luaparam misn Name of the mission to start.
82 * @luafunc missionTest( misn )
84 static int cli_missionTest( lua_State *L )
86 const char *str;
88 str = luaL_checkstring(L, 1);
89 if (mission_start( str )) {
90 NLUA_ERROR(L,"Failed to start mission.");
91 return 0;
94 return 0;