New flag --interactive opens a REPL prompt with project loaded (h/t Richard Geary)
This commit is contained in:
parent
9e372f8edb
commit
b722cfef29
@ -832,6 +832,12 @@
|
||||
description = "Display this information"
|
||||
}
|
||||
|
||||
newoption
|
||||
{
|
||||
trigger = "interactive",
|
||||
description = "Interactive command prompt"
|
||||
}
|
||||
|
||||
newoption
|
||||
{
|
||||
trigger = "os",
|
||||
|
@ -41,6 +41,7 @@
|
||||
-- can be picked up by the scripts.
|
||||
|
||||
premake.action.set(_ACTION)
|
||||
local action = premake.action.current()
|
||||
|
||||
-- If there is a project script available, run it to get the
|
||||
-- project information, available options and actions, etc.
|
||||
@ -59,34 +60,46 @@
|
||||
return 1
|
||||
end
|
||||
|
||||
-- If no action was specified, show a short help message
|
||||
|
||||
if (not _ACTION) then
|
||||
print(shorthelp)
|
||||
return 1
|
||||
end
|
||||
|
||||
-- If there wasn't a project script I've got to bail now
|
||||
|
||||
if not hasScript then
|
||||
error("No Premake script (premake5.lua) found!", 0)
|
||||
end
|
||||
|
||||
-- Validate the command-line arguments. This has to happen after the
|
||||
-- script has run to allow for project-specific options
|
||||
|
||||
action = premake.action.current()
|
||||
if not action then
|
||||
error("Error: no such action '" .. _ACTION .. "'", 0)
|
||||
ok, err = premake.option.validate(_OPTIONS)
|
||||
if not ok then
|
||||
print("Error: " .. err)
|
||||
return 1
|
||||
end
|
||||
|
||||
ok, err = premake.option.validate(_OPTIONS)
|
||||
if not ok then error("Error: " .. err, 0) end
|
||||
-- If no further action is possible, show a short help message
|
||||
|
||||
if not _OPTIONS.interactive then
|
||||
if not _ACTION then
|
||||
print(shorthelp)
|
||||
return 1
|
||||
end
|
||||
|
||||
if not action then
|
||||
print("Error: no such action '" .. _ACTION .. "'")
|
||||
return 1
|
||||
end
|
||||
|
||||
if not hasScript then
|
||||
print("No Premake script (premake5.lua) found!")
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
-- "Bake" the project information, preparing it for use by the action
|
||||
|
||||
print("Building configurations...")
|
||||
premake.oven.bake()
|
||||
if action then
|
||||
print("Building configurations...")
|
||||
premake.oven.bake()
|
||||
end
|
||||
|
||||
-- Run the interactive prompt, if requested
|
||||
|
||||
if _OPTIONS.interactive then
|
||||
debug.prompt()
|
||||
end
|
||||
|
||||
-- Sanity check the current project setup
|
||||
|
||||
@ -99,6 +112,5 @@
|
||||
|
||||
print("Done.")
|
||||
return 0
|
||||
|
||||
end
|
||||
|
||||
|
47
src/host/debug_prompt.c
Normal file
47
src/host/debug_prompt.c
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* \file debug_prompt.c
|
||||
* \brief Display a prompt and enter interactive REPL mode.
|
||||
* \author Copyright (c) 2014 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
|
||||
/* Build on the REPL built into Lua already */
|
||||
#define main lua_main
|
||||
#include "lua-5.1.4/src/lua.c"
|
||||
|
||||
|
||||
/* Based on dotty() in lua.c */
|
||||
int debug_prompt(lua_State* L)
|
||||
{
|
||||
int status;
|
||||
|
||||
const char* oldProgName = progname;
|
||||
progname = NULL;
|
||||
|
||||
while ((status = loadline(L)) != -1) {
|
||||
if (status == 0) {
|
||||
status = docall(L, 0, 0);
|
||||
}
|
||||
|
||||
report(L, status);
|
||||
|
||||
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
|
||||
lua_getglobal(L, "print");
|
||||
lua_insert(L, 1);
|
||||
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0) {
|
||||
l_message(progname, lua_pushfstring(L,
|
||||
"error calling " LUA_QL("print") " (%s)",
|
||||
lua_tostring(L, -1))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lua_settop(L, 0); /* clear stack */
|
||||
fputs("\n", stdout);
|
||||
fflush(stdout);
|
||||
progname = oldProgName;
|
||||
return 0;
|
||||
}
|
||||
|
@ -42,6 +42,11 @@ static const luaL_Reg criteria_functions[] = {
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static const luaL_Reg debug_functions[] = {
|
||||
{ "prompt", debug_prompt },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static const luaL_Reg path_functions[] = {
|
||||
{ "getabsolute", path_getabsolute },
|
||||
{ "getrelative", path_getrelative },
|
||||
@ -87,6 +92,7 @@ static const luaL_Reg string_functions[] = {
|
||||
int premake_init(lua_State* L)
|
||||
{
|
||||
luaL_register(L, "criteria", criteria_functions);
|
||||
luaL_register(L, "debug", debug_functions);
|
||||
luaL_register(L, "path", path_functions);
|
||||
luaL_register(L, "os", os_functions);
|
||||
luaL_register(L, "string", string_functions);
|
||||
|
@ -65,6 +65,7 @@ void do_translate(char* value, const char sep);
|
||||
int criteria_compile(lua_State* L);
|
||||
int criteria_delete(lua_State* L);
|
||||
int criteria_matches(lua_State* L);
|
||||
int debug_prompt(lua_State* L);
|
||||
int path_getabsolute(lua_State* L);
|
||||
int path_getrelative(lua_State* L);
|
||||
int path_isabsolute(lua_State* L);
|
||||
|
Loading…
Reference in New Issue
Block a user