Fix compatibility with Lua 5.2, 5.3, 5.4;

Part of this involved putting the Lua header back in api.h, since we
need to know the Lua version to define some macros properly.
This commit is contained in:
bjorn 2022-11-24 14:33:55 -08:00
parent 23f747d4c3
commit e9776f98c6
39 changed files with 53 additions and 128 deletions

View File

@ -396,7 +396,7 @@ uint32_t _luax_checku32(lua_State* L, int index) {
double x = lua_tonumber(L, index);
if (x == 0. && !lua_isnumber(L, index)) {
luaL_typerror(L, index, "number");
luax_typeerror(L, index, "number");
}
if (x < 0. || x > UINT32_MAX) {

View File

@ -2,12 +2,11 @@
#include <stdint.h>
#include <stdarg.h>
#include <stddef.h>
#include <lua.h>
#include <lauxlib.h>
#pragma once
struct lua_State;
struct luaL_Reg;
// Enums
typedef struct {
uint8_t length;
@ -107,43 +106,43 @@ typedef struct {
#define luax_optfloat(L, i, x) (float) luaL_optnumber(L, i, x)
#define luax_tofloat(L, i) (float) lua_tonumber(L, i)
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_preload(lua_State* 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, int (*loader)(lua_State* L), int index);
int luax_resume(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(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 (*finalizer)(void));
uint32_t _luax_checku32(struct lua_State* L, int index);
uint32_t _luax_optu32(struct lua_State* L, int index, uint32_t fallback);
void luax_readcolor(struct lua_State* L, int index, float color[4]);
void luax_optcolor(struct lua_State* L, int index, float color[4]);
int luax_readmesh(struct lua_State* L, int index, float** vertices, uint32_t* vertexCount, uint32_t** indices, uint32_t* indexCount, bool* shouldFree);
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 (*finalizer)(void));
uint32_t _luax_checku32(lua_State* L, int index);
uint32_t _luax_optu32(lua_State* L, int index, uint32_t fallback);
void luax_readcolor(lua_State* L, int index, float color[4]);
void luax_optcolor(lua_State* L, int index, float color[4]);
int luax_readmesh(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 Image;
struct Blob* luax_readblob(struct lua_State* L, int index, const char* debug);
struct Image* luax_checkimage(struct lua_State* L, int index);
uint32_t luax_checkcodepoint(struct lua_State* L, int index);
struct Blob* luax_readblob(lua_State* L, int index, const char* debug);
struct Image* luax_checkimage(lua_State* L, int index);
uint32_t luax_checkcodepoint(lua_State* L, int index);
#endif
#ifndef LOVR_DISABLE_EVENT
struct Variant;
void luax_checkvariant(struct lua_State* L, int index, struct Variant* variant);
int luax_pushvariant(struct lua_State* L, struct Variant* variant);
void luax_checkvariant(lua_State* L, int index, struct Variant* variant);
int luax_pushvariant(lua_State* L, struct Variant* variant);
#endif
#ifndef LOVR_DISABLE_FILESYSTEM
@ -155,37 +154,37 @@ bool luax_writefile(const char* filename, const void* data, size_t size);
struct Buffer;
struct ColoredString;
struct Model;
struct Buffer* luax_checkbuffer(struct lua_State* L, int index);
void luax_readbufferfield(struct lua_State* L, int index, int type, void* data);
void luax_readbufferdata(struct lua_State* L, int index, struct Buffer* buffer, char* data);
uint32_t luax_checkcomparemode(struct lua_State* L, int index);
struct ColoredString* luax_checkcoloredstrings(struct lua_State* L, int index, uint32_t* count, struct ColoredString* stack);
uint32_t luax_checknodeindex(struct lua_State* L, int index, struct Model* model);
struct Buffer* luax_checkbuffer(lua_State* L, int index);
void luax_readbufferfield(lua_State* L, int index, int type, void* data);
void luax_readbufferdata(lua_State* L, int index, struct Buffer* buffer, char* data);
uint32_t luax_checkcomparemode(lua_State* L, int index);
struct ColoredString* luax_checkcoloredstrings(lua_State* L, int index, uint32_t* count, struct ColoredString* stack);
uint32_t luax_checknodeindex(lua_State* L, int index, struct Model* model);
#endif
#ifndef LOVR_DISABLE_MATH
#include "math/pool.h" // TODO
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);
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);
#endif
#ifndef LOVR_DISABLE_PHYSICS
struct Joint;
struct Shape;
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);
struct Shape* luax_newsphereshape(struct lua_State* L, int index);
struct Shape* luax_newboxshape(struct lua_State* L, int index);
struct Shape* luax_newcapsuleshape(struct lua_State* L, int index);
struct Shape* luax_newcylindershape(struct lua_State* L, int index);
struct Shape* luax_newmeshshape(struct lua_State* L, int index);
struct Shape* luax_newterrainshape(struct lua_State* L, int index);
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);
struct Shape* luax_newsphereshape(lua_State* L, int index);
struct Shape* luax_newboxshape(lua_State* L, int index);
struct Shape* luax_newcapsuleshape(lua_State* L, int index);
struct Shape* luax_newcylindershape(lua_State* L, int index);
struct Shape* luax_newmeshshape(lua_State* L, int index);
struct Shape* luax_newterrainshape(lua_State* L, int index);
#endif

View File

@ -4,8 +4,6 @@
#include "data/sound.h"
#include "core/maf.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
StringEntry lovrEffect[] = {

View File

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

View File

@ -5,8 +5,6 @@
#include "data/sound.h"
#include "data/image.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <string.h>

View File

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

View File

@ -2,8 +2,6 @@
#include "data/image.h"
#include "data/blob.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
StringEntry lovrTextureFormat[] = {
[FORMAT_R8] = ENTRY("r8"),

View File

@ -2,8 +2,6 @@
#include "data/modelData.h"
#include "core/maf.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
static ModelNode* luax_checknode(lua_State* L, int index, ModelData* model) {
switch (lua_type(L, index)) {

View File

@ -2,8 +2,6 @@
#include "data/rasterizer.h"
#include "data/image.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <math.h>
uint32_t luax_checkcodepoint(lua_State* L, int index) {

View File

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

View File

@ -2,8 +2,6 @@
#include "event/event.h"
#include "thread/thread.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <string.h>
@ -185,7 +183,7 @@ static int l_lovrEventPush(lua_State* L) {
}
static int l_lovrEventQuit(lua_State* L) {
int exitCode = luaL_optint(L, 1, 0);
int exitCode = luaL_optinteger(L, 1, 0);
Event event = { .type = EVENT_QUIT, .data.quit.exitCode = exitCode };
lovrEventPush(event);
return 0;

View File

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

View File

@ -5,8 +5,6 @@
#include "data/modelData.h"
#include "data/rasterizer.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <string.h>

View File

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

View File

@ -2,8 +2,6 @@
#include "graphics/graphics.h"
#include "data/rasterizer.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
ColoredString* luax_checkcoloredstrings(lua_State* L, int index, uint32_t* count, ColoredString* stack) {

View File

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

View File

@ -3,8 +3,6 @@
#include "data/modelData.h"
#include "core/maf.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
// This adds about 2-3us of overhead, which sucks, but the reduction in complexity is large
static int luax_callmodeldata(lua_State* L, const char* method, int nrets) {

View File

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

View File

@ -3,8 +3,6 @@
#include "data/blob.h"
#include "data/image.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrReadbackIsComplete(lua_State* L) {
Readback* readback = luax_checktype(L, 1, Readback);

View File

@ -1,8 +1,6 @@
#include "api.h"
#include "graphics/graphics.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrSamplerGetFilter(lua_State* L) {
Sampler* sampler = luax_checktype(L, 1, Sampler);

View File

@ -1,8 +1,6 @@
#include "api.h"
#include "graphics/graphics.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
static int l_lovrShaderClone(lua_State* L) {

View File

@ -1,8 +1,6 @@
#include "api.h"
#include "graphics/graphics.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrTallyGetType(lua_State* L) {
Tally* tally = luax_checktype(L, 1, Tally);

View File

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

View File

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

View File

@ -1,7 +1,5 @@
#include "api.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrGetVersion(lua_State* L) {
lua_pushinteger(L, LOVR_VERSION_MAJOR);

View File

@ -4,8 +4,6 @@
#include "math/pool.h"
#include "math/randomGenerator.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
int l_lovrRandomGeneratorRandom(lua_State* L);

View File

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

View File

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

View File

@ -1,8 +1,6 @@
#include "api.h"
#include "core/maf.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#define EQ_THRESHOLD 1e-10f

View File

@ -1,8 +1,6 @@
#include "api.h"
#include "physics/physics.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
StringEntry lovrShapeType[] = {
[SHAPE_SPHERE] = ENTRY("sphere"),

View File

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

View File

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

View File

@ -3,8 +3,6 @@
#include "data/image.h"
#include "core/maf.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <string.h>

View File

@ -1,8 +1,6 @@
#include "api.h"
#include "physics/physics.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <stdbool.h>
#include <string.h>

View File

@ -3,8 +3,6 @@
#include "data/image.h"
#include "core/os.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <string.h>
StringEntry lovrKeyboardKey[] = {

View File

@ -3,8 +3,6 @@
#include "thread/thread.h"
#include "thread/channel.h"
#include "util.h"
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <stdlib.h>
#include <string.h>

View File

@ -2,8 +2,6 @@
#include "thread/channel.h"
#include "event/event.h"
#include "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,8 +1,6 @@
#include "api.h"
#include "thread/thread.h"
#include "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,7 +1,5 @@
#include "api.h"
#include "timer/timer.h"
#include <lua.h>
#include <lauxlib.h>
static int l_lovrTimerGetDelta(lua_State* L) {
lua_pushnumber(L, lovrTimerGetDelta());