mirror of https://github.com/bjornbytes/lovr.git
luax is now api;
This commit is contained in:
parent
7c8a44cc57
commit
8d4760167f
|
@ -317,12 +317,12 @@ endif()
|
|||
set(LOVR_SRC
|
||||
src/main.c
|
||||
src/core/arr.c
|
||||
src/core/luax.c
|
||||
src/core/maf.c
|
||||
src/core/platform.c
|
||||
src/core/ref.c
|
||||
src/core/utf.c
|
||||
src/core/util.c
|
||||
src/api/api.c
|
||||
src/api/l_lovr.c
|
||||
src/lib/map/map.c
|
||||
src/lib/sds/sds.c
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "luax.h"
|
||||
#include "core/ref.h"
|
||||
#include "platform.h"
|
||||
#include "api.h"
|
||||
#include "util.h"
|
||||
#include "core/ref.h"
|
||||
#include "core/platform.h"
|
||||
#include "lib/sds/sds.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
|
@ -1,18 +1,22 @@
|
|||
#include "luax.h"
|
||||
#include "util.h"
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
// Modules
|
||||
LOVR_EXPORT int luaopen_lovr(lua_State* L);
|
||||
LOVR_EXPORT int luaopen_lovr_audio(lua_State* L);
|
||||
LOVR_EXPORT int luaopen_lovr_data(lua_State* L);
|
||||
LOVR_EXPORT int luaopen_lovr_event(lua_State* L);
|
||||
LOVR_EXPORT int luaopen_lovr_filesystem(lua_State* L);
|
||||
LOVR_EXPORT int luaopen_lovr_graphics(lua_State* L);
|
||||
LOVR_EXPORT int luaopen_lovr_headset(lua_State* L);
|
||||
LOVR_EXPORT int luaopen_lovr_math(lua_State* L);
|
||||
LOVR_EXPORT int luaopen_lovr_physics(lua_State* L);
|
||||
LOVR_EXPORT int luaopen_lovr_thread(lua_State* L);
|
||||
LOVR_EXPORT int luaopen_lovr_timer(lua_State* L);
|
||||
int luaopen_lovr(lua_State* L);
|
||||
int luaopen_lovr_audio(lua_State* L);
|
||||
int luaopen_lovr_data(lua_State* L);
|
||||
int luaopen_lovr_event(lua_State* L);
|
||||
int luaopen_lovr_filesystem(lua_State* L);
|
||||
int luaopen_lovr_graphics(lua_State* L);
|
||||
int luaopen_lovr_headset(lua_State* L);
|
||||
int luaopen_lovr_math(lua_State* L);
|
||||
int luaopen_lovr_physics(lua_State* L);
|
||||
int luaopen_lovr_thread(lua_State* L);
|
||||
int luaopen_lovr_timer(lua_State* L);
|
||||
extern const luaL_Reg lovrModules[];
|
||||
|
||||
// Objects
|
||||
|
@ -86,7 +90,54 @@ extern const char* VerticalAligns[];
|
|||
extern const char* Windings[];
|
||||
extern const char* WrapModes[];
|
||||
|
||||
// Helpers
|
||||
// General helpers
|
||||
|
||||
struct Color;
|
||||
|
||||
typedef struct {
|
||||
uint32_t hash;
|
||||
void* object;
|
||||
} Proxy;
|
||||
|
||||
static inline uint32_t hash(const char* str) {
|
||||
uint32_t x = 0;
|
||||
while (*str) {
|
||||
x = (x * 65599) + *str++;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
#ifndef LUA_RIDX_MAINTHERAD
|
||||
#define LUA_RIDX_MAINTHREAD 1
|
||||
#endif
|
||||
|
||||
#define luax_len(L, i) (int) lua_objlen(L, i)
|
||||
#define luax_registertype(L, T) _luax_registertype(L, #T, lovr ## T, lovr ## T ## Destroy)
|
||||
#define luax_totype(L, i, T) (T*) _luax_totype(L, i, hash(#T))
|
||||
#define luax_checktype(L, i, T) (T*) _luax_checktype(L, i, hash(#T), #T)
|
||||
#define luax_pushtype(L, T, o) _luax_pushtype(L, #T, hash(#T), o)
|
||||
#define luax_checkfloat(L, i) (float) luaL_checknumber(L, i)
|
||||
#define luax_optfloat(L, i, x) (float) luaL_optnumber(L, i, x)
|
||||
#define luax_geterror(L) lua_getfield(L, LUA_REGISTRYINDEX, "_lovrerror")
|
||||
#define luax_seterror(L) lua_setfield(L, LUA_REGISTRYINDEX, "_lovrerror")
|
||||
#define luax_clearerror(L) lua_pushnil(L), luax_seterror(L)
|
||||
|
||||
void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions, void (*destructor)(void*));
|
||||
void* _luax_totype(lua_State* L, int index, uint32_t hash);
|
||||
void* _luax_checktype(lua_State* L, int index, uint32_t hash, const char* debug);
|
||||
void _luax_pushtype(lua_State* L, const char* name, uint32_t hash, void* object);
|
||||
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_traceback(lua_State* L, lua_State* T, const char* message, int level);
|
||||
int luax_getstack(lua_State* L);
|
||||
int luax_print(lua_State* L);
|
||||
void luax_pushconf(lua_State* L);
|
||||
int luax_setconf(lua_State* L);
|
||||
void luax_setmainthread(lua_State* L);
|
||||
void luax_atexit(lua_State* L, void (*destructor)(void));
|
||||
void luax_readcolor(lua_State* L, int index, struct Color* color);
|
||||
|
||||
// Module helpers
|
||||
|
||||
#ifdef LOVR_ENABLE_DATA
|
||||
struct Blob;
|
||||
|
@ -109,7 +160,6 @@ void luax_readattachments(lua_State* L, int index, struct Attachment* attachment
|
|||
#endif
|
||||
|
||||
#ifdef LOVR_ENABLE_MATH
|
||||
#include <stdint.h>
|
||||
#include "math/pool.h" // TODO
|
||||
#include "math/randomGenerator.h" // TODO
|
||||
float* luax_tovector(lua_State* L, int index, VectorType* type);
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
#include "core/ref.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct Blob* luax_readblob(lua_State* L, int index, const char* debug);
|
||||
|
||||
const char* SourceTypes[] = {
|
||||
[SOURCE_STATIC] = "static",
|
||||
[SOURCE_STREAM] = "stream",
|
||||
|
@ -251,7 +249,7 @@ static const luaL_Reg lovrAudio[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_lovr_audio(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr_audio(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovrAudio);
|
||||
luax_registertype(L, Microphone);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "api.h"
|
||||
#include "util.h"
|
||||
#include "math/curve.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ static const luaL_Reg lovrData[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_lovr_data(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr_data(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovrData);
|
||||
luax_registertype(L, Blob);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "api.h"
|
||||
#include "util.h"
|
||||
#include "event/event.h"
|
||||
#include "thread/thread.h"
|
||||
#include "core/platform.h"
|
||||
|
@ -195,7 +196,7 @@ static const luaL_Reg lovrEvent[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_lovr_event(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr_event(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovrEvent);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "api.h"
|
||||
#include "util.h"
|
||||
#include "filesystem/filesystem.h"
|
||||
#include "filesystem/file.h"
|
||||
#include "data/blob.h"
|
||||
|
@ -443,7 +444,7 @@ static int libLoader(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int luaopen_lovr_filesystem(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr_filesystem(lua_State* L) {
|
||||
lua_getglobal(L, "arg");
|
||||
if (lua_istable(L, -1)) {
|
||||
lua_getfield(L, -1, "exe");
|
||||
|
|
|
@ -1689,7 +1689,7 @@ static const luaL_Reg lovrGraphics[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_lovr_graphics(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr_graphics(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovrGraphics);
|
||||
luax_registertype(L, Canvas);
|
||||
|
|
|
@ -592,7 +592,7 @@ static const luaL_Reg lovrHeadset[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_lovr_headset(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr_headset(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovrHeadset);
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ static const luaL_Reg lovr[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_lovr(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovr);
|
||||
return 1;
|
||||
|
|
|
@ -343,7 +343,7 @@ static int l_lovrLightUserdataOp(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int luaopen_lovr_math(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr_math(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovrMath);
|
||||
luax_registertype(L, Curve);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "api.h"
|
||||
#include "util.h"
|
||||
#include "physics/physics.h"
|
||||
#include "core/ref.h"
|
||||
|
||||
|
@ -148,7 +149,7 @@ static const luaL_Reg lovrPhysics[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_lovr_physics(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr_physics(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovrPhysics);
|
||||
luax_registertype(L, World);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "api.h"
|
||||
#include "util.h"
|
||||
#include "event/event.h"
|
||||
#include "filesystem/filesystem.h"
|
||||
#include "thread/thread.h"
|
||||
|
@ -89,7 +90,7 @@ static const luaL_Reg lovrThreadModule[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_lovr_thread(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr_thread(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovrThreadModule);
|
||||
luax_registertype(L, Thread);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "api.h"
|
||||
#include "util.h"
|
||||
#include "timer/timer.h"
|
||||
|
||||
static int l_lovrTimerGetDelta(lua_State* L) {
|
||||
|
@ -42,7 +43,7 @@ static const luaL_Reg lovrTimer[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_lovr_timer(lua_State* L) {
|
||||
LOVR_EXPORT int luaopen_lovr_timer(lua_State* L) {
|
||||
lua_newtable(L);
|
||||
luaL_register(L, NULL, lovrTimer);
|
||||
if (lovrTimerInit()) {
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
struct Color;
|
||||
|
||||
typedef struct {
|
||||
uint32_t hash;
|
||||
void* object;
|
||||
} Proxy;
|
||||
|
||||
#ifndef LUA_RIDX_MAINTHERAD
|
||||
#define LUA_RIDX_MAINTHREAD 1
|
||||
#endif
|
||||
|
||||
#define luax_len(L, i) (int) lua_objlen(L, i)
|
||||
#define luax_registertype(L, T) _luax_registertype(L, #T, lovr ## T, lovr ## T ## Destroy)
|
||||
#define luax_totype(L, i, T) (T*) _luax_totype(L, i, hash(#T))
|
||||
#define luax_checktype(L, i, T) (T*) _luax_checktype(L, i, hash(#T), #T)
|
||||
#define luax_pushtype(L, T, o) _luax_pushtype(L, #T, hash(#T), o)
|
||||
#define luax_checkfloat(L, i) (float) luaL_checknumber(L, i)
|
||||
#define luax_optfloat(L, i, x) (float) luaL_optnumber(L, i, x)
|
||||
#define luax_geterror(L) lua_getfield(L, LUA_REGISTRYINDEX, "_lovrerror")
|
||||
#define luax_seterror(L) lua_setfield(L, LUA_REGISTRYINDEX, "_lovrerror")
|
||||
#define luax_clearerror(L) lua_pushnil(L), luax_seterror(L)
|
||||
|
||||
void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions, void (*destructor)(void*));
|
||||
void* _luax_totype(lua_State* L, int index, uint32_t hash);
|
||||
void* _luax_checktype(lua_State* L, int index, uint32_t hash, const char* debug);
|
||||
void _luax_pushtype(lua_State* L, const char* name, uint32_t hash, void* object);
|
||||
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_traceback(lua_State* L, lua_State* T, const char* message, int level);
|
||||
int luax_getstack(lua_State* L);
|
||||
int luax_print(lua_State* L);
|
||||
void luax_pushconf(lua_State* L);
|
||||
int luax_setconf(lua_State* L);
|
||||
void luax_setmainthread(lua_State* L);
|
||||
void luax_atexit(lua_State* L, void (*destructor)(void));
|
||||
void luax_readcolor(lua_State* L, int index, struct Color* color);
|
|
@ -1,6 +1,5 @@
|
|||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -44,11 +43,3 @@ void lovrSetErrorCallback(errorFn* callback, void* context);
|
|||
void LOVR_NORETURN lovrThrow(const char* format, ...);
|
||||
|
||||
#define lovrAssert(c, ...) if (!(c)) { lovrThrow(__VA_ARGS__); }
|
||||
|
||||
static inline uint32_t hash(const char* str) {
|
||||
uint32_t x = 0;
|
||||
while (*str) {
|
||||
x = (x * 65599) + *str++;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "luax.h"
|
||||
#include "api/api.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "luax.h"
|
||||
#include "api/api.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "resources/boot.lua.h"
|
||||
#include "api/api.h"
|
||||
#include "luax.h"
|
||||
#include "platform.h"
|
||||
#include "util.h"
|
||||
#include <stdbool.h>
|
||||
|
|
|
@ -297,7 +297,6 @@ bool lovrPlatformHasWindow() {
|
|||
#include <assert.h>
|
||||
|
||||
#include "oculus_mobile_bridge.h"
|
||||
#include "luax.h"
|
||||
#include "lib/sds/sds.h"
|
||||
|
||||
#include "api/api.h"
|
||||
|
|
Loading…
Reference in New Issue