Updated Lua binding

This commit is contained in:
raysan5 2016-08-04 13:40:53 +02:00
parent 055d501345
commit 80789e6140

View File

@ -15,7 +15,7 @@
* local x2 = rec.x + rec.width * local x2 = rec.x + rec.width
* *
* The following types: * The following types:
* Image, Texture2D, SpriteFont * Image, Texture2D, RenderTexture2D, SpriteFont
* are immutable, and you can only read their non-pointer arguments (e.g. sprfnt.size). * are immutable, and you can only read their non-pointer arguments (e.g. sprfnt.size).
* *
* All other object types are opaque, that is, you cannot access or * All other object types are opaque, that is, you cannot access or
@ -126,9 +126,11 @@ RLUADEF void CloseLuaDevice(void); // De-initialize Lua system
#define LuaPush_SpriteFont(L, sf) LuaPushOpaqueTypeWithMetatable(L, sf, SpriteFont) #define LuaPush_SpriteFont(L, sf) LuaPushOpaqueTypeWithMetatable(L, sf, SpriteFont)
#define LuaPush_Mesh(L, vd) LuaPushOpaqueType(L, vd) #define LuaPush_Mesh(L, vd) LuaPushOpaqueType(L, vd)
#define LuaPush_Shader(L, s) LuaPushOpaqueType(L, s) #define LuaPush_Shader(L, s) LuaPushOpaqueType(L, s)
#define LuaPush_Light(L, light) LuaPushOpaqueType(L, light)
#define LuaPush_Sound(L, snd) LuaPushOpaqueType(L, snd) #define LuaPush_Sound(L, snd) LuaPushOpaqueType(L, snd)
#define LuaPush_Wave(L, wav) LuaPushOpaqueType(L, wav) #define LuaPush_Wave(L, wav) LuaPushOpaqueType(L, wav)
#define LuaPush_Music(L, mus) LuaPushOpaqueType(L, mus) #define LuaPush_Music(L, mus) LuaPushOpaqueType(L, mus)
#define LuaPush_AudioStream(L, aud) LuaPushOpaqueType(L, aud)
#define LuaGetArgument_string luaL_checkstring #define LuaGetArgument_string luaL_checkstring
#define LuaGetArgument_int (int)luaL_checkinteger #define LuaGetArgument_int (int)luaL_checkinteger
@ -142,9 +144,11 @@ RLUADEF void CloseLuaDevice(void); // De-initialize Lua system
#define LuaGetArgument_SpriteFont(L, sf) *(SpriteFont*)LuaGetArgumentOpaqueTypeWithMetatable(L, sf, "SpriteFont") #define LuaGetArgument_SpriteFont(L, sf) *(SpriteFont*)LuaGetArgumentOpaqueTypeWithMetatable(L, sf, "SpriteFont")
#define LuaGetArgument_Mesh(L, vd) *(Mesh*)LuaGetArgumentOpaqueType(L, vd) #define LuaGetArgument_Mesh(L, vd) *(Mesh*)LuaGetArgumentOpaqueType(L, vd)
#define LuaGetArgument_Shader(L, s) *(Shader*)LuaGetArgumentOpaqueType(L, s) #define LuaGetArgument_Shader(L, s) *(Shader*)LuaGetArgumentOpaqueType(L, s)
#define LuaGetArgument_Light(L, light) *(Light*)LuaGetArgumentOpaqueType(L, light)
#define LuaGetArgument_Sound(L, snd) *(Sound*)LuaGetArgumentOpaqueType(L, snd) #define LuaGetArgument_Sound(L, snd) *(Sound*)LuaGetArgumentOpaqueType(L, snd)
#define LuaGetArgument_Wave(L, wav) *(Wave*)LuaGetArgumentOpaqueType(L, wav) #define LuaGetArgument_Wave(L, wav) *(Wave*)LuaGetArgumentOpaqueType(L, wav)
#define LuaGetArgument_Music(L, mus) *(Music*)LuaGetArgumentOpaqueType(L, mus) #define LuaGetArgument_Music(L, mus) *(Music*)LuaGetArgumentOpaqueType(L, mus)
#define LuaGetArgument_AudioStream(L, aud) *(AudioStream*)LuaGetArgumentOpaqueType(L, aud)
#define LuaPushOpaqueType(L, str) LuaPushOpaque(L, &str, sizeof(str)) #define LuaPushOpaqueType(L, str) LuaPushOpaque(L, &str, sizeof(str))
#define LuaPushOpaqueTypeWithMetatable(L, str, meta) LuaPushOpaqueWithMetatable(L, &str, sizeof(str), #meta) #define LuaPushOpaqueTypeWithMetatable(L, str, meta) LuaPushOpaqueWithMetatable(L, &str, sizeof(str), #meta)
@ -263,7 +267,18 @@ static int LuaIndexTexture2D(lua_State* L)
return 1; return 1;
} }
// TODO: Build opaque metatable for RenderTexture2D? static int LuaIndexRenderTexture2D(lua_State* L)
{
RenderTexture2D img = LuaGetArgument_RenderTexture2D(L, 1);
const char *key = luaL_checkstring(L, 2);
if (!strcmp(key, "texture"))
LuaPush_Texture2D(L, img.texture);
else if (!strcmp(key, "depth"))
LuaPush_Texture2D(L, img.depth);
else
return 0;
return 1;
}
static int LuaIndexSpriteFont(lua_State* L) static int LuaIndexSpriteFont(lua_State* L)
{ {
@ -292,13 +307,11 @@ static void LuaBuildOpaqueMetatables(void)
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");
lua_pop(L, 1); lua_pop(L, 1);
// TODO: Build opaque metatable for RenderTexture2D?
/*
luaL_newmetatable(L, "RenderTexture2D"); luaL_newmetatable(L, "RenderTexture2D");
lua_pushcfunction(L, &LuaIndexRenderTexture2D); lua_pushcfunction(L, &LuaIndexRenderTexture2D);
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");
lua_pop(L, 1); lua_pop(L, 1);
*/
luaL_newmetatable(L, "SpriteFont"); luaL_newmetatable(L, "SpriteFont");
lua_pushcfunction(L, &LuaIndexSpriteFont); lua_pushcfunction(L, &LuaIndexSpriteFont);
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");
@ -403,10 +416,6 @@ static Camera2D LuaGetArgument_Camera2D(lua_State* L, int index)
return result; return result;
} }
// TODO: LightData, *Light
// TODO: MusicData *Music;
// TODO: AudioStream
static BoundingBox LuaGetArgument_BoundingBox(lua_State* L, int index) static BoundingBox LuaGetArgument_BoundingBox(lua_State* L, int index)
{ {
BoundingBox result; BoundingBox result;
@ -649,6 +658,23 @@ static int lua_Vector3(lua_State* L)
return 1; return 1;
} }
static int lua_Quaternion(lua_State* L)
{
LuaPush_Quaternion(L, (Quaternion) { (float)luaL_checknumber(L, 1), (float)luaL_checknumber(L, 2), (float)luaL_checknumber(L, 3), (float)luaL_checknumber(L, 4) });
return 1;
}
/*
static int lua_Matrix(lua_State* L)
{
LuaPush_Matrix(L, (Matrix) { (float)luaL_checknumber(L, 1), (float)luaL_checknumber(L, 2), (float)luaL_checknumber(L, 3), (float)luaL_checknumber(L, 4),
(float)luaL_checknumber(L, 5), (float)luaL_checknumber(L, 6), (float)luaL_checknumber(L, 7), (float)luaL_checknumber(L, 8),
(float)luaL_checknumber(L, 9), (float)luaL_checknumber(L, 10), (float)luaL_checknumber(L, 11), (float)luaL_checknumber(L, 12),
(float)luaL_checknumber(L, 13), (float)luaL_checknumber(L, 14), (float)luaL_checknumber(L, 15), (float)luaL_checknumber(L, 16) });
return 1;
}
*/
static int lua_Rectangle(lua_State* L) static int lua_Rectangle(lua_State* L)
{ {
LuaPush_Rectangle(L, (Rectangle) { (int)luaL_checkinteger(L, 1), (int)luaL_checkinteger(L, 2), (int)luaL_checkinteger(L, 3), (int)luaL_checkinteger(L, 4) }); LuaPush_Rectangle(L, (Rectangle) { (int)luaL_checkinteger(L, 1), (int)luaL_checkinteger(L, 2), (int)luaL_checkinteger(L, 3), (int)luaL_checkinteger(L, 4) });
@ -663,6 +689,14 @@ static int lua_Ray(lua_State* L)
return 1; return 1;
} }
static int lua_BoundingBox(lua_State* L)
{
Vector3 min = LuaGetArgument_Vector3(L, 1);
Vector3 max = LuaGetArgument_Vector3(L, 2);
LuaPush_BoundingBox(L, (BoundingBox) { { min.x, min.y }, { max.x, max.y } });
return 1;
}
static int lua_Camera(lua_State* L) static int lua_Camera(lua_State* L)
{ {
Vector3 pos = LuaGetArgument_Vector3(L, 1); Vector3 pos = LuaGetArgument_Vector3(L, 1);
@ -683,6 +717,22 @@ static int lua_Camera2D(lua_State* L)
return 1; return 1;
} }
/*
// NOTE: does it make sense to have this constructor? Probably not...
static int lua_Material(lua_State* L)
{
Shader sdr = LuaGetArgument_Shader(L, 1);
Texture2D td = LuaGetArgument_Texture2D(L, 2);
Texture2D tn = LuaGetArgument_Texture2D(L, 3);
Texture2D ts = LuaGetArgument_Texture2D(L, 4);
Color cd = LuaGetArgument_Color(L, 5);
Color ca = LuaGetArgument_Color(L, 6);
Color cs = LuaGetArgument_Color(L, 7);
float gloss = LuaGetArgument_float(L, 8);
LuaPush_Material(L, (Material) { sdr, td, tn, ts cd, ca, cs, gloss });
return 1;
}
*/
/************************************************************************************* /*************************************************************************************
* raylib Lua Functions Bindings * raylib Lua Functions Bindings
@ -914,12 +964,47 @@ int lua_GetHexValue(lua_State* L)
return 1; return 1;
} }
// TODO: int lua_ColorToFloat(lua_State* L)
/* {
float *ColorToFloat(Color color); // Converts Color to float array and normalizes Color arg1 = LuaGetArgument_Color(L, 1);
float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array float * result = ColorToFloat(arg1);
float *MatrixToFloat(Matrix mat); // Converts Matrix to float array lua_createtable(L, 4, 0);
*/ for (int i = 0; i < 4; i++)
{
lua_pushnumber(L, result[i]);
lua_rawseti(L, -2, i + 1);
}
free(result);
return 1;
}
int lua_VectorToFloat(lua_State* L)
{
Vector3 arg1 = LuaGetArgument_Vector3(L, 1);
float * result = VectorToFloat(arg1);
lua_createtable(L, 3, 0);
for (int i = 0; i < 3; i++)
{
lua_pushnumber(L, result[i]);
lua_rawseti(L, -2, i + 1);
}
free(result);
return 1;
}
int lua_MatrixToFloat(lua_State* L)
{
Matrix arg1 = LuaGetArgument_Matrix(L, 1);
float * result = MatrixToFloat(arg1);
lua_createtable(L, 16, 0);
for (int i = 0; i < 16; i++)
{
lua_pushnumber(L, result[i]);
lua_rawseti(L, -2, i + 1);
}
free(result);
return 1;
}
int lua_GetRandomValue(lua_State* L) int lua_GetRandomValue(lua_State* L)
{ {
@ -1227,8 +1312,6 @@ int lua_IsGestureDetected(lua_State* L)
return 1; return 1;
} }
// TODO: void ProcessGestureEvent(GestureEvent event);
int lua_UpdateGestures(lua_State* L) int lua_UpdateGestures(lua_State* L)
{ {
UpdateGestures(); UpdateGestures();
@ -1704,7 +1787,7 @@ int lua_LoadTexture(lua_State* L)
int lua_LoadTextureEx(lua_State* L) int lua_LoadTextureEx(lua_State* L)
{ {
void * arg1 = LuaGetArgument_string(L, 1); // NOTE: getting argument as string void * arg1 = (char *)LuaGetArgument_string(L, 1); // NOTE: getting argument as string
int arg2 = LuaGetArgument_int(L, 2); int arg2 = LuaGetArgument_int(L, 2);
int arg3 = LuaGetArgument_int(L, 3); int arg3 = LuaGetArgument_int(L, 3);
int arg4 = LuaGetArgument_int(L, 4); int arg4 = LuaGetArgument_int(L, 4);
@ -1800,26 +1883,172 @@ int lua_ImageFormat(lua_State* L)
return 1; return 1;
} }
// TODO: int lua_ImageDither(lua_State* L)
/* {
void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) Image arg1 = LuaGetArgument_Image(L, 1);
Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) int arg2 = LuaGetArgument_int(L, 2);
void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle int arg3 = LuaGetArgument_int(L, 3);
void ImageResize(Image *image, int newWidth, int newHeight); // Resize and image (bilinear filtering) int arg4 = LuaGetArgument_int(L, 4);
void ImageResizeNN(Image *image,int newWidth,int newHeight); // Resize and image (Nearest-Neighbor scaling algorithm) int arg5 = LuaGetArgument_int(L, 5);
Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) ImageDither(&arg1, arg2, arg3, arg4, arg5);
Image ImageTextEx(SpriteFont font, const char *text, int fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) LuaPush_Image(L, arg1);
void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image return 1;
void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) }
void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, int fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination)
void ImageFlipVertical(Image *image); // Flip image vertically int lua_ImageCopy(lua_State* L)
void ImageFlipHorizontal(Image *image); // Flip image horizontally {
void ImageColorTint(Image *image, Color color); // Modify image color: tint Image arg1 = LuaGetArgument_Image(L, 1);
void ImageColorInvert(Image *image); // Modify image color: invert Image result = ImageCopy(arg1);
void ImageColorGrayscale(Image *image); // Modify image color: grayscale LuaPush_Image(L, result);
void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100) return 1;
void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) }
*/
int lua_ImageCrop(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
Rectangle arg2 = LuaGetArgument_Rectangle(L, 2);
ImageCrop(&arg1, arg2);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageResize(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
int arg2 = LuaGetArgument_int(L, 2);
int arg3 = LuaGetArgument_int(L, 3);
ImageResize(&arg1, arg2, arg3);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageResizeNN(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
int arg2 = LuaGetArgument_int(L, 2);
int arg3 = LuaGetArgument_int(L, 3);
ImageResizeNN(&arg1, arg2, arg3);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageText(lua_State* L)
{
const char * arg1 = LuaGetArgument_string(L, 1);
int arg2 = LuaGetArgument_int(L, 2);
Color arg3 = LuaGetArgument_Color(L, 3);
Image result = ImageText(arg1, arg2, arg3);
LuaPush_Image(L, result);
return 1;
}
int lua_ImageTextEx(lua_State* L)
{
SpriteFont arg1 = LuaGetArgument_SpriteFont(L, 1);
const char * arg2 = LuaGetArgument_string(L, 2);
int arg3 = LuaGetArgument_int(L, 3);
int arg4 = LuaGetArgument_int(L, 4);
Color arg5 = LuaGetArgument_Color(L, 5);
Image result = ImageTextEx(arg1, arg2, arg3, arg4, arg5);
LuaPush_Image(L, result);
return 1;
}
int lua_ImageDraw(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
Image arg2 = LuaGetArgument_Image(L, 2);
Rectangle arg3 = LuaGetArgument_Rectangle(L, 3);
Rectangle arg4 = LuaGetArgument_Rectangle(L, 4);
ImageDraw(&arg1, arg2, arg3, arg4);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageDrawText(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
Vector2 arg2 = LuaGetArgument_Vector2(L, 2);
const char * arg3 = LuaGetArgument_string(L, 3);
int arg4 = LuaGetArgument_int(L, 4);
Color arg5 = LuaGetArgument_Color(L, 5);
ImageDrawText(&arg1, arg2, arg3, arg4, arg5);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageDrawTextEx(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
Vector2 arg2 = LuaGetArgument_Vector2(L, 2);
SpriteFont arg3 = LuaGetArgument_SpriteFont(L, 3);
const char * arg4 = LuaGetArgument_string(L, 4);
int arg5 = LuaGetArgument_int(L, 5);
int arg6 = LuaGetArgument_int(L, 6);
Color arg7 = LuaGetArgument_Color(L, 7);
ImageDrawTextEx(&arg1, arg2, arg3, arg4, arg5, arg6, arg7);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageFlipVertical(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
ImageFlipVertical(&arg1);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageFlipHorizontal(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
ImageFlipHorizontal(&arg1);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageColorTint(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
Color arg2 = LuaGetArgument_Color(L, 2);
ImageColorTint(&arg1, arg2);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageColorInvert(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
ImageColorInvert(&arg1);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageColorGrayscale(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
ImageColorGrayscale(&arg1);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageColorContrast(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
float arg2 = LuaGetArgument_float(L, 2);
ImageColorContrast(&arg1, arg2);
LuaPush_Image(L, arg1);
return 1;
}
int lua_ImageColorBrightness(lua_State* L)
{
Image arg1 = LuaGetArgument_Image(L, 1);
int arg2 = LuaGetArgument_int(L, 2);
ImageColorBrightness(&arg1, arg2);
LuaPush_Image(L, arg1);
return 1;
}
int lua_GenTextureMipmaps(lua_State* L) int lua_GenTextureMipmaps(lua_State* L)
{ {
@ -1831,7 +2060,7 @@ int lua_GenTextureMipmaps(lua_State* L)
int lua_UpdateTexture(lua_State* L) int lua_UpdateTexture(lua_State* L)
{ {
Texture2D arg1 = LuaGetArgument_Texture2D(L, 1); Texture2D arg1 = LuaGetArgument_Texture2D(L, 1);
void * arg2 = LuaGetArgument_string(L, 2); // NOTE: Getting (void *) as string void * arg2 = (char *)LuaGetArgument_string(L, 2); // NOTE: Getting (void *) as string?
UpdateTexture(arg1, arg2); UpdateTexture(arg1, arg2);
return 0; return 0;
} }
@ -2097,12 +2326,27 @@ int lua_DrawGizmo(lua_State* L)
return 0; return 0;
} }
// TODO: // TODO: DrawLight(Light light);
/*
void DrawLight(Light light); // Draw light in 3D world int lua_Draw3DLine(lua_State* L)
void Draw3DLine(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space {
void Draw3DCircle(Vector3 center, float radius, float rotationAngle, Vector3 rotation, Color color); // Draw a circle in 3D world space Vector3 arg1 = LuaGetArgument_Vector3(L, 1);
*/ Vector3 arg2 = LuaGetArgument_Vector3(L, 2);
Color arg3 = LuaGetArgument_Color(L, 3);
Draw3DLine(arg1, arg2, arg3);
return 0;
}
int lua_Draw3DCircle(lua_State* L)
{
Vector3 arg1 = LuaGetArgument_Vector3(L, 1);
float arg2 = LuaGetArgument_float(L, 2);
float arg3 = LuaGetArgument_float(L, 3);
Vector3 arg4 = LuaGetArgument_Vector3(L, 4);
Color arg5 = LuaGetArgument_Color(L, 5);
Draw3DCircle(arg1, arg2, arg3, arg4, arg5);
return 0;
}
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// raylib [models] module functions // raylib [models] module functions
@ -2287,19 +2531,42 @@ int lua_CheckCollisionBoxSphere(lua_State* L)
{ {
BoundingBox arg1 = LuaGetArgument_BoundingBox(L, 1); BoundingBox arg1 = LuaGetArgument_BoundingBox(L, 1);
Vector3 arg2 = LuaGetArgument_Vector3(L, 2); Vector3 arg2 = LuaGetArgument_Vector3(L, 2);
float arg3 = LuaGetArgument_float(L, 4); float arg3 = LuaGetArgument_float(L, 3);
bool result = CheckCollisionBoxSphere(arg1, arg2, arg3); bool result = CheckCollisionBoxSphere(arg1, arg2, arg3);
lua_pushboolean(L, result); lua_pushboolean(L, result);
return 1; return 1;
} }
// TODO: int lua_CheckCollisionRaySphere(lua_State* L)
/* {
bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere Ray arg1 = LuaGetArgument_Ray(L, 1);
bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere with extended parameters and collision point detection Vector3 arg2 = LuaGetArgument_Vector3(L, 2);
bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box float arg3 = LuaGetArgument_float(L, 3);
Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Detect collision of player radius with cubicmap bool result = CheckCollisionRaySphere(arg1, arg2, arg3);
*/ lua_pushboolean(L, result);
return 1;
}
int lua_CheckCollisionRaySphereEx(lua_State* L)
{
Ray arg1 = LuaGetArgument_Ray(L, 1);
Vector3 arg2 = LuaGetArgument_Vector3(L, 2);
float arg3 = LuaGetArgument_float(L, 3);
Vector3 arg4 = LuaGetArgument_Vector3(L, 4);
bool result = CheckCollisionRaySphereEx(arg1, arg2, arg3, &arg4);
lua_pushboolean(L, result);
LuaPush_Vector3(L, arg4);
return 2;
}
int lua_CheckCollisionRayBox(lua_State* L)
{
Ray arg1 = LuaGetArgument_Ray(L, 1);
BoundingBox arg2 = LuaGetArgument_BoundingBox(L, 2);
bool result = CheckCollisionRayBox(arg1, arg2);
lua_pushboolean(L, result);
return 1;
}
int lua_ResolveCollisionCubicmap(lua_State* L) int lua_ResolveCollisionCubicmap(lua_State* L)
{ {
@ -2431,23 +2698,55 @@ int lua_EndBlendMode(lua_State* L)
return 0; return 0;
} }
// TODO: // TODO: Light CreateLight(int type, Vector3 position, Color diffuse);
//Light CreateLight(int type, Vector3 position, Color diffuse); // Create a new light, initialize it and add to pool // TODO: void DestroyLight(Light light);
//void DestroyLight(Light light); // Destroy a light and take it out of the list
// TODO:
/*
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// raylib [rlgl] module functions - VR experience // raylib [rlgl] module functions - VR experience
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
void InitVrDevice(int vdDevice); // Init VR device int lua_InitVrDevice(lua_State* L)
void CloseVrDevice(void); // Close VR device {
void UpdateVrTracking(void); // Update VR tracking (position and orientation) int arg1 = LuaGetArgument_int(L, 1);
void BeginVrDrawing(void); // Begin VR drawing configuration InitVrDevice(arg1);
void EndVrDrawing(void); // End VR drawing process (and desktop mirror) return 0;
bool IsVrDeviceReady(void); // Detect if VR device (or simulator) is ready }
void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator)
*/ int lua_CloseVrDevice(lua_State* L)
{
CloseVrDevice();
return 0;
}
int lua_UpdateVrTracking(lua_State* L)
{
UpdateVrTracking();
return 0;
}
int lua_BeginVrDrawing(lua_State* L)
{
BeginVrDrawing();
return 0;
}
int lua_EndVrDrawing(lua_State* L)
{
EndVrDrawing();
return 0;
}
int lua_IsVrDeviceReady(lua_State* L)
{
bool result = IsVrDeviceReady();
lua_pushboolean(L, result);
return 1;
}
int lua_ToggleVrMode(lua_State* L)
{
ToggleVrMode();
return 0;
}
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// raylib [audio] module functions - Audio Loading and Playing // raylib [audio] module functions - Audio Loading and Playing
@ -2570,6 +2869,13 @@ int lua_UnloadMusicStream(lua_State* L)
return 0; return 0;
} }
int lua_UpdateMusicStream(lua_State* L)
{
Music arg1 = LuaGetArgument_Music(L, 1);
UpdateMusicStream(arg1);
return 0;
}
int lua_PlayMusicStream(lua_State* L) int lua_PlayMusicStream(lua_State* L)
{ {
Music arg1 = LuaGetArgument_Music(L, 1); Music arg1 = LuaGetArgument_Music(L, 1);
@ -2577,12 +2883,6 @@ int lua_PlayMusicStream(lua_State* L)
return 0; return 0;
} }
int lua_UpdateMusicStream(lua_State* L)
{
Music arg1 = LuaGetArgument_Music(L, 1);
UpdateMusicStream(arg1);
return 0;
}
int lua_StopMusicStream(lua_State* L) int lua_StopMusicStream(lua_State* L)
{ {
@ -2621,6 +2921,14 @@ int lua_SetMusicVolume(lua_State* L)
return 0; return 0;
} }
int lua_SetMusicPitch(lua_State* L)
{
Music arg1 = LuaGetArgument_Music(L, 1);
float arg2 = LuaGetArgument_float(L, 2);
SetMusicPitch(arg1, arg2);
return 0;
}
int lua_GetMusicTimeLength(lua_State* L) int lua_GetMusicTimeLength(lua_State* L)
{ {
Music arg1 = LuaGetArgument_Music(L, 1); Music arg1 = LuaGetArgument_Music(L, 1);
@ -2637,19 +2945,68 @@ int lua_GetMusicTimePlayed(lua_State* L)
return 1; return 1;
} }
// TODO: int lua_InitAudioStream(lua_State* L)
/* {
AudioStream InitAudioStream(unsigned int sampleRate, int arg1 = LuaGetArgument_int(L, 1);
unsigned int sampleSize, int arg2 = LuaGetArgument_int(L, 2);
unsigned int channels); // Init audio stream (to stream audio pcm data) int arg3 = LuaGetArgument_int(L, 3);
void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data AudioStream result = InitAudioStream(arg1, arg2, arg3);
void CloseAudioStream(AudioStream stream); // Close audio stream and free memory LuaPush_AudioStream(L, result);
bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill return 1;
void PlayAudioStream(AudioStream stream); // Play audio stream }
void PauseAudioStream(AudioStream stream); // Pause audio stream
void ResumeAudioStream(AudioStream stream); // Resume audio stream int lua_CloseAudioStream(lua_State* L)
void StopAudioStream(AudioStream stream); // Stop audio stream {
*/ AudioStream arg1 = LuaGetArgument_AudioStream(L, 1);
CloseAudioStream(arg1);
return 0;
}
int lua_UpdateAudioStream(lua_State* L)
{
AudioStream arg1 = LuaGetArgument_AudioStream(L, 1);
void * arg2 = (char *)LuaGetArgument_string(L, 2);
int arg3 = LuaGetArgument_int(L, 3);
UpdateAudioStream(arg1, arg2, arg3);
return 0;
}
int lua_IsAudioBufferProcessed(lua_State* L)
{
AudioStream arg1 = LuaGetArgument_AudioStream(L, 1);
bool result = IsAudioBufferProcessed(arg1);
lua_pushboolean(L, result);
return 1;
}
int lua_PlayAudioStream(lua_State* L)
{
AudioStream arg1 = LuaGetArgument_AudioStream(L, 1);
PlayAudioStream(arg1);
return 0;
}
int lua_StopAudioStream(lua_State* L)
{
AudioStream arg1 = LuaGetArgument_AudioStream(L, 1);
StopAudioStream(arg1);
return 0;
}
int lua_PauseAudioStream(lua_State* L)
{
AudioStream arg1 = LuaGetArgument_AudioStream(L, 1);
PauseAudioStream(arg1);
return 0;
}
int lua_ResumeAudioStream(lua_State* L)
{
AudioStream arg1 = LuaGetArgument_AudioStream(L, 1);
ResumeAudioStream(arg1);
return 0;
}
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// raylib [utils] module functions // raylib [utils] module functions
@ -3114,29 +3471,49 @@ int lua_QuaternionTransform(lua_State* L)
// raylib Functions (and data types) list // raylib Functions (and data types) list
static luaL_Reg raylib_functions[] = { static luaL_Reg raylib_functions[] = {
// Register non-opaque data types
REG(Color) REG(Color)
REG(Vector2) REG(Vector2)
REG(Vector3) REG(Vector3)
//REG(Matrix)
REG(Quaternion)
REG(Rectangle) REG(Rectangle)
REG(Ray) REG(Ray)
REG(Camera) REG(Camera)
// TODO: Additional structs REG(Camera2D)
REG(BoundingBox)
//REG(Material)
// TODO: Review registered functions // Register functions
REG(InitWindow) REG(InitWindow)
REG(CloseWindow) REG(CloseWindow)
REG(WindowShouldClose) REG(WindowShouldClose)
REG(IsWindowMinimized) REG(IsWindowMinimized)
REG(ToggleFullscreen) REG(ToggleFullscreen)
REG(GetScreenWidth) REG(GetScreenWidth)
REG(GetScreenHeight) REG(GetScreenHeight)
REG(ShowCursor)
REG(HideCursor)
REG(IsCursorHidden)
REG(EnableCursor)
REG(DisableCursor)
REG(ClearBackground) REG(ClearBackground)
REG(BeginDrawing) REG(BeginDrawing)
REG(EndDrawing) REG(EndDrawing)
REG(Begin2dMode)
REG(End2dMode)
REG(Begin3dMode) REG(Begin3dMode)
REG(End3dMode) REG(End3dMode)
REG(BeginTextureMode)
REG(EndTextureMode)
REG(GetMouseRay) REG(GetMouseRay)
REG(GetWorldToScreen)
REG(GetCameraMatrix)
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
REG(SetDrawingLoop) REG(SetDrawingLoop)
#else #else
@ -3144,21 +3521,39 @@ static luaL_Reg raylib_functions[] = {
#endif #endif
REG(GetFPS) REG(GetFPS)
REG(GetFrameTime) REG(GetFrameTime)
REG(GetColor) REG(GetColor)
REG(GetHexValue) REG(GetHexValue)
REG(ColorToFloat)
REG(VectorToFloat)
REG(MatrixToFloat)
REG(GetRandomValue) REG(GetRandomValue)
REG(Fade) REG(Fade)
REG(SetConfigFlags) REG(SetConfigFlags)
REG(ShowLogo) REG(ShowLogo)
REG(IsFileDropped) REG(IsFileDropped)
//REG(*GetDroppedFiles) //REG(*GetDroppedFiles)
REG(ClearDroppedFiles) REG(ClearDroppedFiles)
REG(StorageSaveValue)
REG(StorageLoadValue)
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
REG(IsKeyPressed) REG(IsKeyPressed)
REG(IsKeyDown) REG(IsKeyDown)
REG(IsKeyReleased) REG(IsKeyReleased)
REG(IsKeyUp) REG(IsKeyUp)
REG(GetKeyPressed) REG(GetKeyPressed)
REG(SetExitKey)
REG(IsGamepadAvailable)
REG(GetGamepadAxisMovement)
REG(IsGamepadButtonPressed)
REG(IsGamepadButtonDown)
REG(IsGamepadButtonReleased)
REG(IsGamepadButtonUp)
#endif
REG(IsMouseButtonPressed) REG(IsMouseButtonPressed)
REG(IsMouseButtonDown) REG(IsMouseButtonDown)
REG(IsMouseButtonReleased) REG(IsMouseButtonReleased)
@ -3168,50 +3563,41 @@ static luaL_Reg raylib_functions[] = {
REG(GetMousePosition) REG(GetMousePosition)
REG(SetMousePosition) REG(SetMousePosition)
REG(GetMouseWheelMove) REG(GetMouseWheelMove)
REG(ShowCursor)
REG(HideCursor)
REG(IsCursorHidden)
#endif
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
REG(IsGamepadAvailable)
REG(IsGamepadButtonPressed)
REG(IsGamepadButtonDown)
REG(IsGamepadButtonReleased)
REG(IsGamepadButtonUp)
#endif
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
REG(GetTouchX) REG(GetTouchX)
REG(GetTouchY) REG(GetTouchY)
REG(GetTouchPosition) REG(GetTouchPosition)
#if defined(PLATFORM_WEB)
REG(InitGesturesSystem) #if defined(PLATFORM_ANDROID)
#elif defined(PLATFORM_ANDROID) REG(IsButtonPressed)
//REG(InitGesturesSystem) REG(IsButtonDown)
REG(IsButtonReleased)
#endif #endif
REG(UpdateGestures)
REG(IsGestureDetected)
REG(GetGestureType)
REG(SetGesturesEnabled) REG(SetGesturesEnabled)
REG(GetGestureDragIntensity) REG(IsGestureDetected)
REG(GetGestureDragAngle) //REG(ProcessGestureEvent)
REG(GetGestureDragVector) REG(UpdateGestures)
REG(GetTouchPointsCount)
REG(GetGestureDetected)
REG(GetGestureHoldDuration) REG(GetGestureHoldDuration)
REG(GetGesturePinchDelta) REG(GetGestureDragVector)
REG(GetGestureDragAngle)
REG(GetGesturePinchVector)
REG(GetGesturePinchAngle) REG(GetGesturePinchAngle)
#endif
REG(SetCameraMode) REG(SetCameraMode)
REG(UpdateCamera) REG(UpdateCamera)
REG(UpdateCameraPlayer) REG(UpdateCameraPlayer)
REG(SetCameraPosition) REG(SetCameraPosition)
REG(SetCameraTarget) REG(SetCameraTarget)
REG(SetCameraFovy)
REG(SetCameraPanControl) REG(SetCameraPanControl)
REG(SetCameraAltControl) REG(SetCameraAltControl)
REG(SetCameraSmoothZoomControl) REG(SetCameraSmoothZoomControl)
REG(SetCameraMoveControls) REG(SetCameraMoveControls)
REG(SetCameraMouseSensitivity) REG(SetCameraMouseSensitivity)
REG(DrawPixel) REG(DrawPixel)
REG(DrawPixelV) REG(DrawPixelV)
REG(DrawLine) REG(DrawLine)
@ -3230,6 +3616,7 @@ static luaL_Reg raylib_functions[] = {
REG(DrawPoly) REG(DrawPoly)
REG(DrawPolyEx) REG(DrawPolyEx)
REG(DrawPolyExLines) REG(DrawPolyExLines)
REG(CheckCollisionRecs) REG(CheckCollisionRecs)
REG(CheckCollisionCircles) REG(CheckCollisionCircles)
REG(CheckCollisionCircleRec) REG(CheckCollisionCircleRec)
@ -3237,25 +3624,48 @@ static luaL_Reg raylib_functions[] = {
REG(CheckCollisionPointRec) REG(CheckCollisionPointRec)
REG(CheckCollisionPointCircle) REG(CheckCollisionPointCircle)
REG(CheckCollisionPointTriangle) REG(CheckCollisionPointTriangle)
REG(LoadImage) REG(LoadImage)
REG(LoadImageEx) REG(LoadImageEx)
REG(LoadImageRaw) REG(LoadImageRaw)
REG(LoadImageFromRES) REG(LoadImageFromRES)
REG(LoadTexture) REG(LoadTexture)
REG(LoadTextureEx)
REG(LoadTextureFromRES) REG(LoadTextureFromRES)
REG(LoadTextureFromImage) REG(LoadTextureFromImage)
REG(LoadRenderTexture)
REG(UnloadImage) REG(UnloadImage)
REG(UnloadTexture) REG(UnloadTexture)
REG(GetImageData) REG(GetImageData)
REG(GetTextureData) REG(GetTextureData)
REG(ImageToPOT) REG(ImageToPOT)
REG(ImageFormat) REG(ImageFormat)
REG(ImageDither)
REG(ImageCopy)
REG(ImageCrop)
REG(ImageResize)
REG(ImageResizeNN)
REG(ImageText)
REG(ImageTextEx)
REG(ImageDraw)
REG(ImageDrawText)
REG(ImageDrawTextEx)
REG(ImageFlipVertical)
REG(ImageFlipHorizontal)
REG(ImageColorTint)
REG(ImageColorInvert)
REG(ImageColorGrayscale)
REG(ImageColorContrast)
REG(ImageColorBrightness)
REG(GenTextureMipmaps) REG(GenTextureMipmaps)
REG(UpdateTexture)
REG(DrawTexture) REG(DrawTexture)
REG(DrawTextureV) REG(DrawTextureV)
REG(DrawTextureEx) REG(DrawTextureEx)
REG(DrawTextureRec) REG(DrawTextureRec)
REG(DrawTexturePro) REG(DrawTexturePro)
REG(GetDefaultFont) REG(GetDefaultFont)
REG(LoadSpriteFont) REG(LoadSpriteFont)
REG(UnloadSpriteFont) REG(UnloadSpriteFont)
@ -3264,6 +3674,9 @@ static luaL_Reg raylib_functions[] = {
REG(MeasureText) REG(MeasureText)
REG(MeasureTextEx) REG(MeasureTextEx)
REG(DrawFPS) REG(DrawFPS)
//REG(FormatText)
//REG(SubText)
REG(DrawCube) REG(DrawCube)
REG(DrawCubeV) REG(DrawCubeV)
REG(DrawCubeWires) REG(DrawCubeWires)
@ -3277,50 +3690,93 @@ static luaL_Reg raylib_functions[] = {
REG(DrawRay) REG(DrawRay)
REG(DrawGrid) REG(DrawGrid)
REG(DrawGizmo) REG(DrawGizmo)
REG(LoadModel) REG(LoadModel)
REG(LoadModelEx) REG(LoadModelEx)
REG(LoadModelFromRES)
REG(LoadHeightmap) REG(LoadHeightmap)
REG(LoadCubicmap) REG(LoadCubicmap)
REG(UnloadModel) REG(UnloadModel)
//REG(GenMesh*) // Not ready yet...
REG(DrawModel) REG(DrawModel)
REG(DrawModelEx) REG(DrawModelEx)
REG(DrawModelWires) REG(DrawModelWires)
REG(DrawModelWiresEx)
REG(DrawBillboard) REG(DrawBillboard)
REG(DrawBillboardRec) REG(DrawBillboardRec)
REG(CalculateBoundingBox)
REG(CheckCollisionSpheres) REG(CheckCollisionSpheres)
REG(CheckCollisionBoxes) REG(CheckCollisionBoxes)
REG(CheckCollisionBoxSphere) REG(CheckCollisionBoxSphere)
REG(CheckCollisionRaySphere)
REG(CheckCollisionRaySphereEx)
REG(CheckCollisionRayBox)
REG(ResolveCollisionCubicmap) REG(ResolveCollisionCubicmap)
REG(LoadShader) REG(LoadShader)
REG(UnloadShader) REG(UnloadShader)
REG(GetDefaultShader)
REG(GetStandardShader)
REG(GetDefaultTexture)
REG(GetShaderLocation) REG(GetShaderLocation)
REG(SetShaderValue) REG(SetShaderValue)
REG(SetShaderValuei) REG(SetShaderValuei)
REG(SetShaderValueMatrix)
REG(SetMatrixProjection)
REG(SetMatrixModelview)
REG(BeginShaderMode)
REG(EndShaderMode)
REG(BeginBlendMode) REG(BeginBlendMode)
REG(EndBlendMode) REG(EndBlendMode)
//REG(CreateLight)
//REG(DestroyLight)
REG(InitVrDevice)
REG(CloseVrDevice)
REG(UpdateVrTracking)
REG(BeginVrDrawing)
REG(EndVrDrawing)
REG(IsVrDeviceReady)
REG(ToggleVrMode)
REG(InitAudioDevice) REG(InitAudioDevice)
REG(CloseAudioDevice) REG(CloseAudioDevice)
REG(IsAudioDeviceReady)
REG(LoadSound) REG(LoadSound)
REG(LoadSoundFromWave) REG(LoadSoundFromWave)
REG(LoadSoundFromRES) REG(LoadSoundFromRES)
REG(UnloadSound) REG(UnloadSound)
REG(PlaySound) REG(PlaySound)
REG(PauseSound) REG(PauseSound)
REG(ResumeSound)
REG(StopSound) REG(StopSound)
REG(IsSoundPlaying) REG(IsSoundPlaying)
REG(SetSoundVolume) REG(SetSoundVolume)
REG(SetSoundPitch) REG(SetSoundPitch)
REG(PlayMusicStream)
REG(LoadMusicStream)
REG(UnloadMusicStream)
REG(UpdateMusicStream) REG(UpdateMusicStream)
REG(PlayMusicStream)
REG(StopMusicStream) REG(StopMusicStream)
REG(PauseMusicStream) REG(PauseMusicStream)
REG(ResumeMusicStream) REG(ResumeMusicStream)
REG(IsMusicPlaying) REG(IsMusicPlaying)
REG(SetMusicVolume) REG(SetMusicVolume)
REG(SetMusicPitch)
REG(GetMusicTimeLength) REG(GetMusicTimeLength)
REG(GetMusicTimePlayed) REG(GetMusicTimePlayed)
REG(InitAudioStream)
REG(UpdateAudioStream)
REG(CloseAudioStream)
REG(IsAudioBufferProcessed)
REG(PlayAudioStream)
REG(PauseAudioStream)
REG(ResumeAudioStream)
REG(StopAudioStream)
/// Math and util /// Math and util
REG(DecompressData) REG(DecompressData)
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)