Flatten api.h;

This commit is contained in:
bjorn 2021-03-15 18:54:27 -06:00
parent f9f4907a50
commit e63099ba6a
38 changed files with 220 additions and 144 deletions

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "core/os.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
@ -8,6 +10,25 @@
typedef void voidFn(void);
typedef void destructorFn(void*);
#ifdef _WIN32
#define LOVR_EXPORT __declspec(dllexport)
#else
#define LOVR_EXPORT __attribute__((visibility("default")))
#endif
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_system(lua_State* L);
LOVR_EXPORT int luaopen_lovr_thread(lua_State* L);
LOVR_EXPORT int luaopen_lovr_timer(lua_State* L);
// Object names are lightuserdata because Variants need a non-Lua string due to threads.
static int luax_meta__tostring(lua_State* L) {
lua_getfield(L, -1, "__info");
@ -41,6 +62,51 @@ static int luax_module__gc(lua_State* L) {
return 0;
}
void luax_preload(lua_State* L) {
static const luaL_Reg lovrModules[] = {
{ "lovr", luaopen_lovr },
#ifndef LOVR_DISABLE_AUDIO
{ "lovr.audio", luaopen_lovr_audio },
#endif
#ifndef LOVR_DISABLE_DATA
{ "lovr.data", luaopen_lovr_data },
#endif
#ifndef LOVR_DISABLE_EVENT
{ "lovr.event", luaopen_lovr_event },
#endif
#ifndef LOVR_DISABLE_FILESYSTEM
{ "lovr.filesystem", luaopen_lovr_filesystem },
#endif
#ifndef LOVR_DISABLE_GRAPHICS
{ "lovr.graphics", luaopen_lovr_graphics },
#endif
#ifndef LOVR_DISABLE_HEADSET
{ "lovr.headset", luaopen_lovr_headset },
#endif
#ifndef LOVR_DISABLE_MATH
{ "lovr.math", luaopen_lovr_math },
#endif
#ifndef LOVR_DISABLE_PHYSICS
{ "lovr.physics", luaopen_lovr_physics },
#endif
#ifndef LOVR_DISABLE_SYSTEM
{ "lovr.system", luaopen_lovr_system },
#endif
#ifndef LOVR_DISABLE_THREAD
{ "lovr.thread", luaopen_lovr_thread },
#endif
#ifndef LOVR_DISABLE_TIMER
{ "lovr.timer", luaopen_lovr_timer },
#endif
{ NULL, NULL }
};
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
luax_register(L, lovrModules);
lua_pop(L, 2);
}
void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions, destructorFn* destructor) {
// Push metatable

View File

@ -1,70 +1,14 @@
#include <lua.h>
#include <lauxlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
#include <stddef.h>
#pragma once
struct lua_State;
struct luaL_Reg;
struct Color;
#ifdef _WIN32
#define LOVR_EXPORT __declspec(dllexport)
#else
#define LOVR_EXPORT __attribute__((visibility("default")))
#endif
// 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_system(lua_State* L);
LOVR_EXPORT int luaopen_lovr_thread(lua_State* L);
LOVR_EXPORT int luaopen_lovr_timer(lua_State* L);
extern const luaL_Reg lovrModules[];
// Objects
extern const luaL_Reg lovrBallJoint[];
extern const luaL_Reg lovrBlob[];
extern const luaL_Reg lovrBoxShape[];
extern const luaL_Reg lovrCanvas[];
extern const luaL_Reg lovrCapsuleShape[];
extern const luaL_Reg lovrChannel[];
extern const luaL_Reg lovrCollider[];
extern const luaL_Reg lovrCurve[];
extern const luaL_Reg lovrCylinderShape[];
extern const luaL_Reg lovrDistanceJoint[];
extern const luaL_Reg lovrFont[];
extern const luaL_Reg lovrHingeJoint[];
extern const luaL_Reg lovrImage[];
extern const luaL_Reg lovrMat4[];
extern const luaL_Reg lovrMaterial[];
extern const luaL_Reg lovrMesh[];
extern const luaL_Reg lovrMicrophone[];
extern const luaL_Reg lovrModel[];
extern const luaL_Reg lovrModelData[];
extern const luaL_Reg lovrQuat[];
extern const luaL_Reg lovrRandomGenerator[];
extern const luaL_Reg lovrRasterizer[];
extern const luaL_Reg lovrShader[];
extern const luaL_Reg lovrShaderBlock[];
extern const luaL_Reg lovrSliderJoint[];
extern const luaL_Reg lovrSound[];
extern const luaL_Reg lovrSource[];
extern const luaL_Reg lovrSphereShape[];
extern const luaL_Reg lovrMeshShape[];
extern const luaL_Reg lovrTexture[];
extern const luaL_Reg lovrThread[];
extern const luaL_Reg lovrVec2[];
extern const luaL_Reg lovrVec4[];
extern const luaL_Reg lovrVec3[];
extern const luaL_Reg lovrWorld[];
// Enums
typedef struct {
uint8_t length;
@ -148,36 +92,37 @@ typedef struct {
#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, uint64_t hash);
void* _luax_checktype(lua_State* L, int index, uint64_t hash, const char* debug);
int luax_typeerror(lua_State* L, int index, const char* expected);
void _luax_pushtype(lua_State* L, const char* name, uint64_t hash, void* object);
int _luax_checkenum(lua_State* L, int index, const StringEntry* map, const char* fallback, const char* label);
void luax_registerloader(lua_State* L, lua_CFunction loader, int index);
int luax_resume(lua_State* T, int n);
void luax_preload(struct lua_State* L);
void _luax_registertype(struct lua_State* L, const char* name, const struct luaL_Reg* functions, void (*destructor)(void*));
void* _luax_totype(struct lua_State* L, int index, uint64_t hash);
void* _luax_checktype(struct lua_State* L, int index, uint64_t hash, const char* debug);
int luax_typeerror(struct lua_State* L, int index, const char* expected);
void _luax_pushtype(struct lua_State* L, const char* name, uint64_t hash, void* object);
int _luax_checkenum(struct lua_State* L, int index, const StringEntry* map, const char* fallback, const char* label);
void luax_registerloader(struct lua_State* L, int (*loader)(struct lua_State* L), int index);
int luax_resume(struct lua_State* T, int n);
void luax_vthrow(void* L, const char* format, va_list args);
void luax_vlog(void* context, int level, const char* tag, 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);
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);
int luax_readtriangles(lua_State* L, int index, float** vertices, uint32_t* vertexCount, uint32_t** indices, uint32_t* indexCount, bool* shouldFree);
void luax_traceback(struct lua_State* L, struct lua_State* T, const char* message, int level);
int luax_getstack(struct lua_State* L);
void luax_pushconf(struct lua_State* L);
int luax_setconf(struct lua_State* L);
void luax_setmainthread(struct lua_State* L);
void luax_atexit(struct lua_State* L, void (*destructor)(void));
void luax_readcolor(struct lua_State* L, int index, struct Color* color);
int luax_readtriangles(struct lua_State* L, int index, float** vertices, uint32_t* vertexCount, uint32_t** indices, uint32_t* indexCount, bool* shouldFree);
// Module helpers
#ifndef LOVR_DISABLE_DATA
struct Blob;
struct Blob* luax_readblob(lua_State* L, int index, const char* debug);
struct Blob* luax_readblob(struct lua_State* L, int index, const char* debug);
#endif
#ifndef LOVR_DISABLE_EVENT
struct Variant;
void luax_checkvariant(lua_State* L, int index, struct Variant* variant);
int luax_pushvariant(lua_State* L, struct Variant* variant);
void luax_checkvariant(struct lua_State* L, int index, struct Variant* variant);
int luax_pushvariant(struct lua_State* L, struct Variant* variant);
#endif
#ifndef LOVR_DISABLE_FILESYSTEM
@ -188,28 +133,28 @@ void* luax_readfile(const char* filename, size_t* bytesRead);
struct Attachment;
struct Texture;
struct Uniform;
int luax_checkuniform(lua_State* L, int index, const struct Uniform* uniform, void* dest, const char* debug);
int luax_optmipmap(lua_State* L, int index, struct Texture* texture);
void luax_readattachments(lua_State* L, int index, struct Attachment* attachments, int* count);
int luax_checkuniform(struct lua_State* L, int index, const struct Uniform* uniform, void* dest, const char* debug);
int luax_optmipmap(struct lua_State* L, int index, struct Texture* texture);
void luax_readattachments(struct lua_State* L, int index, struct Attachment* attachments, int* count);
#endif
#ifndef LOVR_DISABLE_MATH
#include "math/pool.h" // TODO
float* luax_tovector(lua_State* L, int index, VectorType* type);
float* luax_checkvector(lua_State* L, int index, VectorType type, const char* expected);
float* luax_newtempvector(lua_State* L, VectorType type);
int luax_readvec3(lua_State* L, int index, float* v, const char* expected);
int luax_readscale(lua_State* L, int index, float* v, int components, const char* expected);
int luax_readquat(lua_State* L, int index, float* q, const char* expected);
int luax_readmat4(lua_State* L, int index, float* m, int scaleComponents);
uint64_t luax_checkrandomseed(lua_State* L, int index);
float* luax_tovector(struct lua_State* L, int index, VectorType* type);
float* luax_checkvector(struct lua_State* L, int index, VectorType type, const char* expected);
float* luax_newtempvector(struct lua_State* L, VectorType type);
int luax_readvec3(struct lua_State* L, int index, float* v, const char* expected);
int luax_readscale(struct lua_State* L, int index, float* v, int components, const char* expected);
int luax_readquat(struct lua_State* L, int index, float* q, const char* expected);
int luax_readmat4(struct lua_State* L, int index, float* m, int scaleComponents);
uint64_t luax_checkrandomseed(struct lua_State* L, int index);
#endif
#ifndef LOVR_DISABLE_PHYSICS
struct Joint;
struct Shape;
void luax_pushjoint(lua_State* L, struct Joint* joint);
void luax_pushshape(lua_State* L, struct Shape* shape);
struct Joint* luax_checkjoint(lua_State* L, int index);
struct Shape* luax_checkshape(lua_State* L, int index);
void luax_pushjoint(struct lua_State* L, struct Joint* joint);
void luax_pushshape(struct lua_State* L, struct Shape* shape);
struct Joint* luax_checkjoint(struct lua_State* L, int index);
struct Shape* luax_checkshape(struct lua_State* L, int index);
#endif

View File

@ -4,6 +4,8 @@
#include "data/sound.h"
#include "core/maf.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
StringEntry lovrEffect[] = {
@ -267,6 +269,8 @@ static const luaL_Reg lovrAudio[] = {
{ NULL, NULL }
};
extern const luaL_Reg lovrSource[];
int luaopen_lovr_audio(lua_State* L) {
lua_newtable(L);
luax_register(L, lovrAudio);

View File

@ -2,6 +2,8 @@
#include "audio/audio.h"
#include "core/maf.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrSourceClone(lua_State* L) {
Source* source = luax_checktype(L, 1, Source);

View File

@ -4,6 +4,8 @@
#include "data/rasterizer.h"
#include "data/sound.h"
#include "data/image.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <string.h>
@ -124,6 +126,12 @@ static const luaL_Reg lovrData[] = {
{ NULL, NULL }
};
extern const luaL_Reg lovrBlob[];
extern const luaL_Reg lovrImage[];
extern const luaL_Reg lovrModelData[];
extern const luaL_Reg lovrRasterizer[];
extern const luaL_Reg lovrSound[];
int luaopen_lovr_data(lua_State* L) {
lua_newtable(L);
luax_register(L, lovrData);

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "data/blob.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrBlobGetName(lua_State* L) {
Blob* blob = luax_checktype(L, 1, Blob);

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "data/image.h"
#include "data/blob.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrImageEncode(lua_State* L) {
Image* image = luax_checktype(L, 1, Image);

View File

@ -1,5 +1,7 @@
#include "api.h"
#include "data/modelData.h"
#include <lua.h>
#include <lauxlib.h>
const luaL_Reg lovrModelData[] = {
{ NULL, NULL }

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "data/rasterizer.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrRasterizerGetHeight(lua_State* L) {
Rasterizer* rasterizer = luax_checktype(L, 1, Rasterizer);

View File

@ -2,6 +2,8 @@
#include "data/sound.h"
#include "data/blob.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
StringEntry lovrSampleFormat[] = {
[SAMPLE_F32] = ENTRY("f32"),

View File

@ -2,6 +2,8 @@
#include "event/event.h"
#include "thread/thread.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <string.h>

View File

@ -4,6 +4,8 @@
#include "core/fs.h"
#include "core/os.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <string.h>

View File

@ -12,6 +12,8 @@
#include "data/image.h"
#include "core/os.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
@ -1820,6 +1822,15 @@ static const luaL_Reg lovrGraphics[] = {
{ NULL, NULL }
};
extern const luaL_Reg lovrCanvas[];
extern const luaL_Reg lovrFont[];
extern const luaL_Reg lovrMaterial[];
extern const luaL_Reg lovrMesh[];
extern const luaL_Reg lovrModel[];
extern const luaL_Reg lovrShader[];
extern const luaL_Reg lovrShaderBlock[];
extern const luaL_Reg lovrTexture[];
int luaopen_lovr_graphics(lua_State* L) {
lua_newtable(L);
luax_register(L, lovrGraphics);

View File

@ -2,6 +2,8 @@
#include "graphics/canvas.h"
#include "graphics/graphics.h"
#include "graphics/texture.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
static int luax_checkattachment(lua_State* L, int index, Attachment* attachment) {

View File

@ -2,6 +2,8 @@
#include "graphics/font.h"
#include "data/rasterizer.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrFontGetWidth(lua_State* L) {
Font* font = luax_checktype(L, 1, Font);

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "graphics/material.h"
#include "graphics/texture.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrMaterialGetColor(lua_State* L) {
Material* material = luax_checktype(L, 1, Material);

View File

@ -4,6 +4,8 @@
#include "graphics/material.h"
#include "graphics/mesh.h"
#include "data/blob.h"
#include <lua.h>
#include <lauxlib.h>
#include <limits.h>
static int l_lovrMeshAttachAttributes(lua_State* L) {

View File

@ -3,6 +3,8 @@
#include "graphics/model.h"
#include "data/modelData.h"
#include "core/maf.h"
#include <lua.h>
#include <lauxlib.h>
static uint32_t luax_checkanimation(lua_State* L, int index, Model* model) {
switch (lua_type(L, index)) {

View File

@ -3,6 +3,8 @@
#include "graphics/shader.h"
#include "data/blob.h"
#include "core/maf.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
struct TempData {

View File

@ -2,6 +2,8 @@
#include "graphics/buffer.h"
#include "graphics/shader.h"
#include "data/blob.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <string.h>

View File

@ -1,5 +1,7 @@
#include "api.h"
#include "graphics/texture.h"
#include <lua.h>
#include <lauxlib.h>
int luax_optmipmap(lua_State* L, int index, Texture* texture) {
uint32_t mipmap = luaL_optinteger(L, index, 1);

View File

@ -5,6 +5,8 @@
#include "graphics/model.h"
#include "graphics/texture.h"
#include "core/maf.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
StringEntry lovrHeadsetDriver[] = {

View File

@ -1,43 +1,7 @@
#include "api.h"
#include "core/util.h"
const luaL_Reg lovrModules[] = {
{ "lovr", luaopen_lovr },
#ifndef LOVR_DISABLE_AUDIO
{ "lovr.audio", luaopen_lovr_audio },
#endif
#ifndef LOVR_DISABLE_DATA
{ "lovr.data", luaopen_lovr_data },
#endif
#ifndef LOVR_DISABLE_EVENT
{ "lovr.event", luaopen_lovr_event },
#endif
#ifndef LOVR_DISABLE_FILESYSTEM
{ "lovr.filesystem", luaopen_lovr_filesystem },
#endif
#ifndef LOVR_DISABLE_GRAPHICS
{ "lovr.graphics", luaopen_lovr_graphics },
#endif
#ifndef LOVR_DISABLE_HEADSET
{ "lovr.headset", luaopen_lovr_headset },
#endif
#ifndef LOVR_DISABLE_MATH
{ "lovr.math", luaopen_lovr_math },
#endif
#ifndef LOVR_DISABLE_PHYSICS
{ "lovr.physics", luaopen_lovr_physics },
#endif
#ifndef LOVR_DISABLE_SYSTEM
{ "lovr.system", luaopen_lovr_system },
#endif
#ifndef LOVR_DISABLE_THREAD
{ "lovr.thread", luaopen_lovr_thread },
#endif
#ifndef LOVR_DISABLE_TIMER
{ "lovr.timer", luaopen_lovr_timer },
#endif
{ NULL, NULL }
};
#include <lua.h>
#include <lauxlib.h>
static int l_lovrGetVersion(lua_State* L) {
lua_pushinteger(L, LOVR_VERSION_MAJOR);

View File

@ -5,6 +5,8 @@
#include "math/randomGenerator.h"
#include "core/maf.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
int l_lovrRandomGeneratorRandom(lua_State* L);
@ -19,6 +21,14 @@ int l_lovrMat4Set(lua_State* L);
static LOVR_THREAD_LOCAL Pool* pool;
extern const luaL_Reg lovrCurve[];
extern const luaL_Reg lovrRandomGenerator[];
extern const luaL_Reg lovrVec2[];
extern const luaL_Reg lovrVec3[];
extern const luaL_Reg lovrVec4[];
extern const luaL_Reg lovrQuat[];
extern const luaL_Reg lovrMat4[];
static const luaL_Reg* lovrVectorMetatables[] = {
[V_VEC2] = lovrVec2,
[V_VEC3] = lovrVec3,

View File

@ -1,7 +1,8 @@
#include "api.h"
#include "math/curve.h"
#include "core/util.h"
#include <stdlib.h>
#include <lua.h>
#include <lauxlib.h>
static int l_lovrCurveEvaluate(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve);

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "math/randomGenerator.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <math.h>
static double luax_checkrandomseedpart(lua_State* L, int index) {

View File

@ -2,6 +2,8 @@
#include "math/math.h"
#include "core/maf.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
static const uint32_t* swizzles[5] = {
[2] = (uint32_t[]) {

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "physics/physics.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
StringEntry lovrShapeType[] = {
[SHAPE_SPHERE] = ENTRY("sphere"),
@ -141,6 +143,18 @@ static const luaL_Reg lovrPhysics[] = {
{ NULL, NULL }
};
extern const luaL_Reg lovrWorld[];
extern const luaL_Reg lovrCollider[];
extern const luaL_Reg lovrBallJoint[];
extern const luaL_Reg lovrDistanceJoint[];
extern const luaL_Reg lovrHingeJoint[];
extern const luaL_Reg lovrSliderJoint[];
extern const luaL_Reg lovrSphereShape[];
extern const luaL_Reg lovrBoxShape[];
extern const luaL_Reg lovrCapsuleShape[];
extern const luaL_Reg lovrCylinderShape[];
extern const luaL_Reg lovrMeshShape[];
int luaopen_lovr_physics(lua_State* L) {
lua_newtable(L);
luax_register(L, lovrPhysics);

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "physics/physics.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdbool.h>
static int l_lovrColliderDestroy(lua_State* L) {

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "physics/physics.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
void luax_pushjoint(lua_State* L, Joint* joint) {
switch (joint->type) {

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "physics/physics.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
void luax_pushshape(lua_State* L, Shape* shape) {
switch (shape->type) {

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "physics/physics.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdbool.h>
static void collisionResolver(World* world, void* userdata) {

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "system/system.h"
#include "core/os.h"
#include <lua.h>
#include <lauxlib.h>
StringEntry lovrKeyboardKey[] = {
[KEY_A] = ENTRY("a"),

View File

@ -3,6 +3,8 @@
#include "thread/thread.h"
#include "thread/channel.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <stdlib.h>
#include <string.h>
@ -17,13 +19,9 @@ static int threadRunner(void* data) {
lua_State* L = luaL_newstate();
luaL_openlibs(L);
luax_preload(L);
lovrSetErrorCallback((errorFn*) luax_vthrow, L);
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
luax_register(L, lovrModules);
lua_pop(L, 2);
lua_pushcfunction(L, luax_getstack);
int errhandler = lua_gettop(L);
@ -104,6 +102,9 @@ static const luaL_Reg lovrThreadModule[] = {
{ NULL, NULL }
};
extern const luaL_Reg lovrThread[];
extern const luaL_Reg lovrChannel[];
int luaopen_lovr_thread(lua_State* L) {
lua_newtable(L);
luax_register(L, lovrThreadModule);

View File

@ -2,6 +2,8 @@
#include "thread/channel.h"
#include "event/event.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <math.h>
static void luax_checktimeout(lua_State* L, int index, double* timeout) {

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "thread/thread.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrThreadStart(lua_State* L) {
Thread* thread = luax_checktype(L, 1, Thread);

View File

@ -1,5 +1,7 @@
#include "api.h"
#include "timer/timer.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrTimerGetDelta(lua_State* L) {
lua_pushnumber(L, lovrTimerGetDelta());

View File

@ -3,6 +3,8 @@
#include "event/event.h"
#include "core/os.h"
#include "core/util.h"
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <stdbool.h>
#include <string.h>
@ -39,6 +41,7 @@ int main(int argc, char** argv) {
lua_State* L = luaL_newstate();
luax_setmainthread(L);
luaL_openlibs(L);
luax_preload(L);
// arg table
lua_newtable(L);
@ -63,11 +66,6 @@ int main(int argc, char** argv) {
}
lua_setglobal(L, "arg");
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
luax_register(L, lovrModules);
lua_pop(L, 2);
lua_pushcfunction(L, luax_getstack);
if (luaL_loadbuffer(L, (const char*) src_resources_boot_lua, src_resources_boot_lua_len, "@boot.lua") || lua_pcall(L, 0, 1, -2)) {
fprintf(stderr, "%s\n", lua_tostring(L, -1));
@ -107,7 +105,7 @@ int main(int argc, char** argv) {
}
#ifdef EMSCRIPTEN
// Called by JS
// Called by JS, don't delete
void lovrDestroy(void* arg) {
if (arg) {
lovrEmscriptenContext* context = arg;