mirror of https://github.com/bjornbytes/lovr.git
Use generic Lua helpers;
This commit is contained in:
parent
0c200b9a2c
commit
0f0c301525
|
@ -248,12 +248,12 @@ int l_lovrGraphicsSetScissor(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrGraphicsGetShader(lua_State* L) {
|
||||
luax_pushshader(L, lovrGraphicsGetShader());
|
||||
luax_pushtype(L, Shader, lovrGraphicsGetShader());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrGraphicsSetShader(lua_State* L) {
|
||||
Shader* shader = lua_isnoneornil(L, 1) ? NULL : luax_checkshader(L, 1);
|
||||
Shader* shader = lua_isnoneornil(L, 1) ? NULL : luax_checktype(L, 1, Shader);
|
||||
lovrGraphicsSetShader(shader);
|
||||
return 0;
|
||||
}
|
||||
|
@ -542,7 +542,7 @@ int l_lovrGraphicsNewModel(lua_State* L) {
|
|||
return luaL_error(L, "Could not load model file '%s'", path);
|
||||
}
|
||||
|
||||
luax_pushmodel(L, lovrModelCreate(data, size));
|
||||
luax_pushtype(L, Model, lovrModelCreate(data, size));
|
||||
free(data);
|
||||
return 1;
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ int l_lovrGraphicsNewShader(lua_State* L) {
|
|||
|
||||
const char* vertexSource = lua_tostring(L, 1);
|
||||
const char* fragmentSource = lua_tostring(L, 2);
|
||||
luax_pushshader(L, lovrShaderCreate(vertexSource, fragmentSource));
|
||||
luax_pushtype(L, Shader, lovrShaderCreate(vertexSource, fragmentSource));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -595,7 +595,7 @@ int l_lovrGraphicsNewSkybox(lua_State* L) {
|
|||
}
|
||||
}
|
||||
|
||||
luax_pushskybox(L, lovrSkyboxCreate(data, size));
|
||||
luax_pushtype(L, Skybox, lovrSkyboxCreate(data, size));
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
free(data[i]);
|
||||
|
@ -621,7 +621,7 @@ int l_lovrGraphicsNewTexture(lua_State* L) {
|
|||
texture = lovrTextureCreateFromBuffer(buffer);
|
||||
}
|
||||
|
||||
luax_pushtexture(L, texture);
|
||||
luax_pushtype(L, Texture, texture);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ int l_lovrHeadsetGetAngularVelocity(lua_State* L) {
|
|||
|
||||
int l_lovrHeadsetGetController(lua_State* L) {
|
||||
ControllerHand* hand = (ControllerHand*) luax_checkenum(L, 1, &ControllerHands, "controller hand");
|
||||
luax_pushcontroller(L, lovrHeadsetGetController(*hand));
|
||||
luax_pushtype(L, Controller, lovrHeadsetGetController(*hand));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "lovr/types/texture.h"
|
||||
#include "lovr/graphics.h"
|
||||
|
||||
int luax_pushbuffervertex(lua_State* L, void* vertex, BufferFormat format) {
|
||||
static int luax_pushbuffervertex(lua_State* L, void* vertex, BufferFormat format) {
|
||||
int count = 0;
|
||||
int i;
|
||||
BufferAttribute attribute;
|
||||
|
@ -322,13 +322,13 @@ int l_lovrBufferSetDrawRange(lua_State* L) {
|
|||
|
||||
int l_lovrBufferGetTexture(lua_State* L) {
|
||||
Buffer* buffer = luax_checktype(L, 1, Buffer);
|
||||
luax_pushtexture(L, lovrBufferGetTexture(buffer));
|
||||
luax_pushtype(L, Texture, lovrBufferGetTexture(buffer));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrBufferSetTexture(lua_State* L) {
|
||||
Buffer* buffer = luax_checktype(L, 1, Buffer);
|
||||
Texture* texture = luax_checktexture(L, 2);
|
||||
Texture* texture = luax_checktype(L, 2, Texture);
|
||||
lovrBufferSetTexture(buffer, texture);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,10 +3,9 @@
|
|||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
|
||||
int luax_pushvertex(lua_State* L, void* vertex, BufferFormat format);
|
||||
void luax_checkbufferformat(lua_State* L, int index, BufferFormat* format);
|
||||
extern const luaL_Reg lovrBuffer[];
|
||||
|
||||
extern const luaL_Reg lovrBuffer[];
|
||||
int l_lovrBufferDraw(lua_State* L);
|
||||
int l_lovrBufferGetVertexCount(lua_State* L);
|
||||
int l_lovrBufferGetVertex(lua_State* L);
|
||||
|
|
|
@ -2,22 +2,6 @@
|
|||
#include "lovr/headset.h"
|
||||
#include "util.h"
|
||||
|
||||
void luax_pushcontroller(lua_State* L, Controller* controller) {
|
||||
if (controller == NULL) {
|
||||
lua_pushnil(L);
|
||||
return;
|
||||
}
|
||||
|
||||
Controller** userdata = (Controller**) lua_newuserdata(L, sizeof(Controller*));
|
||||
luaL_getmetatable(L, "Controller");
|
||||
lua_setmetatable(L, -2);
|
||||
*userdata = controller;
|
||||
}
|
||||
|
||||
Controller* luax_checkcontroller(lua_State* L, int index) {
|
||||
return *(Controller**) luaL_checkudata(L, index, "Controller");
|
||||
}
|
||||
|
||||
const luaL_Reg lovrController[] = {
|
||||
{ "isPresent", l_lovrControllerIsPresent },
|
||||
{ "getPosition", l_lovrControllerGetPosition },
|
||||
|
@ -30,13 +14,13 @@ const luaL_Reg lovrController[] = {
|
|||
};
|
||||
|
||||
int l_lovrControllerIsPresent(lua_State* L) {
|
||||
Controller* controller = luax_checkcontroller(L, 1);
|
||||
Controller* controller = luax_checktype(L, 1, Controller);
|
||||
lua_pushboolean(L, lovrHeadsetControllerIsPresent(controller));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrControllerGetPosition(lua_State* L) {
|
||||
Controller* controller = luax_checkcontroller(L, 1);
|
||||
Controller* controller = luax_checktype(L, 1, Controller);
|
||||
float x, y, z;
|
||||
lovrHeadsetControllerGetPosition(controller, &x, &y, &z);
|
||||
lua_pushnumber(L, x);
|
||||
|
@ -46,7 +30,7 @@ int l_lovrControllerGetPosition(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrControllerGetOrientation(lua_State* L) {
|
||||
Controller* controller = luax_checkcontroller(L, 1);
|
||||
Controller* controller = luax_checktype(L, 1, Controller);
|
||||
float w, x, y, z;
|
||||
lovrHeadsetControllerGetOrientation(controller, &w, &x, &y, &z);
|
||||
lua_pushnumber(L, w);
|
||||
|
@ -57,27 +41,27 @@ int l_lovrControllerGetOrientation(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrControllerGetAxis(lua_State* L) {
|
||||
Controller* controller = luax_checkcontroller(L, 1);
|
||||
Controller* controller = luax_checktype(L, 1, Controller);
|
||||
ControllerAxis* axis = (ControllerAxis*) luax_checkenum(L, 2, &ControllerAxes, "controller axis");
|
||||
lua_pushnumber(L, lovrHeadsetControllerGetAxis(controller, *axis));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrControllerIsDown(lua_State* L) {
|
||||
Controller* controller = luax_checkcontroller(L, 1);
|
||||
Controller* controller = luax_checktype(L, 1, Controller);
|
||||
ControllerButton* button = (ControllerButton*) luax_checkenum(L, 2, &ControllerButtons, "controller button");
|
||||
lua_pushboolean(L, lovrHeadsetControllerIsDown(controller, *button));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrControllerGetHand(lua_State* L) {
|
||||
Controller* controller = luax_checkcontroller(L, 1);
|
||||
Controller* controller = luax_checktype(L, 1, Controller);
|
||||
lua_pushstring(L, map_int_find(&ControllerHands, lovrHeadsetControllerGetHand(controller)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrControllerVibrate(lua_State* L) {
|
||||
Controller* controller = luax_checkcontroller(L, 1);
|
||||
Controller* controller = luax_checktype(L, 1, Controller);
|
||||
float duration = luaL_optnumber(L, 2, .5);
|
||||
lovrHeadsetControllerVibrate(controller, duration);
|
||||
return 0;
|
||||
|
|
|
@ -3,9 +3,6 @@
|
|||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
|
||||
void luax_pushcontroller(lua_State* L, Controller* controller);
|
||||
extern const luaL_Reg lovrController[];
|
||||
|
||||
extern const luaL_Reg lovrController[];
|
||||
int l_lovrControllerIsPresent(lua_State* L);
|
||||
int l_lovrControllerGetPosition(lua_State* L);
|
||||
|
|
|
@ -1,22 +1,6 @@
|
|||
#include "lovr/types/model.h"
|
||||
#include "lovr/types/texture.h"
|
||||
|
||||
void luax_pushmodel(lua_State* L, Model* model) {
|
||||
if (model == NULL) {
|
||||
lua_pushnil(L);
|
||||
return;
|
||||
}
|
||||
|
||||
Model** userdata = (Model**) lua_newuserdata(L, sizeof(Model*));
|
||||
luaL_getmetatable(L, "Model");
|
||||
lua_setmetatable(L, -2);
|
||||
*userdata = model;
|
||||
}
|
||||
|
||||
Model* luax_checkmodel(lua_State* L, int index) {
|
||||
return *(Model**) luaL_checkudata(L, index, "Model");
|
||||
}
|
||||
|
||||
const luaL_Reg lovrModel[] = {
|
||||
{ "draw", l_lovrModelDraw },
|
||||
{ "getTexture", l_lovrModelGetTexture },
|
||||
|
@ -25,7 +9,7 @@ const luaL_Reg lovrModel[] = {
|
|||
};
|
||||
|
||||
int l_lovrModelDraw(lua_State* L) {
|
||||
Model* model = luax_checkmodel(L, 1);
|
||||
Model* model = luax_checktype(L, 1, Model);
|
||||
float x = luaL_optnumber(L, 2, 0.f);
|
||||
float y = luaL_optnumber(L, 3, 0.f);
|
||||
float z = luaL_optnumber(L, 4, 0.f);
|
||||
|
@ -39,14 +23,14 @@ int l_lovrModelDraw(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrModelGetTexture(lua_State* L) {
|
||||
Model* model = luax_checkmodel(L, 1);
|
||||
luax_pushtexture(L, lovrModelGetTexture(model));
|
||||
Model* model = luax_checktype(L, 1, Model);
|
||||
luax_pushtype(L, Texture, lovrModelGetTexture(model));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrModelSetTexture(lua_State* L) {
|
||||
Model* model = luax_checkmodel(L, 1);
|
||||
Texture* texture = luax_checktexture(L, 2);
|
||||
Model* model = luax_checktype(L, 1, Model);
|
||||
Texture* texture = luax_checktype(L, 2, Texture);
|
||||
lovrModelSetTexture(model, texture);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@
|
|||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
|
||||
void luax_pushmodel(lua_State* L, Model* model);
|
||||
Model* luax_checkmodel(lua_State* L, int index);
|
||||
extern const luaL_Reg lovrModel[];
|
||||
|
||||
int l_lovrModelDraw(lua_State* L);
|
||||
int l_lovrModelGetTexture(lua_State* L);
|
||||
int l_lovrModelSetTexture(lua_State* L);
|
||||
|
|
|
@ -1,28 +1,12 @@
|
|||
#include "lovr/types/shader.h"
|
||||
|
||||
void luax_pushshader(lua_State* L, Shader* shader) {
|
||||
if (shader == NULL) {
|
||||
lua_pushnil(L);
|
||||
return;
|
||||
}
|
||||
|
||||
Shader** userdata = (Shader**) lua_newuserdata(L, sizeof(Shader*));
|
||||
luaL_getmetatable(L, "Shader");
|
||||
lua_setmetatable(L, -2);
|
||||
*userdata = shader;
|
||||
}
|
||||
|
||||
Shader* luax_checkshader(lua_State* L, int index) {
|
||||
return *(Shader**) luaL_checkudata(L, index, "Shader");
|
||||
}
|
||||
|
||||
const luaL_Reg lovrShader[] = {
|
||||
{ "send", l_lovrShaderSend },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int l_lovrShaderSend(lua_State* L) {
|
||||
Shader* shader = luax_checkshader(L, 1);
|
||||
Shader* shader = luax_checktype(L, 1, Shader);
|
||||
const char* name = luaL_checkstring(L, 2);
|
||||
|
||||
int id = lovrShaderGetUniformId(shader, name);
|
||||
|
|
|
@ -3,8 +3,5 @@
|
|||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
|
||||
void luax_pushshader(lua_State* L, Shader* shader);
|
||||
Shader* luax_checkshader(lua_State* L, int index);
|
||||
extern const luaL_Reg lovrShader[];
|
||||
|
||||
int l_lovrShaderSend(lua_State* L);
|
||||
|
|
|
@ -1,20 +1,5 @@
|
|||
#include "lovr/types/skybox.h"
|
||||
|
||||
void luax_pushskybox(lua_State* L, Skybox* skybox) {
|
||||
if (skybox == NULL) {
|
||||
lua_pushnil(L);
|
||||
return;
|
||||
}
|
||||
|
||||
Skybox** userdata = (Skybox**) lua_newuserdata(L, sizeof(Skybox*));
|
||||
luaL_getmetatable(L, "Skybox");
|
||||
lua_setmetatable(L, -2);
|
||||
*userdata = skybox;
|
||||
}
|
||||
|
||||
Skybox* luax_checkskybox(lua_State* L, int index) {
|
||||
return *(Skybox**) luaL_checkudata(L, index, "Skybox");
|
||||
}
|
||||
#include "graphics/graphics.h"
|
||||
|
||||
const luaL_Reg lovrSkybox[] = {
|
||||
{ "draw", l_lovrSkyboxDraw },
|
||||
|
@ -22,7 +7,7 @@ const luaL_Reg lovrSkybox[] = {
|
|||
};
|
||||
|
||||
int l_lovrSkyboxDraw(lua_State* L) {
|
||||
Skybox* skybox = luax_checkskybox(L, 1);
|
||||
Skybox* skybox = luax_checktype(L, 1, Skybox);
|
||||
float angle = luaL_optnumber(L, 2, 0.f);
|
||||
float ax = luaL_optnumber(L, 3, 0.f);
|
||||
float ay = luaL_optnumber(L, 4, 0.f);
|
||||
|
|
|
@ -4,8 +4,5 @@
|
|||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
|
||||
void luax_pushskybox(lua_State* L, Skybox* skybox);
|
||||
Skybox* luax_checkskybox(lua_State* L, int index);
|
||||
extern const luaL_Reg lovrSkybox[];
|
||||
|
||||
int l_lovrSkyboxDraw(lua_State* L);
|
||||
|
|
|
@ -2,22 +2,6 @@
|
|||
#include "lovr/graphics.h"
|
||||
#include "util.h"
|
||||
|
||||
void luax_pushtexture(lua_State* L, Texture* texture) {
|
||||
if (texture == NULL) {
|
||||
lua_pushnil(L);
|
||||
return;
|
||||
}
|
||||
|
||||
Texture** userdata = (Texture**) lua_newuserdata(L, sizeof(Texture*));
|
||||
luaL_getmetatable(L, "Texture");
|
||||
lua_setmetatable(L, -2);
|
||||
*userdata = texture;
|
||||
}
|
||||
|
||||
Texture* luax_checktexture(lua_State* L, int index) {
|
||||
return *(Texture**) luaL_checkudata(L, index, "Texture");
|
||||
}
|
||||
|
||||
const luaL_Reg lovrTexture[] = {
|
||||
{ "bind", l_lovrTextureBind },
|
||||
{ "refresh", l_lovrTextureRefresh },
|
||||
|
@ -32,26 +16,26 @@ const luaL_Reg lovrTexture[] = {
|
|||
};
|
||||
|
||||
int l_lovrTextureBind(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
lovrTextureBind(texture);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrTextureRefresh(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
lovrTextureRefresh(texture);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrTextureGetDimensions(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
lua_pushnumber(L, lovrTextureGetWidth(texture));
|
||||
lua_pushnumber(L, lovrTextureGetHeight(texture));
|
||||
return 2;
|
||||
}
|
||||
|
||||
int l_lovrTextureGetFilter(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
FilterMode min, mag;
|
||||
lovrTextureGetFilter(texture, &min, &mag);
|
||||
lua_pushstring(L, map_int_find(&FilterModes, min));
|
||||
|
@ -60,19 +44,19 @@ int l_lovrTextureGetFilter(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrTextureGetHeight(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
lua_pushnumber(L, lovrTextureGetHeight(texture));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrTextureGetWidth(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
lua_pushnumber(L, lovrTextureGetWidth(texture));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrTextureGetWrap(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
WrapMode horizontal, vertical;
|
||||
lovrTextureGetWrap(texture, &horizontal, &vertical);
|
||||
lua_pushstring(L, map_int_find(&WrapModes, horizontal));
|
||||
|
@ -81,7 +65,7 @@ int l_lovrTextureGetWrap(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrTextureSetFilter(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
FilterMode* min = (FilterMode*) luax_checkenum(L, 2, &FilterModes, "filter mode");
|
||||
FilterMode* mag = (FilterMode*) luax_optenum(L, 3, luaL_checkstring(L, 2), &FilterModes, "filter mode");
|
||||
lovrTextureSetFilter(texture, *min, *mag);
|
||||
|
@ -89,7 +73,7 @@ int l_lovrTextureSetFilter(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrTextureSetWrap(lua_State* L) {
|
||||
Texture* texture = luax_checktexture(L, 1);
|
||||
Texture* texture = luax_checktype(L, 1, Texture);
|
||||
WrapMode* horizontal = (WrapMode*) luax_checkenum(L, 2, &WrapModes, "wrap mode");
|
||||
WrapMode* vertical = (WrapMode*) luax_optenum(L, 3, luaL_checkstring(L, 2), &WrapModes, "wrap mode");
|
||||
lovrTextureSetWrap(texture, *horizontal, *vertical);
|
||||
|
|
|
@ -3,10 +3,7 @@
|
|||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
|
||||
void luax_pushtexture(lua_State* L, Texture* texture);
|
||||
Texture* luax_checktexture(lua_State* L, int index);
|
||||
extern const luaL_Reg lovrTexture[];
|
||||
|
||||
int l_lovrTextureBind(lua_State* L);
|
||||
int l_lovrTextureRefresh(lua_State* L);
|
||||
int l_lovrTextureGetDimensions(lua_State* L);
|
||||
|
|
Loading…
Reference in New Issue