From 7f965cc2451e5bfcf60b2b9f9ee744828822a516 Mon Sep 17 00:00:00 2001 From: rxi Date: Thu, 29 Sep 2016 20:36:16 +0100 Subject: [PATCH] Added storing of argv to love.argv, added `args` arg to love.load() --- src/embed/boot.lua | 8 +++++++- src/main.c | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/embed/boot.lua b/src/embed/boot.lua index 835785b..b7b5b9c 100644 --- a/src/embed/boot.lua +++ b/src/embed/boot.lua @@ -1,6 +1,12 @@ function love.run() - if love.load then love.load() end + -- Prepare arguments + local args = {} + for i = 2, #love.argv do + args[i - 1] = love.argv[i] + end + -- Do load callback + if love.load then love.load(args) end love.timer.step() while true do -- Handle mouse events diff --git a/src/main.c b/src/main.c index e260f1c..e80b47f 100644 --- a/src/main.c +++ b/src/main.c @@ -43,7 +43,7 @@ static int onLuaPanic(lua_State *L) { int luaopen_love(lua_State *L); -int main(void) { +int main(int argc, char **argv) { /* Init everything */ atexit(deinit); @@ -59,6 +59,20 @@ int main(void) { luaL_openlibs(L); luaL_requiref(L, "love", luaopen_love, 1); + /* Create `love.argv` and fill with arguments */ + lua_getglobal(L, "love"); + if (!lua_isnil(L, -1)) { + lua_newtable(L); + int i; + for (i = 0; i < argc; i++) { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i + 1); + } + lua_setfield(L, -2, "argv"); + } + lua_pop(L, 1); + + /* Init embedded scripts */ #include "boot_lua.h" int err = luaL_loadbuffer(L, boot_lua, sizeof(boot_lua) - 1, "boot.lua");