From 44a4b94d97125bed5168d030ff6b01f4719fd8ce Mon Sep 17 00:00:00 2001 From: TSnake41 Date: Wed, 19 Aug 2020 16:58:45 +0200 Subject: [PATCH] Some improvements and fixes for raylua.dll/raylua.so. --- makefile | 2 +- src/raylib.lua | 4 +++- src/raylua.c | 8 ++++++-- src/raylua.h | 3 ++- src/raylua.lua | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/makefile b/makefile index 0a72e74..4fab86f 100644 --- a/makefile +++ b/makefile @@ -49,7 +49,7 @@ libraylua.a: src/raylua.o $(AR) rcu $@ $^ raylua.dll: src/raylua.o - $(CC) -shared -fPIE -o $@ $^ $(LDFLAGS) + $(CC) -shared -fPIE -o $@ $^ $(LDFLAGS) -llua5.1 raylua.so: src/raylua.o $(CC) -shared -fPIE -o $@ $^ $(LDFLAGS) diff --git a/src/raylib.lua b/src/raylib.lua index ff09fb2..ae3ed33 100644 --- a/src/raylib.lua +++ b/src/raylib.lua @@ -24,7 +24,7 @@ end local ffi = require "ffi" local C = ffi.C -rl = {} +local rl = {} setmetatable(rl, rl) -- structs definition @@ -894,3 +894,5 @@ end rl.__newindex = function () error "rl table is readonly" end + +_G.rl = rl diff --git a/src/raylua.c b/src/raylua.c index cb75cea..d7a07ee 100644 --- a/src/raylua.c +++ b/src/raylua.c @@ -39,7 +39,8 @@ extern const char *raylua_boot_str; -void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles, bool repl) +void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles, + bool repl) { lua_newtable(L); @@ -72,5 +73,8 @@ void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles, int luaopen_raylua(lua_State *L) { raylua_boot(L, NULL, NULL, false); - return 0; + + lua_getglobal(L, "rl"); + lua_getglobal(L, "raylua"); + return 2; } diff --git a/src/raylua.h b/src/raylua.h index 1ab1a53..60e9ede 100644 --- a/src/raylua.h +++ b/src/raylua.h @@ -20,7 +20,8 @@ #include #include -void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles, bool repl); +void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles, + bool repl); /* raylua_boot alias to allow direct loading */ int luaopen_raylua(lua_State *L); diff --git a/src/raylua.lua b/src/raylua.lua index 559694b..7bb92cc 100644 --- a/src/raylua.lua +++ b/src/raylua.lua @@ -73,7 +73,7 @@ if raylua.loadfile then end end -if arg[1] then +if arg and arg[1] then dofile(arg[1]) return end