2019-05-18 00:11:22 +00:00
|
|
|
#include "api/api.h"
|
2020-02-26 22:40:40 +00:00
|
|
|
#include "event/event.h"
|
2019-12-14 03:36:46 +00:00
|
|
|
#include "core/os.h"
|
2022-03-22 07:13:21 +00:00
|
|
|
#include "util.h"
|
2022-03-30 19:13:53 +00:00
|
|
|
#include "boot.lua.h"
|
2021-03-16 00:54:27 +00:00
|
|
|
#include <lua.h>
|
|
|
|
#include <lauxlib.h>
|
2021-02-07 23:51:31 +00:00
|
|
|
#include <lualib.h>
|
2018-09-27 04:55:54 +00:00
|
|
|
#include <stdbool.h>
|
2018-05-15 04:38:50 +00:00
|
|
|
#include <string.h>
|
2018-02-17 17:18:08 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2024-03-27 19:48:35 +00:00
|
|
|
static void run(void* T) {
|
|
|
|
while (luax_resume(T, 0) == LUA_YIELD) {
|
|
|
|
os_sleep(0.);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-08 20:51:22 +00:00
|
|
|
int main(int argc, char** argv) {
|
2023-11-02 20:15:37 +00:00
|
|
|
os_init();
|
2018-02-17 17:18:08 +00:00
|
|
|
|
2023-11-02 20:15:37 +00:00
|
|
|
for (;;) {
|
2018-10-29 20:52:50 +00:00
|
|
|
lua_State* L = luaL_newstate();
|
2019-03-06 16:42:32 +00:00
|
|
|
luax_setmainthread(L);
|
2018-10-29 20:52:50 +00:00
|
|
|
luaL_openlibs(L);
|
2021-03-16 00:54:27 +00:00
|
|
|
luax_preload(L);
|
2018-10-29 20:52:50 +00:00
|
|
|
|
2020-01-29 05:38:44 +00:00
|
|
|
lua_newtable(L);
|
2023-11-02 20:15:37 +00:00
|
|
|
static Variant cookie;
|
2020-02-26 22:40:40 +00:00
|
|
|
luax_pushvariant(L, &cookie);
|
|
|
|
lua_setfield(L, -2, "restart");
|
2020-01-29 05:38:44 +00:00
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
lua_pushstring(L, argv[i]);
|
2023-11-02 20:15:37 +00:00
|
|
|
lua_rawseti(L, -2, i);
|
2020-01-29 05:38:44 +00:00
|
|
|
}
|
|
|
|
lua_setglobal(L, "arg");
|
|
|
|
|
|
|
|
lua_pushcfunction(L, luax_getstack);
|
2022-03-30 19:13:53 +00:00
|
|
|
if (luaL_loadbuffer(L, (const char*) etc_boot_lua, etc_boot_lua_len, "@boot.lua") || lua_pcall(L, 0, 1, -2)) {
|
2020-01-29 05:38:44 +00:00
|
|
|
fprintf(stderr, "%s\n", lua_tostring(L, -1));
|
2023-11-02 20:15:37 +00:00
|
|
|
os_destroy();
|
2018-10-29 20:52:50 +00:00
|
|
|
return 1;
|
2018-04-26 03:07:28 +00:00
|
|
|
}
|
2018-10-29 20:52:50 +00:00
|
|
|
|
2023-11-01 21:38:04 +00:00
|
|
|
lua_State* T = lua_tothread(L, -1);
|
lovr.log;
lovr.log is a new callback that is invoked whenever LÖVR wants to
send the project a message. For example, this could be a performance
warning from the graphics module, an error message from one of the
headset backends, or an API deprecation notice.
The callback's signature is (message, level, tag). The message is a
string containing the message to log, level is a string that is currently
one of "debug", "info", "warn", "error", and tag is an optional string
that is used to indicate the source of the message for grouping purposes.
The default implementation of the callback just prints the message,
but the callback can be overridden to do things like filter messages,
write them to a file, or even render them in VR. Projects can also
invoke the callback directly to log their own messages.
2020-07-06 22:20:55 +00:00
|
|
|
lovrSetLogCallback(luax_vlog, T);
|
2024-03-27 19:48:35 +00:00
|
|
|
lovrTry(run, T, luax_vthrow, T);
|
2018-10-29 20:52:50 +00:00
|
|
|
|
2023-11-02 20:15:37 +00:00
|
|
|
if (lua_type(T, 1) == LUA_TSTRING && !strcmp(lua_tostring(T, 1), "restart")) {
|
|
|
|
luax_checkvariant(T, 2, &cookie);
|
|
|
|
if (cookie.type == TYPE_OBJECT) memset(&cookie, 0, sizeof(cookie));
|
|
|
|
lua_close(L);
|
|
|
|
continue;
|
2020-12-25 19:18:57 +00:00
|
|
|
} else {
|
2023-11-02 20:15:37 +00:00
|
|
|
int status = lua_tointeger(T, 1);
|
|
|
|
lua_close(L);
|
2021-02-25 16:00:12 +00:00
|
|
|
os_destroy();
|
2023-11-02 20:15:37 +00:00
|
|
|
return status;
|
2020-12-25 19:18:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|