2016-11-19 09:28:01 +00:00
|
|
|
#include "vendor/vec/vec.h"
|
|
|
|
#include "vendor/map/map.h"
|
2016-07-07 07:04:24 +00:00
|
|
|
#include <lua.h>
|
|
|
|
#include <lauxlib.h>
|
|
|
|
#include <lualib.h>
|
2016-09-30 06:18:51 +00:00
|
|
|
|
|
|
|
#ifndef UTIL_TYPES
|
|
|
|
#define UTIL_TYPES
|
2016-11-19 08:37:43 +00:00
|
|
|
#define containerof(ptr, type) ((type*)((char*)(ptr) - offsetof(type, ref)))
|
|
|
|
|
2016-10-04 22:05:34 +00:00
|
|
|
#define MAX(a, b) a > b ? a : b
|
|
|
|
#define MIN(a, b) a < b ? a : b
|
|
|
|
|
2016-11-14 23:48:17 +00:00
|
|
|
#define LOVR_COLOR(r, g, b, a) ((a << 0) | (b << 8) | (g << 16) | (r << 24))
|
|
|
|
#define LOVR_COLOR_R(c) (c >> 24 & 0xff)
|
|
|
|
#define LOVR_COLOR_G(c) (c >> 16 & 0xff)
|
|
|
|
#define LOVR_COLOR_B(c) (c >> 8 & 0xff)
|
|
|
|
#define LOVR_COLOR_A(c) (c >> 0 & 0xff)
|
|
|
|
|
2017-01-06 01:00:53 +00:00
|
|
|
#define luax_checktype(L, i, T) *(T**) luaL_checkudata(L, i, #T)
|
2016-11-19 07:41:23 +00:00
|
|
|
|
2016-11-19 08:37:43 +00:00
|
|
|
#define luax_pushtype(L, T, x) \
|
2016-11-19 07:41:23 +00:00
|
|
|
T** u = (T**) lua_newuserdata(L, sizeof(T**)); \
|
|
|
|
luaL_getmetatable(L, #T); \
|
|
|
|
lua_setmetatable(L, -2); \
|
|
|
|
*u = x;
|
|
|
|
|
|
|
|
typedef struct ref {
|
|
|
|
void (*free)(const struct ref* ref);
|
|
|
|
int count;
|
|
|
|
} Ref;
|
|
|
|
|
2016-09-30 06:18:51 +00:00
|
|
|
typedef vec_t(unsigned int) vec_uint_t;
|
|
|
|
#endif
|
2016-07-07 07:04:24 +00:00
|
|
|
|
|
|
|
void error(const char* format, ...);
|
2016-11-08 09:42:31 +00:00
|
|
|
unsigned char* loadImage(void* data, size_t size, int* w, int* h, int* n, int channels);
|
2016-11-08 22:15:37 +00:00
|
|
|
const char* map_int_find(map_int_t *map, int value);
|
2016-11-26 07:32:48 +00:00
|
|
|
void lovrSleep(double seconds);
|
2016-11-19 08:37:43 +00:00
|
|
|
|
2016-11-19 07:41:23 +00:00
|
|
|
void* lovrAlloc(size_t size, void (*destructor)(const Ref* ref));
|
|
|
|
void lovrRetain(const Ref* ref);
|
|
|
|
void lovrRelease(const Ref* ref);
|
2016-11-19 08:37:43 +00:00
|
|
|
|
|
|
|
int luax_preloadmodule(lua_State* L, const char* key, lua_CFunction f);
|
|
|
|
void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions);
|
|
|
|
int luax_releasetype(lua_State* L);
|
|
|
|
void* luax_checkenum(lua_State* L, int index, map_int_t* map, const char* typeName);
|
|
|
|
void* luax_optenum(lua_State* L, int index, const char* fallback, map_int_t* map, const char* typeName);
|