Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Perkins <starkos@industriousone.com>2012-02-06 23:24:44 +0400
committerJason Perkins <starkos@industriousone.com>2012-02-06 23:24:44 +0400
commit0536685c8c3ffd31b492abbbc59b2df29da181b1 (patch)
treee04311a7f31a6afe76a5bd8836ccc3810ca8e517
parente4d23a49bf9c3c917c006385d6c536ff763e19f8 (diff)
Patch 3353975: Support usage of premake as a library (Konstantin Tokarev)
-rw-r--r--CHANGES.txt1
-rwxr-xr-xsrc/host/premake.c37
-rwxr-xr-xsrc/host/premake.h5
-rw-r--r--src/host/premake_main.c29
4 files changed, 51 insertions, 21 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 1bae7bd..a3fb801 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -53,6 +53,7 @@
* Patch 3463020: Add windres environment variable for makefiles (icebreaker)
* Bug 3413866: Incorrect VS200x .csproj relative source paths
* Patch 3111264: Allow path.join() to accept any number of args
+* Patch 3353975: Support usage of premake as a library (Konstantin Tokarev)
-------
diff --git a/src/host/premake.c b/src/host/premake.c
index 04686d3..1db66fd 100755
--- a/src/host/premake.c
+++ b/src/host/premake.c
@@ -1,7 +1,7 @@
/**
* \file premake.c
* \brief Program entry point.
- * \author Copyright (c) 2002-2011 Jason Perkins and the Premake project
+ * \author Copyright (c) 2002-2012 Jason Perkins and the Premake project
*/
#include <stdlib.h>
@@ -18,11 +18,12 @@
#define ERROR_MESSAGE "%s\n"
-static int find_premake_executable(lua_State* L, const char* argv0);
static int process_arguments(lua_State* L, int argc, const char** argv);
static int process_option(lua_State* L, const char* arg);
static int load_builtin_scripts(lua_State* L);
+int premake_locate(lua_State* L, const char* argv0);
+
/* A search path for script files */
static const char* scripts_path = NULL;
@@ -64,25 +65,16 @@ static const luaL_Reg string_functions[] = {
{ NULL, NULL }
};
+
/**
- * Program entry point.
+ * Initialize the Premake Lua environment.
*/
-int main(int argc, const char** argv)
+int premake_init(lua_State* L)
{
- lua_State* L;
- int z = OKAY;
-
- /* prepare Lua for use */
- L = lua_open();
- luaL_openlibs(L);
luaL_register(L, "path", path_functions);
luaL_register(L, "os", os_functions);
luaL_register(L, "string", string_functions);
- /* push the location of the Premake executable */
- find_premake_executable(L, argv[0]);
- lua_setglobal(L, "_PREMAKE_COMMAND");
-
/* push the application metadata */
lua_pushstring(L, LUA_COPYRIGHT);
lua_setglobal(L, "_COPYRIGHT");
@@ -96,20 +88,23 @@ int main(int argc, const char** argv)
/* set the OS platform variable */
lua_pushstring(L, PLATFORM_STRING);
lua_setglobal(L, "_OS");
+
+ return OKAY;
+}
+
+int premake_execute(lua_State* L, int argc, const char** argv)
+{
/* Parse the command line arguments */
- if (z == OKAY) z = process_arguments(L, argc, argv);
+ int z = process_arguments(L, argc, argv);
/* Run the built-in Premake scripts */
if (z == OKAY) z = load_builtin_scripts(L);
-
- /* Clean up and turn off the lights */
- lua_close(L);
+
return z;
}
-
/**
* Locate the Premake executable, and push its full path to the Lua stack.
* Based on:
@@ -117,7 +112,7 @@ int main(int argc, const char** argv)
* http://stackoverflow.com/questions/933850/how-to-find-the-location-of-the-executable-in-c
* http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe
*/
-int find_premake_executable(lua_State* L, const char* argv0)
+int premake_locate(lua_State* L, const char* argv0)
{
#if !defined(PATH_MAX)
#define PATH_MAX (4096)
@@ -270,7 +265,7 @@ int process_option(lua_State* L, const char* arg)
-#if defined(_DEBUG)
+#if !defined(NDEBUG)
/**
* When running in debug mode, the scripts are loaded from the disk. The path to
* the scripts must be provided via either the /scripts command line option or
diff --git a/src/host/premake.h b/src/host/premake.h
index 5f496e6..a374780 100755
--- a/src/host/premake.h
+++ b/src/host/premake.h
@@ -72,3 +72,8 @@ int os_uuid(lua_State* L);
int string_endswith(lua_State* L);
+/* Engine interface */
+int premake_init(lua_State* L);
+int premake_locate(lua_State* L, const char* argv0);
+int premake_execute(lua_State* L, int argc, const char** argv);
+
diff --git a/src/host/premake_main.c b/src/host/premake_main.c
new file mode 100644
index 0000000..86bc971
--- /dev/null
+++ b/src/host/premake_main.c
@@ -0,0 +1,29 @@
+/**
+ * \file premake_main.c
+ * \brief Program entry point.
+ * \author Copyright (c) 2002-2012 Jason Perkins and the Premake project
+ */
+
+#include "premake.h"
+
+int main(int argc, const char** argv)
+{
+ lua_State* L;
+ int z = OKAY;
+
+ L = lua_open();
+ luaL_openlibs(L);
+ z = premake_init(L);
+
+ /* push the location of the Premake executable */
+ premake_locate(L, argv[0]);
+ lua_setglobal(L, "_PREMAKE_COMMAND");
+
+ if (z == OKAY)
+ {
+ z = premake_execute(L, argc, argv);
+ }
+
+ lua_close(L);
+ return z;
+}