From aa786270b5ee39c2d067551435d4b274713b3474 Mon Sep 17 00:00:00 2001 From: TSnake41 Date: Tue, 31 Mar 2020 21:34:23 +0200 Subject: [PATCH] Improve repl and make output more consistent with raylib 3.0 Fix building issues. Check for duplicated entries. --- src/raylib.lua | 11 ++++++++--- src/raylua.c | 10 ++++++++++ src/raylua.lua | 11 ++++++++--- src/raylua_builder.c | 2 +- src/raylua_builder.lua | 24 +++++++++++------------- src/raylua_e.c | 10 +++++----- src/raylua_s.c | 2 +- 7 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/raylib.lua b/src/raylib.lua index b31d226..05ab548 100644 --- a/src/raylib.lua +++ b/src/raylib.lua @@ -14,7 +14,7 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ]] -print "[RAYLUA] Raylua boot script" +print "RAYLUA: Raylua boot script" local ffi = require "ffi" local C = ffi.C @@ -822,15 +822,20 @@ do local i = ffi.new("size_t", 0) local NULL = ffi.new("void *", nil) - print "[RAYLUA] Loading FFI binding entries." + print "RAYLUA: Loading FFI binding entries." while entries[i].name ~= NULL do local name, proto = ffi.string(entries[i].name), ffi.string(entries[i].proto) + + if rl[name] then + print("RAYLUA: Warn: Duplicated FFI entry : " .. name) + end + rl[name] = ffi.cast(proto, entries[i].ptr) i = i + 1 end - print("[RAYLUA] Loaded " .. tonumber(i) .. " FFI entries.") + print("RAYLUA: Loaded " .. tonumber(i) .. " FFI entries.") end -- colors diff --git a/src/raylua.c b/src/raylua.c index d9fcb1f..b12133c 100644 --- a/src/raylua.c +++ b/src/raylua.c @@ -21,6 +21,16 @@ #include #include +#include +#include +#include +#include + +#define RAYGUI_SUPPORT_ICONS +#define RAYGUI_IMPLEMENTATION +#define RAYGUI_STATIC +#include + #define PHYSAC_IMPLEMENTATION #define PHYSAC_NO_THREADS #include diff --git a/src/raylua.lua b/src/raylua.lua index cc1544d..7eaf50d 100644 --- a/src/raylua.lua +++ b/src/raylua.lua @@ -17,12 +17,17 @@ local load = loadstring function raylua.repl() - print ">> raylua WIP repl <<" + print "> raylua v3.0a <" + print "Type 'q' to quit." print "" while true do io.write "> " local line = io.read "l" + if line == "q" then + break + end + local f, err = loadstring(line) if f then @@ -57,7 +62,7 @@ if raylua.loadfile then return end - print "[RAYLUA] Load main.lua from payload." + print "RAYLUA: Load main.lua from payload." require "main" if not raylua.isrepl then @@ -72,6 +77,6 @@ if arg[1] then end if raylua.isrepl then - print "[RAYLUA] Go to repl." + print "RAYLUA: Go to repl." raylua.repl() end diff --git a/src/raylua_builder.c b/src/raylua_builder.c index b4e232d..a3b7d99 100644 --- a/src/raylua_builder.c +++ b/src/raylua_builder.c @@ -126,7 +126,7 @@ static int raylua_builder_add(lua_State *L) if (!mz_zip_writer_add_file(&builder->zip, dest, path, NULL, 0, MZ_BEST_COMPRESSION)) - printf("Unable to write %s (%s)\n", dest, path); + printf("BUILDER: > Unable to write %s (%s)\n", dest, path); return 0; } diff --git a/src/raylua_builder.lua b/src/raylua_builder.lua index d0e9967..8e15316 100644 --- a/src/raylua_builder.lua +++ b/src/raylua_builder.lua @@ -48,10 +48,8 @@ local append_file_offset = ffi.cast("void (*)(FILE *, FILE *, FILE *)", append_f local self_path = arg[0] local input_path = arg[1] -print ">> Raylua builder <<" +print "BUILDER: Initialized builder" if #arg == 0 then - print "TODO: Improve builder usage." - print "Usage: raylua_e [output]" return end @@ -66,7 +64,7 @@ if ffi.os == "Windows" and self_path:sub("-4") ~= ".exe" then self_path = self_path .. ".exe" end -print("Self is " .. self_path) +print("BUILDER: Self is " .. self_path) if t == "directory" then local output = arg[2] @@ -81,7 +79,7 @@ if t == "directory" then end end - print("Building " .. output) + print("BUILDER: Building " .. output) local builder = builder_new(self_path, output) assert(builder, "Can't initialize builder") @@ -108,13 +106,13 @@ if t == "directory" then local t = get_type(full_file_path) if t == "file" then - print("Adding file " .. partial_file_path) + print("BUILDER: +> " .. partial_file_path) builder_add(builder, full_file_path, partial_file_path) elseif t == "directory" then - print("Adding directory " .. partial_file_path .. "/") + print("BUILDER: /> " .. partial_file_path .. "/") add_dir(root, partial_file_path) else - print("Unknown file type " .. partial_file_path) + print("BUILDER: ?> " .. partial_file_path) end end end @@ -123,7 +121,7 @@ if t == "directory" then add_dir(input_path, nil) if not have_main then - print("WARN: main.lua is missing, your executable may not run") + print("BUILDER: WARN: main.lua is missing, your executable may not run") end builder_close(builder) @@ -139,10 +137,10 @@ elseif t == "file" then path = path .. ".elf" end - print("Building " .. path) + print("BUILDER: Building " .. path) if ext == ".zip" then - print "Build from zip file." + print "BUILDER: Building from zip file." local dest = assert(io.open(path, "wb"), "Can't open destination file.") local source = assert(io.open(self_path, "rb"), "Can't open self file.") @@ -154,7 +152,7 @@ elseif t == "file" then source:close() input:close() elseif ext == ".lua" then - print "Build from lua file." + print "BUILDER: Building from lua file." local builder = builder_new(self_path, path) builder_add(builder, input_path, "main.lua") @@ -162,4 +160,4 @@ elseif t == "file" then end end -print "Done" +print "BUILDER: Done" diff --git a/src/raylua_e.c b/src/raylua_e.c index c0a297a..0fa84a8 100644 --- a/src/raylua_e.c +++ b/src/raylua_e.c @@ -77,7 +77,7 @@ static bool raylua_init_payload(const char *path, bool direct) FILE *f = fopen(path, "rb"); if (f == NULL) { - puts("[RAYLUA] Can't load self."); + puts("RAYLUA: Can't load self."); return false; } else { /* Read offset at the end of the file */ @@ -101,7 +101,7 @@ int main(int argc, const char **argv) luaL_openlibs(L); if (L == NULL) - puts("[RAYLUA] Unable to initialize Lua."); + puts("RAYLUA: Unable to initialize Lua."); /* Populate arg. */ lua_newtable(L); @@ -126,16 +126,16 @@ int main(int argc, const char **argv) strcpy(new_path, path); strcpy(new_path + path_len, ".exe"); - printf("[RAYLUA] Translated self executable name from %s to %s.\n", path, new_path); + printf("RAYLUA: Translated self executable name from %s to %s.\n", path, new_path); path = new_path; } #endif if (!raylua_init_payload(path, false)) { #ifdef RAYLUA_NO_BUILDER - puts("[RAYLUA] No payload."); + puts("RAYLUA: No payload."); #else - puts("[RAYLUA] No payload, use internal builder."); + puts("RAYLUA: No payload, use internal builder."); raylua_builder_boot(L); #endif } else { diff --git a/src/raylua_s.c b/src/raylua_s.c index 1087fd2..2b5f5a9 100644 --- a/src/raylua_s.c +++ b/src/raylua_s.c @@ -30,7 +30,7 @@ int main(int argc, const char **argv) luaL_openlibs(L); if (L == NULL) - puts("[RAYLUA] Unable to initialize Lua."); + puts("RAYLUA: Unable to initialize Lua."); lua_newtable(L);