2021-02-19 03:46:14 +00:00
|
|
|
#include <stdbool.h>
|
2019-08-21 22:27:26 +00:00
|
|
|
#include <stdint.h>
|
2021-03-16 00:54:27 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2022-11-24 22:33:55 +00:00
|
|
|
#include <lua.h>
|
|
|
|
#include <lauxlib.h>
|
2019-08-21 22:27:26 +00:00
|
|
|
|
|
|
|
#pragma once
|
2017-03-11 11:08:07 +00:00
|
|
|
|
2018-01-21 22:20:06 +00:00
|
|
|
// Enums
|
2020-02-17 01:50:51 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t length;
|
|
|
|
char string[31];
|
|
|
|
} StringEntry;
|
|
|
|
|
|
|
|
#define ENTRY(s) { sizeof(s) - 1, s }
|
2019-08-21 22:27:26 +00:00
|
|
|
|
2021-10-08 21:25:03 +00:00
|
|
|
extern StringEntry lovrAnimationProperty[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrArcMode[];
|
|
|
|
extern StringEntry lovrAttributeType[];
|
2021-02-28 22:27:20 +00:00
|
|
|
extern StringEntry lovrAudioMaterial[];
|
2021-03-04 03:01:56 +00:00
|
|
|
extern StringEntry lovrAudioShareMode[];
|
2021-02-05 21:06:25 +00:00
|
|
|
extern StringEntry lovrAudioType[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrBlendAlphaMode[];
|
|
|
|
extern StringEntry lovrBlendMode[];
|
|
|
|
extern StringEntry lovrBlockType[];
|
2022-04-26 22:32:54 +00:00
|
|
|
extern StringEntry lovrBufferLayout[];
|
2021-02-19 04:17:25 +00:00
|
|
|
extern StringEntry lovrChannelLayout[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrCompareMode[];
|
2022-05-11 19:50:26 +00:00
|
|
|
extern StringEntry lovrCullMode[];
|
2023-06-24 02:11:30 +00:00
|
|
|
extern StringEntry lovrDataType[];
|
2022-04-19 02:30:58 +00:00
|
|
|
extern StringEntry lovrDefaultAttribute[];
|
2022-05-28 03:47:07 +00:00
|
|
|
extern StringEntry lovrDefaultShader[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrDevice[];
|
2021-02-05 21:06:25 +00:00
|
|
|
extern StringEntry lovrDeviceAxis[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrDeviceButton[];
|
|
|
|
extern StringEntry lovrDrawMode[];
|
|
|
|
extern StringEntry lovrDrawStyle[];
|
2021-03-03 22:25:03 +00:00
|
|
|
extern StringEntry lovrEffect[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrEventType[];
|
|
|
|
extern StringEntry lovrFilterMode[];
|
|
|
|
extern StringEntry lovrHeadsetDriver[];
|
|
|
|
extern StringEntry lovrHorizontalAlign[];
|
|
|
|
extern StringEntry lovrJointType[];
|
2021-02-25 16:00:12 +00:00
|
|
|
extern StringEntry lovrKeyboardKey[];
|
2023-06-11 05:06:29 +00:00
|
|
|
extern StringEntry lovrMeshStorage[];
|
|
|
|
extern StringEntry lovrModelDrawMode[];
|
2023-11-22 02:47:56 +00:00
|
|
|
extern StringEntry lovrOpenMode[];
|
2022-08-18 05:33:43 +00:00
|
|
|
extern StringEntry lovrOriginType[];
|
2022-05-01 01:54:29 +00:00
|
|
|
extern StringEntry lovrPassType[];
|
2021-02-08 15:05:29 +00:00
|
|
|
extern StringEntry lovrPermission[];
|
|
|
|
extern StringEntry lovrSampleFormat[];
|
2022-05-09 18:47:06 +00:00
|
|
|
extern StringEntry lovrShaderStage[];
|
2024-02-20 23:07:30 +00:00
|
|
|
extern StringEntry lovrShaderType[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrShapeType[];
|
2021-10-08 21:25:03 +00:00
|
|
|
extern StringEntry lovrSmoothMode[];
|
2022-05-07 00:26:38 +00:00
|
|
|
extern StringEntry lovrStackType[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrStencilAction[];
|
2022-04-30 00:12:10 +00:00
|
|
|
extern StringEntry lovrTextureFeature[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrTextureFormat[];
|
|
|
|
extern StringEntry lovrTextureType[];
|
2022-04-30 03:56:23 +00:00
|
|
|
extern StringEntry lovrTextureUsage[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrTimeUnit[];
|
|
|
|
extern StringEntry lovrUniformAccess[];
|
|
|
|
extern StringEntry lovrVerticalAlign[];
|
2023-10-20 16:52:42 +00:00
|
|
|
extern StringEntry lovrViewMask[];
|
2021-03-19 23:20:21 +00:00
|
|
|
extern StringEntry lovrVolumeUnit[];
|
2020-09-28 00:13:00 +00:00
|
|
|
extern StringEntry lovrWinding[];
|
|
|
|
extern StringEntry lovrWrapMode[];
|
2020-02-17 02:31:02 +00:00
|
|
|
|
|
|
|
// General helpers
|
|
|
|
|
2021-02-20 06:10:24 +00:00
|
|
|
typedef struct {
|
|
|
|
const char* name;
|
|
|
|
void (*destructor)(void*);
|
|
|
|
} TypeInfo;
|
|
|
|
|
2019-08-21 22:27:26 +00:00
|
|
|
typedef struct {
|
2019-09-07 22:07:07 +00:00
|
|
|
uint64_t hash;
|
2019-08-21 22:27:26 +00:00
|
|
|
void* object;
|
|
|
|
} Proxy;
|
|
|
|
|
2020-08-19 19:12:06 +00:00
|
|
|
#if LUA_VERSION_NUM > 501
|
|
|
|
#define luax_len(L, i) (int) lua_rawlen(L, i)
|
|
|
|
#define luax_register(L, f) luaL_setfuncs(L, f, 0)
|
|
|
|
#else
|
|
|
|
#define luax_len(L, i) (int) lua_objlen(L, i)
|
|
|
|
#define luax_register(L, f) luaL_register(L, NULL, f)
|
2019-08-21 22:27:26 +00:00
|
|
|
#define LUA_RIDX_MAINTHREAD 1
|
|
|
|
#endif
|
|
|
|
|
2022-02-08 20:40:10 +00:00
|
|
|
#ifdef LOVR_UNCHECKED
|
|
|
|
#define luax_checku32(L, i) (uint32_t) lua_tonumber(L, i)
|
2022-06-21 01:17:51 +00:00
|
|
|
#define luax_optu32(L, i, x) (uint32_t) luaL_optnumber(L, i, x)
|
2022-02-08 20:40:10 +00:00
|
|
|
#else
|
|
|
|
#define luax_checku32(L, i) _luax_checku32(L, i)
|
2022-06-21 01:17:51 +00:00
|
|
|
#define luax_optu32(L, i, x) _luax_optu32(L, i, x)
|
2022-02-08 20:40:10 +00:00
|
|
|
#endif
|
|
|
|
|
2019-08-21 22:27:26 +00:00
|
|
|
#define luax_registertype(L, T) _luax_registertype(L, #T, lovr ## T, lovr ## T ## Destroy)
|
2021-02-09 03:29:57 +00:00
|
|
|
#define luax_totype(L, i, T) (T*) _luax_totype(L, i, hash64(#T, sizeof(#T) - 1))
|
|
|
|
#define luax_checktype(L, i, T) (T*) _luax_checktype(L, i, hash64(#T, sizeof(#T) - 1), #T)
|
|
|
|
#define luax_pushtype(L, T, o) _luax_pushtype(L, #T, hash64(#T, sizeof(#T) - 1), o)
|
2020-09-28 00:13:00 +00:00
|
|
|
#define luax_checkenum(L, i, T, x) _luax_checkenum(L, i, lovr ## T, x, #T)
|
|
|
|
#define luax_pushenum(L, T, x) lua_pushlstring(L, (lovr ## T)[x].string, (lovr ## T)[x].length)
|
2019-08-21 22:27:26 +00:00
|
|
|
#define luax_checkfloat(L, i) (float) luaL_checknumber(L, i)
|
|
|
|
#define luax_optfloat(L, i, x) (float) luaL_optnumber(L, i, x)
|
2022-05-30 20:32:40 +00:00
|
|
|
#define luax_tofloat(L, i) (float) lua_tonumber(L, i)
|
2019-08-21 22:27:26 +00:00
|
|
|
|
2022-11-24 22:33:55 +00:00
|
|
|
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);
|
2023-06-28 23:10:30 +00:00
|
|
|
int luax_loadbufferx(lua_State* L, const char* buffer, size_t size, const char* name, const char* mode);
|
2019-09-24 14:28:34 +00:00
|
|
|
void luax_vthrow(void* L, const char* format, va_list args);
|
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
|
|
|
void luax_vlog(void* context, int level, const char* tag, const char* format, va_list args);
|
2022-11-24 22:33:55 +00:00
|
|
|
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);
|
2019-08-21 22:27:26 +00:00
|
|
|
|
|
|
|
// Module helpers
|
2019-05-18 00:11:22 +00:00
|
|
|
|
2021-02-07 23:45:03 +00:00
|
|
|
#ifndef LOVR_DISABLE_DATA
|
2019-05-18 00:11:22 +00:00
|
|
|
struct Blob;
|
2022-04-30 10:06:14 +00:00
|
|
|
struct Image;
|
2023-03-22 04:30:11 +00:00
|
|
|
struct ModelData;
|
2022-11-24 22:33:55 +00:00
|
|
|
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);
|
2023-03-22 04:30:11 +00:00
|
|
|
uint32_t luax_checkanimationindex(lua_State* L, int index, struct ModelData* model);
|
|
|
|
uint32_t luax_checkmaterialindex(lua_State* L, int index, struct ModelData* model);
|
|
|
|
uint32_t luax_checknodeindex(lua_State* L, int index, struct ModelData* model);
|
2019-05-18 00:11:22 +00:00
|
|
|
#endif
|
|
|
|
|
2021-02-07 23:45:03 +00:00
|
|
|
#ifndef LOVR_DISABLE_EVENT
|
2019-05-18 00:11:22 +00:00
|
|
|
struct Variant;
|
2022-11-24 22:33:55 +00:00
|
|
|
void luax_checkvariant(lua_State* L, int index, struct Variant* variant);
|
|
|
|
int luax_pushvariant(lua_State* L, struct Variant* variant);
|
2019-05-18 00:11:22 +00:00
|
|
|
#endif
|
|
|
|
|
2021-02-07 23:45:03 +00:00
|
|
|
#ifndef LOVR_DISABLE_FILESYSTEM
|
2019-12-08 09:46:54 +00:00
|
|
|
void* luax_readfile(const char* filename, size_t* bytesRead);
|
2022-08-03 05:05:12 +00:00
|
|
|
bool luax_writefile(const char* filename, const void* data, size_t size);
|
2019-12-08 09:46:54 +00:00
|
|
|
#endif
|
|
|
|
|
2021-02-07 23:45:03 +00:00
|
|
|
#ifndef LOVR_DISABLE_GRAPHICS
|
2023-06-24 04:14:19 +00:00
|
|
|
struct DataField;
|
2023-10-31 23:08:00 +00:00
|
|
|
struct Material;
|
2022-06-30 03:17:26 +00:00
|
|
|
struct ColoredString;
|
2023-08-25 20:42:09 +00:00
|
|
|
void luax_checkfieldn(lua_State* L, int index, int type, void* data);
|
|
|
|
void luax_checkfieldv(lua_State* L, int index, int type, void* data);
|
|
|
|
void luax_checkfieldt(lua_State* L, int index, int type, void* data);
|
|
|
|
uint32_t luax_checkfieldarray(lua_State* L, int index, const struct DataField* array, char* data);
|
|
|
|
void luax_checkdataflat(lua_State* L, int index, int subindex, uint32_t count, const struct DataField* format, char* data);
|
|
|
|
void luax_checkdatatuples(lua_State* L, int index, int start, uint32_t count, const struct DataField* format, char* data);
|
|
|
|
void luax_checkdatakeys(lua_State* L, int index, int start, uint32_t count, const struct DataField* array, char* data);
|
|
|
|
void luax_checkstruct(lua_State* L, int index, const struct DataField* fields, uint32_t count, char* data);
|
2023-10-04 14:43:00 +00:00
|
|
|
int luax_pushbufferdata(lua_State* L, const struct DataField* format, uint32_t count, char* data);
|
2023-08-25 20:42:09 +00:00
|
|
|
void luax_pushbufferformat(lua_State* L, const struct DataField* fields, uint32_t count);
|
|
|
|
uint32_t luax_gettablestride(lua_State* L, int index, int subindex, struct DataField* fields, uint32_t count);
|
2022-11-24 22:33:55 +00:00
|
|
|
uint32_t luax_checkcomparemode(lua_State* L, int index);
|
2023-10-31 23:08:00 +00:00
|
|
|
struct Material* luax_optmaterial(lua_State* L, int index);
|
2022-11-24 22:33:55 +00:00
|
|
|
struct ColoredString* luax_checkcoloredstrings(lua_State* L, int index, uint32_t* count, struct ColoredString* stack);
|
2019-05-18 00:11:22 +00:00
|
|
|
#endif
|
|
|
|
|
2021-02-07 23:45:03 +00:00
|
|
|
#ifndef LOVR_DISABLE_MATH
|
2023-02-08 05:44:43 +00:00
|
|
|
#include "math/math.h" // TODO
|
2022-11-24 22:33:55 +00:00
|
|
|
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);
|
2023-07-11 00:51:24 +00:00
|
|
|
int luax_readvec2(lua_State* L, int index, float* v, const char* expected);
|
2022-11-24 22:33:55 +00:00
|
|
|
int luax_readvec3(lua_State* L, int index, float* v, const char* expected);
|
2023-07-11 00:51:24 +00:00
|
|
|
int luax_readvec4(lua_State* L, int index, float* v, const char* expected);
|
2022-11-24 22:33:55 +00:00
|
|
|
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);
|
2019-05-18 00:11:22 +00:00
|
|
|
#endif
|
2019-06-02 07:20:10 +00:00
|
|
|
|
2021-02-07 23:45:03 +00:00
|
|
|
#ifndef LOVR_DISABLE_PHYSICS
|
2019-06-02 07:20:10 +00:00
|
|
|
struct Joint;
|
|
|
|
struct Shape;
|
2022-11-24 22:33:55 +00:00
|
|
|
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);
|
2024-04-03 22:03:46 +00:00
|
|
|
struct Shape* luax_newcompoundshape(lua_State* L, int index);
|
2019-06-02 07:20:10 +00:00
|
|
|
#endif
|