mirror of https://github.com/bjornbytes/lovr.git
Simplify logging;
This commit is contained in:
parent
fb2d8aae2c
commit
13655d0df4
|
@ -194,27 +194,6 @@ int luax_getstack(lua_State *L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A version of print that uses lovrLog, for platforms that need it (Android)
|
|
||||||
int luax_print(lua_State* L) {
|
|
||||||
luaL_Buffer buffer;
|
|
||||||
int n = lua_gettop(L);
|
|
||||||
lua_getglobal(L, "tostring");
|
|
||||||
luaL_buffinit(L, &buffer);
|
|
||||||
for (int i = 1; i <= n; i++) {
|
|
||||||
lua_pushvalue(L, -1);
|
|
||||||
lua_pushvalue(L, i);
|
|
||||||
lua_call(L, 1, 1);
|
|
||||||
lovrAssert(lua_type(L, -1) == LUA_TSTRING, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
|
|
||||||
luaL_addvalue(&buffer);
|
|
||||||
if (i > 1) {
|
|
||||||
luaL_addchar(&buffer, '\t');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
luaL_pushresult(&buffer);
|
|
||||||
lovrLog("%s", lua_tostring(L, -1));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void luax_pushconf(lua_State* L) {
|
void luax_pushconf(lua_State* L) {
|
||||||
lua_getfield(L, LUA_REGISTRYINDEX, "_lovrconf");
|
lua_getfield(L, LUA_REGISTRYINDEX, "_lovrconf");
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,6 @@ void luax_registerloader(lua_State* L, lua_CFunction loader, int index);
|
||||||
void luax_vthrow(lua_State* L, const char* format, va_list args);
|
void luax_vthrow(lua_State* L, const char* format, va_list args);
|
||||||
void luax_traceback(lua_State* L, lua_State* T, const char* message, int level);
|
void luax_traceback(lua_State* L, lua_State* T, const char* message, int level);
|
||||||
int luax_getstack(lua_State* L);
|
int luax_getstack(lua_State* L);
|
||||||
int luax_print(lua_State* L);
|
|
||||||
void luax_pushconf(lua_State* L);
|
void luax_pushconf(lua_State* L);
|
||||||
int luax_setconf(lua_State* L);
|
int luax_setconf(lua_State* L);
|
||||||
void luax_setmainthread(lua_State* L);
|
void luax_setmainthread(lua_State* L);
|
||||||
|
|
|
@ -3,20 +3,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
#include <android/log.h>
|
|
||||||
#define lovrLog(...) __android_log_print(ANDROID_LOG_DEBUG, "LOVR", __VA_ARGS__)
|
|
||||||
#define lovrLogv(...) __android_log_vprint(ANDROID_LOG_DEBUG, "LOVR", __VA_ARGS__)
|
|
||||||
#define lovrWarn(...) __android_log_print(ANDROID_LOG_WARN, "LOVR", __VA_ARGS__)
|
|
||||||
#define lovrWarnv(...) __android_log_vprint(ANDROID_LOG_WARN, "LOVR", __VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#include <stdio.h>
|
|
||||||
#define lovrLog(...) printf(__VA_ARGS__)
|
|
||||||
#define lovrLogv(...) vprintf(__VA_ARGS__)
|
|
||||||
#define lovrWarn(...) fprintf(stderr, __VA_ARGS__)
|
|
||||||
#define lovrWarnv(...) vfprintf(stderr, __VA_ARGS__)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
|
|
|
@ -1,29 +1,25 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "platform.h"
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
LOVR_THREAD_LOCAL errorFn* lovrErrorCallback = NULL;
|
static void defaultErrorCallback(void* p, const char* format, va_list args) {
|
||||||
|
fprintf(stderr, "Error: ");
|
||||||
|
vfprintf(stderr, format, args);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
LOVR_THREAD_LOCAL errorFn* lovrErrorCallback = defaultErrorCallback;
|
||||||
LOVR_THREAD_LOCAL void* lovrErrorUserdata = NULL;
|
LOVR_THREAD_LOCAL void* lovrErrorUserdata = NULL;
|
||||||
|
|
||||||
void lovrSetErrorCallback(errorFn* callback, void* userdata) {
|
void lovrSetErrorCallback(errorFn* callback, void* userdata) {
|
||||||
lovrErrorCallback = callback;
|
lovrErrorCallback = callback ? callback : defaultErrorCallback;
|
||||||
lovrErrorUserdata = userdata;
|
lovrErrorUserdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrThrow(const char* format, ...) {
|
void lovrThrow(const char* format, ...) {
|
||||||
if (lovrErrorCallback) {
|
va_list args;
|
||||||
va_list args;
|
va_start(args, format);
|
||||||
va_start(args, format);
|
lovrErrorCallback(lovrErrorUserdata, format, args);
|
||||||
lovrErrorCallback(lovrErrorUserdata, format, args);
|
va_end(args);
|
||||||
va_end(args);
|
exit(EXIT_FAILURE);
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
} else {
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
lovrWarn("Error: ");
|
|
||||||
lovrWarnv(format, args);
|
|
||||||
lovrWarn("\n");
|
|
||||||
va_end(args);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ static void emscriptenLoop(void* arg) {
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
if (argc > 1 && (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-v"))) {
|
if (argc > 1 && (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-v"))) {
|
||||||
lovrPlatformOpenConsole();
|
lovrPlatformOpenConsole();
|
||||||
lovrLog("LOVR %d.%d.%d (%s)\n", LOVR_VERSION_MAJOR, LOVR_VERSION_MINOR, LOVR_VERSION_PATCH, LOVR_VERSION_ALIAS);
|
printf("LOVR %d.%d.%d (%s)\n", LOVR_VERSION_MAJOR, LOVR_VERSION_MINOR, LOVR_VERSION_PATCH, LOVR_VERSION_ALIAS);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ lua_State* lovrInit(lua_State* L, int argc, char** argv) {
|
||||||
|
|
||||||
lua_pushcfunction(L, luax_getstack);
|
lua_pushcfunction(L, luax_getstack);
|
||||||
if (luaL_loadbuffer(L, (const char*) boot_lua, boot_lua_len, "boot.lua") || lua_pcall(L, 0, 1, -2)) {
|
if (luaL_loadbuffer(L, (const char*) boot_lua, boot_lua_len, "boot.lua") || lua_pcall(L, 0, 1, -2)) {
|
||||||
lovrWarn("%s\n", lua_tostring(L, -1));
|
fprintf(stderr, "%s\n", lua_tostring(L, -1));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "resources/shaders.h"
|
#include "resources/shaders.h"
|
||||||
#include "core/ref.h"
|
#include "core/ref.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
static size_t getUniformTypeLength(const Uniform* uniform) {
|
static size_t getUniformTypeLength(const Uniform* uniform) {
|
||||||
|
|
|
@ -6,8 +6,12 @@
|
||||||
#include "lib/glad/glad.h"
|
#include "lib/glad/glad.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <android/log.h>
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
|
#define LOG(...) __android_log_print(ANDROID_LOG_DEBUG, "LOVR", __VA_ARGS__)
|
||||||
|
#define WARN(...) __android_log_print(ANDROID_LOG_WARN, "LOVR", __VA_ARGS__)
|
||||||
|
|
||||||
// Data passed from bridge code to headset code
|
// Data passed from bridge code to headset code
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
|
@ -328,13 +332,32 @@ enum {
|
||||||
PAUSESTATE_RESUME // We have resumed, and the next frame will need to adjust the clock
|
PAUSESTATE_RESUME // We have resumed, and the next frame will need to adjust the clock
|
||||||
} pauseState;
|
} pauseState;
|
||||||
|
|
||||||
int lovr_luaB_print_override (lua_State *L);
|
// A version of print that uses LOG, since stdout does not work on Android
|
||||||
|
int luax_print(lua_State* L) {
|
||||||
|
luaL_Buffer buffer;
|
||||||
|
int n = lua_gettop(L);
|
||||||
|
lua_getglobal(L, "tostring");
|
||||||
|
luaL_buffinit(L, &buffer);
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
lua_pushvalue(L, -1);
|
||||||
|
lua_pushvalue(L, i);
|
||||||
|
lua_call(L, 1, 1);
|
||||||
|
lovrAssert(lua_type(L, -1) == LUA_TSTRING, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
|
||||||
|
luaL_addvalue(&buffer);
|
||||||
|
if (i > 1) {
|
||||||
|
luaL_addchar(&buffer, '\t');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
luaL_pushresult(&buffer);
|
||||||
|
LOG("%s", lua_tostring(L, -1));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void android_vthrow(lua_State* L, const char* format, va_list args) {
|
static void android_vthrow(lua_State* L, const char* format, va_list args) {
|
||||||
#define MAX_ERROR_LENGTH 1024
|
#define MAX_ERROR_LENGTH 1024
|
||||||
char lovrErrorMessage[MAX_ERROR_LENGTH];
|
char lovrErrorMessage[MAX_ERROR_LENGTH];
|
||||||
vsnprintf(lovrErrorMessage, MAX_ERROR_LENGTH, format, args);
|
vsnprintf(lovrErrorMessage, MAX_ERROR_LENGTH, format, args);
|
||||||
lovrWarn("Error: %s\n", lovrErrorMessage);
|
WARN("Error: %s\n", lovrErrorMessage);
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +376,7 @@ static void bridgeLovrInitState() {
|
||||||
luax_setmainthread(L);
|
luax_setmainthread(L);
|
||||||
lua_atpanic(L, luax_custom_atpanic);
|
lua_atpanic(L, luax_custom_atpanic);
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
lovrLog("\n OPENED LIB\n");
|
LOG("\n OPENED LIB\n");
|
||||||
|
|
||||||
lovrSetErrorCallback((errorFn*) android_vthrow, L);
|
lovrSetErrorCallback((errorFn*) android_vthrow, L);
|
||||||
|
|
||||||
|
@ -395,7 +418,7 @@ static void bridgeLovrInitState() {
|
||||||
|
|
||||||
lua_pushcfunction(L, luax_getstack);
|
lua_pushcfunction(L, luax_getstack);
|
||||||
if (luaL_loadbuffer(L, (const char*) boot_lua, boot_lua_len, "boot.lua") || lua_pcall(L, 0, 1, -2)) {
|
if (luaL_loadbuffer(L, (const char*) boot_lua, boot_lua_len, "boot.lua") || lua_pcall(L, 0, 1, -2)) {
|
||||||
lovrWarn("\n LUA STARTUP FAILED: %s\n", lua_tostring(L, -1));
|
WARN("\n LUA STARTUP FAILED: %s\n", lua_tostring(L, -1));
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
@ -405,11 +428,11 @@ static void bridgeLovrInitState() {
|
||||||
lua_atpanic(T, luax_custom_atpanic);
|
lua_atpanic(T, luax_custom_atpanic);
|
||||||
coroutineRef = luaL_ref(L, LUA_REGISTRYINDEX); // Hold on to the Lua-side coroutine object so it isn't GC'd
|
coroutineRef = luaL_ref(L, LUA_REGISTRYINDEX); // Hold on to the Lua-side coroutine object so it isn't GC'd
|
||||||
|
|
||||||
lovrLog("\n STATE INIT COMPLETE\n");
|
LOG("\n STATE INIT COMPLETE\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void bridgeLovrInit(BridgeLovrInitData *initData) {
|
void bridgeLovrInit(BridgeLovrInitData *initData) {
|
||||||
lovrLog("\n INSIDE LOVR\n");
|
LOG("\n INSIDE LOVR\n");
|
||||||
|
|
||||||
// Save writable data directory for LovrFilesystemInit later
|
// Save writable data directory for LovrFilesystemInit later
|
||||||
{
|
{
|
||||||
|
@ -433,7 +456,7 @@ void bridgeLovrInit(BridgeLovrInitData *initData) {
|
||||||
|
|
||||||
bridgeLovrInitState();
|
bridgeLovrInitState();
|
||||||
|
|
||||||
lovrLog("\n BRIDGE INIT COMPLETE\n");
|
LOG("\n BRIDGE INIT COMPLETE\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void bridgeLovrUpdate(BridgeLovrUpdateData *updateData) {
|
void bridgeLovrUpdate(BridgeLovrUpdateData *updateData) {
|
||||||
|
@ -464,7 +487,7 @@ void bridgeLovrUpdate(BridgeLovrUpdateData *updateData) {
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
bridgeLovrInitState();
|
bridgeLovrInitState();
|
||||||
} else {
|
} else {
|
||||||
lovrLog("\n LUA REQUESTED A QUIT\n");
|
LOG("\n LUA REQUESTED A QUIT\n");
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue