raylua v3.0b 😎

Add support of asset loading from payload. (filesystem override)
Update raylib.
This commit is contained in:
TSnake41 2020-04-10 21:32:36 +02:00
parent 0066987f84
commit 3d7a4ceaf0
4 changed files with 66 additions and 7 deletions

2
raylib

@ -1 +1 @@
Subproject commit 62b7064e903fa04a403282ff2af55856da3e037d
Subproject commit 91e36777625b6d808e31fc2eb46a5519054bd801

View File

@ -16,7 +16,7 @@
local load = loadstring
raylua.version = "v3.0a"
raylua.version = "v3.0b"
function raylua.repl()
print("> raylua " .. raylua.version .. " <")

View File

@ -23,6 +23,8 @@
#include <lualib.h>
#include <lauxlib.h>
#include <raylib.h>
#include "raylua.h"
#include "lib/miniz.h"
@ -51,13 +53,12 @@ int raylua_loadfile(lua_State *L)
}
size_t size = stat.m_uncomp_size;
char *buffer = malloc(size + 1);
char *buffer = malloc(size);
if (buffer == NULL) {
lua_pushnil(L);
lua_pushfstring(L, "%s: Can't allocate file buffer.", path);
return 2;
}
buffer[size] = '\0';
mz_zip_reader_extract_to_mem(&zip_file, index, buffer, size, 0);
@ -66,6 +67,60 @@ int raylua_loadfile(lua_State *L)
return 1;
}
unsigned char *raylua_loadFileData(const char *path, unsigned int *out_size)
{
int index = mz_zip_reader_locate_file(&zip_file, path, NULL, 0);
if (index == -1) {
printf("RAYLUA: WARN: File not found in payload : '%s'", path);
return NULL;
}
mz_zip_archive_file_stat stat;
if (!mz_zip_reader_file_stat(&zip_file, index, &stat)) {
printf("RAYLUA: WARN: Can't get file information of '%s' in payload.", path);
return NULL;
}
size_t size = stat.m_uncomp_size;
unsigned char *buffer = RL_MALLOC(size);
if (buffer == NULL) {
printf("RAYLUA: WARN: Can't allocate file buffer for '%s'.", path);
return NULL;
}
mz_zip_reader_extract_to_mem(&zip_file, index, buffer, size, 0);
*out_size = size;
return buffer;
}
char *raylua_loadFileText(const char *path)
{
int index = mz_zip_reader_locate_file(&zip_file, path, NULL, 0);
if (index == -1) {
printf("RAYLUA: WARN: File not found in payload : '%s'", path);
return NULL;
}
mz_zip_archive_file_stat stat;
if (!mz_zip_reader_file_stat(&zip_file, index, &stat)) {
printf("RAYLUA: WARN: Can't get file information of '%s' in payload.", path);
return NULL;
}
size_t size = stat.m_uncomp_size;
char *buffer = RL_MALLOC(size + 1);
if (buffer == NULL) {
printf("RAYLUA: WARN: Can't allocate file buffer for '%s'.", path);
return NULL;
}
buffer[size] = '\0';
mz_zip_reader_extract_to_mem(&zip_file, index, buffer, size, 0);
return buffer;
}
static bool raylua_init_payload(const char *path)
{
mz_zip_zero_struct(&zip_file);
@ -109,6 +164,11 @@ int main(int argc, const char **argv)
}
#endif
SetFilesystemOverride((FilesystemOverride){
.loadFileData = &raylua_loadFileData,
.loadFileText = &raylua_loadFileText,
});
if (!raylua_init_payload(path)) {
#ifdef RAYLUA_NO_BUILDER
puts("RAYLUA: No payload.");

View File

@ -181,7 +181,6 @@ bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius);
bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3);
Image LoadImage(const char *fileName);
Image LoadImageEx(Color *pixels, int width, int height);
Image LoadImagePro(void *data, int width, int height, int format);
Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize);
void ExportImage(Image image, const char *fileName);
void ExportImageAsCode(Image image, const char *fileName);
@ -228,8 +227,8 @@ void ImageDrawCircle(Image *dst, int centerX, int centerY, int radius, Color col
void ImageDrawCircleV(Image *dst, Vector2 center, int radius, Color color);
void ImageDrawLine(Image *dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color);
void ImageDrawLineV(Image *dst, Vector2 start, Vector2 end, Color color);
void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color);
void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, float fontSize, float spacing, Color color);
void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSize, Color color);
void ImageDrawTextEx(Image *dst, Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint);
void ImageFlipVertical(Image *image);
void ImageFlipHorizontal(Image *image);
void ImageRotateCW(Image *image);