Commit d19f6e6b0a76272a649560b69bdd6a008405c747
1 parent
89551d48
fix
git-svn-id: http://svn.net-core.org/repos/t-engine4@2994 51575b47-30f0-44d4-a5cc-537603b46e54
Showing
7 changed files
with
85 additions
and
69 deletions
... | ... | @@ -25,7 +25,9 @@ else |
25 | 25 | end |
26 | 26 | |
27 | 27 | -- Look for a core |
28 | -function get_core(type, id) | |
28 | +function get_core(coretype, id) | |
29 | + coretype = coretype or "te4core" | |
30 | + | |
29 | 31 | local homepath = fs.getUserPath()..fs.getPathSeparator()..fs.getHomePath()..fs.getPathSeparator().."4.0" |
30 | 32 | fs.mount(homepath, "/", 1) |
31 | 33 | |
... | ... | @@ -33,20 +35,23 @@ function get_core(type, id) |
33 | 35 | local usable = {} |
34 | 36 | for i, file in ipairs(fs.list("/engines/cores/")) do |
35 | 37 | if file:find("%.tec$") then |
36 | - print("Possible engine core", file) | |
37 | - if id > 0 and file == type.."-"..id..".tec" then usable[#usable+1] = {file=file, id=id} | |
38 | - elseif id == -1 and file:find(type) then | |
38 | + print("Looking for cores", coretype, id, " <=> ", file) | |
39 | + if id > 0 and file == coretype.."-"..id..".tec" then | |
40 | + usable[#usable+1] = {file=file, id=id} | |
41 | + print("Possible engine core", file) | |
42 | + elseif id == -1 and file:find(coretype) then | |
39 | 43 | local _, _, cid = file:find("%-([0-9]+)%.tec$") |
40 | 44 | cid = tonumber(cid) |
41 | 45 | if cid then |
42 | 46 | usable[#usable+1] = {file=file, id=cid} |
47 | + print("Possible engine core", file) | |
43 | 48 | end |
44 | 49 | end |
45 | 50 | end |
46 | 51 | end |
47 | 52 | -- Order the cores to find the newest |
48 | 53 | table.sort(usable, function(a, b) return b.id < a.id end) |
49 | - for i, file in ipairs(usable) do print("Selected cores:", file.file) end | |
54 | + for i, file in ipairs(usable) do print("Selected cores:", file.id, file.file) end | |
50 | 55 | |
51 | 56 | -- Check for sanity and tell the runner to use it |
52 | 57 | local core = "/engines/cores/"..usable[1].file | ... | ... |
... | ... | @@ -949,7 +949,7 @@ function util.showMainMenu(no_reboot, reboot_engine, reboot_engine_version, rebo |
949 | 949 | else |
950 | 950 | -- Tell the C engine to discard the current lua state and make a new one |
951 | 951 | print("[MAIN] rebooting lua state: ", reboot_engine, reboot_engine_version, reboot_module, reboot_name, reboot_new) |
952 | - core.game.reboot(-1, reboot_engine or "te4", reboot_engine_version or "LATEST", reboot_module or "boot", reboot_name or "player", reboot_new, reboot_einfo or "") | |
952 | + core.game.reboot("te4core", -1, reboot_engine or "te4", reboot_engine_version or "LATEST", reboot_module or "boot", reboot_name or "player", reboot_new, reboot_einfo or "") | |
953 | 953 | end |
954 | 954 | end |
955 | 955 | ... | ... |
... | ... | @@ -142,33 +142,22 @@ static int lua_exit_engine(lua_State *L) |
142 | 142 | exit_engine = TRUE; |
143 | 143 | return 0; |
144 | 144 | } |
145 | -extern int reboot_lua; | |
146 | -extern bool reboot_new; | |
147 | -extern char *reboot_engine, *reboot_engine_version, *reboot_module, *reboot_name, *reboot_einfo; | |
148 | 145 | static int lua_reboot_lua(lua_State *L) |
149 | 146 | { |
150 | - if (reboot_engine) free(reboot_engine); | |
151 | - if (reboot_engine_version) free(reboot_engine_version); | |
152 | - if (reboot_module) free(reboot_module); | |
153 | - if (reboot_name) free(reboot_name); | |
154 | - if (reboot_einfo) free(reboot_einfo); | |
155 | - | |
156 | - reboot_lua = luaL_checknumber(L, 1); | |
157 | - reboot_engine = (char *)luaL_checkstring(L, 2); | |
158 | - reboot_engine_version = (char *)luaL_checkstring(L, 3); | |
159 | - reboot_module = (char *)luaL_checkstring(L, 4); | |
160 | - reboot_name = (char *)luaL_checkstring(L, 5); | |
161 | - reboot_new = lua_toboolean(L, 6); | |
162 | - reboot_einfo = (char *)luaL_checkstring(L, 7); | |
147 | + core_def->define( | |
148 | + core_def, | |
149 | + luaL_checkstring(L, 1), | |
150 | + luaL_checknumber(L, 2), | |
151 | + luaL_checkstring(L, 3), | |
152 | + luaL_checkstring(L, 4), | |
153 | + luaL_checkstring(L, 5), | |
154 | + luaL_checkstring(L, 6), | |
155 | + lua_toboolean(L, 7), | |
156 | + luaL_checkstring(L, 8) | |
157 | + ); | |
163 | 158 | |
164 | 159 | // By default reboot the same core -- this skips some initializations |
165 | - if (reboot_lua == -1) reboot_lua = TE4CORE_VERSION; | |
166 | - | |
167 | - if (reboot_engine) reboot_engine = strdup(reboot_engine); | |
168 | - if (reboot_engine_version) reboot_engine_version = strdup(reboot_engine_version); | |
169 | - if (reboot_module) reboot_module = strdup(reboot_module); | |
170 | - if (reboot_name) reboot_name = strdup(reboot_name); | |
171 | - if (reboot_einfo) reboot_einfo = strdup(reboot_einfo); | |
160 | + if (core_def->corenum == -1) core_def->corenum = TE4CORE_VERSION; | |
172 | 161 | |
173 | 162 | return 0; |
174 | 163 | } | ... | ... |
... | ... | @@ -53,10 +53,7 @@ bool no_debug = FALSE; |
53 | 53 | int current_mousehandler = LUA_NOREF; |
54 | 54 | int current_keyhandler = LUA_NOREF; |
55 | 55 | int current_game = LUA_NOREF; |
56 | -int reboot_lua = 0; | |
57 | -bool reboot_new = FALSE; | |
58 | -char *request_profile = "default"; | |
59 | -char *reboot_engine = NULL, *reboot_engine_version = NULL, *reboot_module = NULL, *reboot_name = NULL, *reboot_einfo = NULL; | |
56 | +core_boot_type *core_def = NULL; | |
60 | 57 | bool exit_engine = FALSE; |
61 | 58 | bool no_sound = FALSE; |
62 | 59 | bool isActive = TRUE; |
... | ... | @@ -668,7 +665,7 @@ void do_resize(int w, int h, bool fullscreen) |
668 | 665 | |
669 | 666 | void boot_lua(int state, bool rebooting, int argc, char *argv[]) |
670 | 667 | { |
671 | - reboot_lua = 0; | |
668 | + core_def->corenum = 0; | |
672 | 669 | |
673 | 670 | if (state == 1) |
674 | 671 | { |
... | ... | @@ -776,14 +773,13 @@ void boot_lua(int state, bool rebooting, int argc, char *argv[]) |
776 | 773 | // And run the lua engine scripts |
777 | 774 | if (!luaL_loadfile(L, "/loader/init.lua")) |
778 | 775 | { |
779 | - if (reboot_engine) lua_pushstring(L, reboot_engine); else lua_pushnil(L); | |
780 | - if (reboot_engine_version) lua_pushstring(L, reboot_engine_version); else lua_pushnil(L); | |
781 | - if (reboot_module) lua_pushstring(L, reboot_module); else lua_pushnil(L); | |
782 | - if (reboot_name) lua_pushstring(L, reboot_name); else lua_pushnil(L); | |
783 | - lua_pushboolean(L, reboot_new); | |
784 | - if (reboot_einfo) lua_pushstring(L, reboot_einfo); else lua_pushnil(L); | |
785 | - if (request_profile) lua_pushstring(L, request_profile); else lua_pushnil(L); | |
786 | - docall(L, 7, 0); | |
776 | + if (core_def->reboot_engine) lua_pushstring(L, core_def->reboot_engine); else lua_pushnil(L); | |
777 | + if (core_def->reboot_engine_version) lua_pushstring(L, core_def->reboot_engine_version); else lua_pushnil(L); | |
778 | + if (core_def->reboot_module) lua_pushstring(L, core_def->reboot_module); else lua_pushnil(L); | |
779 | + if (core_def->reboot_name) lua_pushstring(L, core_def->reboot_name); else lua_pushnil(L); | |
780 | + lua_pushboolean(L, core_def->reboot_new); | |
781 | + if (core_def->reboot_einfo) lua_pushstring(L, core_def->reboot_einfo); else lua_pushnil(L); | |
782 | + docall(L, 6, 0); | |
787 | 783 | } |
788 | 784 | else |
789 | 785 | { |
... | ... | @@ -795,8 +791,9 @@ void boot_lua(int state, bool rebooting, int argc, char *argv[]) |
795 | 791 | /** |
796 | 792 | * Core entry point. |
797 | 793 | */ |
798 | -void _te4_export te4main(int argc, char *argv[], core_boot_type *core_def) | |
794 | +void _te4_export te4main(int argc, char *argv[], core_boot_type *given_core_def) | |
799 | 795 | { |
796 | + core_def = given_core_def; | |
800 | 797 | core_def->corenum = 0; |
801 | 798 | |
802 | 799 | // Get cpu cores |
... | ... | @@ -811,13 +808,7 @@ void _te4_export te4main(int argc, char *argv[], core_boot_type *core_def) |
811 | 808 | for (i = 1; i < argc; i++) |
812 | 809 | { |
813 | 810 | char *arg = argv[i]; |
814 | - if (!strncmp(arg, "-P", 2)) request_profile = strdup(arg+2); | |
815 | - if (!strncmp(arg, "-M", 2)) reboot_module = strdup(arg+2); | |
816 | - if (!strncmp(arg, "-u", 2)) reboot_name = strdup(arg+2); | |
817 | - if (!strncmp(arg, "-E", 2)) reboot_einfo = strdup(arg+2); | |
818 | - if (!strncmp(arg, "-n", 2)) reboot_new = TRUE; | |
819 | - if (!strncmp(arg, "--no-debug", 10)) no_debug = TRUE; | |
820 | - if (!strncmp(arg, "--flush-stdout", 14)) setvbuf(stdout, (char *) NULL, _IOLBF, 0);; | |
811 | + if (!strncmp(arg, "--no-debug", 10)) no_debug = 0; | |
821 | 812 | } |
822 | 813 | |
823 | 814 | // initialize engine and set up resolution and depth |
... | ... | @@ -949,10 +940,10 @@ void _te4_export te4main(int argc, char *argv[], core_boot_type *core_def) |
949 | 940 | if (!realtime_timer_id && isActive && !tickPaused) on_tick(); |
950 | 941 | |
951 | 942 | /* Reboot the lua engine */ |
952 | - if (reboot_lua) | |
943 | + if (core_def->corenum) | |
953 | 944 | { |
954 | 945 | // Just reboot the lua VM |
955 | - if (reboot_lua == TE4CORE_VERSION && 0) | |
946 | + if (core_def->corenum == TE4CORE_VERSION && 0) | |
956 | 947 | { |
957 | 948 | tickPaused = FALSE; |
958 | 949 | setupRealtime(0); |
... | ... | @@ -962,13 +953,10 @@ void _te4_export te4main(int argc, char *argv[], core_boot_type *core_def) |
962 | 953 | // Clean up and tell the runner to run a different core |
963 | 954 | else |
964 | 955 | { |
956 | + lua_close(L); | |
965 | 957 | free_particles_thread(); |
966 | 958 | free_profile_thread(); |
967 | - lua_close(L); | |
968 | 959 | PHYSFS_deinit(); |
969 | - | |
970 | - core_def->corenum = reboot_lua; | |
971 | - | |
972 | 960 | break; |
973 | 961 | } |
974 | 962 | } | ... | ... |
... | ... | @@ -21,6 +21,8 @@ |
21 | 21 | #ifndef _MAIN_H_ |
22 | 22 | #define _MAIN_H_ |
23 | 23 | |
24 | +#include "runner/core.h" | |
25 | + | |
24 | 26 | #if defined(SELFEXE_LINUX) |
25 | 27 | #define _te4_export |
26 | 28 | #elif defined(SELFEXE_WINDOWS) |
... | ... | @@ -51,6 +53,7 @@ struct lua_err_type_s { |
51 | 53 | typedef struct lua_err_type_s lua_err_type; |
52 | 54 | extern lua_err_type *last_lua_error_head, *last_lua_error_tail; |
53 | 55 | extern void del_lua_error(); |
56 | +extern core_boot_type *core_def; | |
54 | 57 | |
55 | 58 | #endif |
56 | 59 | ... | ... |
... | ... | @@ -21,7 +21,9 @@ |
21 | 21 | #ifndef TE4CORE_H |
22 | 22 | #define TE4CORE_H |
23 | 23 | |
24 | -typedef struct { | |
24 | +struct core_def_s { | |
25 | + void (*define)(struct core_def_s *core_def, const char *coretype, int id, const char *reboot_engine, const char *reboot_engine_version, const char *reboot_module, const char *reboot_name, int reboot_new, const char *reboot_einfo); | |
26 | + | |
25 | 27 | int corenum; |
26 | 28 | char *coretype; |
27 | 29 | |
... | ... | @@ -31,6 +33,8 @@ typedef struct { |
31 | 33 | char *reboot_name; |
32 | 34 | char *reboot_einfo; |
33 | 35 | int reboot_new; |
34 | -} core_boot_type; | |
36 | +}; | |
37 | + | |
38 | +typedef struct core_def_s core_boot_type; | |
35 | 39 | |
36 | 40 | #endif | ... | ... |
... | ... | @@ -21,6 +21,7 @@ |
21 | 21 | |
22 | 22 | #include <stdio.h> |
23 | 23 | #include <stdlib.h> |
24 | +#include <string.h> | |
24 | 25 | |
25 | 26 | #ifdef SELFEXE_WINDOWS |
26 | 27 | #include <windows.h> |
... | ... | @@ -35,6 +36,26 @@ |
35 | 36 | #include "core.h" |
36 | 37 | #include "getself.h" |
37 | 38 | |
39 | +// Update core to run | |
40 | +void define_core(core_boot_type *core_def, const char *coretype, int id, const char *reboot_engine, const char *reboot_engine_version, const char *reboot_module, const char *reboot_name, int reboot_new, const char *reboot_einfo) | |
41 | +{ | |
42 | + if (core_def->coretype) free(core_def->coretype); | |
43 | + if (core_def->reboot_engine) free(core_def->reboot_engine); | |
44 | + if (core_def->reboot_engine_version) free(core_def->reboot_engine_version); | |
45 | + if (core_def->reboot_module) free(core_def->reboot_module); | |
46 | + if (core_def->reboot_name) free(core_def->reboot_name); | |
47 | + if (core_def->reboot_einfo) free(core_def->reboot_einfo); | |
48 | + | |
49 | + core_def->corenum = id; | |
50 | + core_def->coretype = coretype ? strdup(coretype) : NULL; | |
51 | + core_def->reboot_engine = reboot_engine ? strdup(reboot_engine) : NULL; | |
52 | + core_def->reboot_engine_version = reboot_engine_version ? strdup(reboot_engine_version) : NULL; | |
53 | + core_def->reboot_module = reboot_module ? strdup(reboot_module) : NULL; | |
54 | + core_def->reboot_name = reboot_name ? strdup(reboot_name) : NULL; | |
55 | + core_def->reboot_einfo = reboot_einfo ? strdup(reboot_einfo) : NULL; | |
56 | + core_def->reboot_new = reboot_new; | |
57 | +} | |
58 | + | |
38 | 59 | // Load the shared lib containing the core and calls te4main inside it, passing control to that core |
39 | 60 | void run_core(core_boot_type *core_def, int argc, char **argv) |
40 | 61 | { |
... | ... | @@ -78,7 +99,7 @@ void run_core(core_boot_type *core_def, int argc, char **argv) |
78 | 99 | |
79 | 100 | // Get the core |
80 | 101 | lua_getglobal(L, "get_core"); |
81 | - lua_pushstring(L, core_def->coretype); | |
102 | + if (core_def->coretype) lua_pushstring(L, core_def->coretype); else lua_pushnil(L); | |
82 | 103 | lua_pushnumber(L, core_def->corenum); |
83 | 104 | lua_call(L, 2, 1); |
84 | 105 | char *core = strdup((char*)lua_tostring(L, -1)); |
... | ... | @@ -160,19 +181,25 @@ void run_core(core_boot_type *core_def, int argc, char **argv) |
160 | 181 | |
161 | 182 | int main(int argc, char **argv) |
162 | 183 | { |
163 | - core_boot_type core_def; | |
184 | + core_boot_type *core_def = calloc(1, sizeof(core_boot_type)); | |
164 | 185 | |
165 | - core_def.corenum = -1; // Start with latest core | |
166 | - core_def.coretype = "te4core"; | |
167 | - core_def.reboot_engine = NULL; | |
168 | - core_def.reboot_engine_version = NULL; | |
169 | - core_def.reboot_module = NULL; | |
170 | - core_def.reboot_name = NULL; | |
171 | - core_def.reboot_einfo = NULL; | |
172 | - core_def.reboot_new = 0; | |
186 | + core_def->define = &define_core; | |
187 | + core_def->define(core_def, "te4core", -1, NULL, NULL, NULL, NULL, 0, NULL); | |
188 | + | |
189 | + // Parse arguments | |
190 | + int i; | |
191 | + for (i = 1; i < argc; i++) | |
192 | + { | |
193 | + char *arg = argv[i]; | |
194 | + if (!strncmp(arg, "-M", 2)) core_def->reboot_module = strdup(arg+2); | |
195 | + if (!strncmp(arg, "-u", 2)) core_def->reboot_name = strdup(arg+2); | |
196 | + if (!strncmp(arg, "-E", 2)) core_def->reboot_einfo = strdup(arg+2); | |
197 | + if (!strncmp(arg, "-n", 2)) core_def->reboot_new = 0; | |
198 | + if (!strncmp(arg, "--flush-stdout", 14)) setvbuf(stdout, (char *) NULL, _IOLBF, 0);; | |
199 | + } | |
173 | 200 | |
174 | 201 | // Run the requested cores until we want no more |
175 | - while (core_def.corenum) run_core(&core_def, argc, argv); | |
202 | + while (core_def->corenum) run_core(core_def, argc, argv); | |
176 | 203 | |
177 | 204 | exit(EXIT_SUCCESS); |
178 | 205 | } | ... | ... |
-
Please register or login to post a comment