Update binding

No longer use fork : Use Load*FromMemory where possible
Fix builder issues
Improve error handling (stacktrace)
This commit is contained in:
Astie Teddy 2020-09-17 17:37:13 +02:00
parent 0daa5e63ed
commit 2914f26360
9 changed files with 104 additions and 81 deletions

2
raylib

@ -1 +1 @@
Subproject commit be03613d1b6f9b0051d78c790f97df069150c65f
Subproject commit fa2c1146366557e5ce779d8b5c2575579dfa6389

View File

@ -14,9 +14,67 @@
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
]]
-- math metamethods
local new = ffi.new
-- Load*() wrappers.
if raylua.loadfile then
local LoadImage = rl.LoadImage
function rl.LoadImage(path)
local f, err = raylua.loadfile(path)
if f then
local ext = path:gsub(".+%.", "")
return rl.LoadImageFromMemory(ext, f, #f)
else
print(("RAYLUA: %s"):format(err))
return LoadImage(path)
end
end
function rl.LoadTexture(path)
return rl.LoadTextureFromImage(rl.LoadImage(path))
end
local LoadFont, LoadFontEx = rl.LoadFont, rl.LoadFontEx
function rl.LoadFontEx(path, sz, chars, count)
local f, err = raylua.loadfile(path)
if f then
local ext = path:gsub(".+%.", "")
return rl.LoadFontFromMemory(ext, f, #f, sz, chars, count)
else
return LoadFontEx(sz, chars, count)
end
end
function rl.LoadFont(path)
-- HACK: Hardcoded values (FONT_TTF_DEFAULT_SIZE,
-- FONT_TTF_DEFAULT_NUMCHARS)
return rl.LoadFontEx(path, 32, nil, 95)
end
local LoadWave = rl.LoadWave
function rl.LoadWave(path)
local f, err = raylua.loadfile(path)
if f then
local ext = path:gsub(".+%.", "")
return rl.LoadWaveFromMemory(ext, f, #f)
else
print(("RAYLUA: %s"):format(err))
return LoadWave(path)
end
end
function rl.LoadSound(path)
return rl.LoadSoundFromWave(rl.LoadWave(path))
end
end
-- math metamethods
ffi.metatype("Vector2", {
__add = function (a, b)
if ffi.istype("Vector2", b) then

View File

@ -92,7 +92,6 @@ ffi.cdef [[
unsigned int id;
Texture2D texture;
Texture2D depth;
bool depthTexture;
} RenderTexture2D;
typedef RenderTexture2D RenderTexture;
@ -188,9 +187,9 @@ ffi.cdef [[
Matrix transform;
int meshCount;
Mesh *meshes;
int materialCount;
Mesh *meshes;
Material *materials;
int *meshMaterial;
int boneCount;
@ -200,9 +199,9 @@ ffi.cdef [[
typedef struct ModelAnimation {
int boneCount;
BoneInfo *bones;
int frameCount;
BoneInfo *bones;
Transform **framePoses;
} ModelAnimation;
@ -233,26 +232,25 @@ ffi.cdef [[
typedef struct rAudioBuffer rAudioBuffer;
typedef struct AudioStream {
rAudioBuffer *buffer;
unsigned int sampleRate;
unsigned int sampleSize;
unsigned int channels;
rAudioBuffer *buffer;
} AudioStream;
typedef struct Sound {
unsigned int sampleCount;
AudioStream stream;
unsigned int sampleCount;
} Sound;
typedef struct Music {
AudioStream stream;
unsigned int sampleCount;
bool looping;
int ctxType;
void *ctxData;
bool looping;
unsigned int sampleCount;
AudioStream stream;
} Music;
typedef struct VrDeviceInfo {

View File

@ -68,8 +68,10 @@ void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles,
lua_setglobal(L, "raylua");
if (luaL_dostring(L, raylua_boot_lua))
if (luaL_dostring(L, raylua_boot_lua)) {
fputs(luaL_checkstring(L, -1), stderr);
fputc('\n', stderr);
}
}
int luaopen_raylua(lua_State *L)

View File

@ -16,7 +16,7 @@
local load = loadstring
raylua.version = "v3.1-dev1"
raylua.version = "v3.1-dev2"
function raylua.repl()
print("> raylua " .. raylua.version .. " <")
@ -65,16 +65,37 @@ if raylua.loadfile then
end
print "RAYLUA: Load main.lua from payload."
require "main"
local f, err = load(raylua.loadfile "main.lua", "main.lua")
if f then
local status, f_err = xpcall(f, debug.traceback)
if not status then
print(f_err)
end
else
print(err)
end
if not raylua.isrepl then
-- Keep launching the repl even with `loadfile` defined.
return
end
-- Keep launching the repl even with `loadfile` defined.
end
if arg and arg[1] then
dofile(arg[1])
local f, err = loadfile(arg[1])
if f then
local status, f_err = xpcall(f, debug.traceback)
if not status then
print(f_err)
end
else
print(err)
end
return
end

View File

@ -150,7 +150,7 @@ static int list_dir(lua_State *L)
return 0;
struct dirent *entry;
size_t count = 0;
size_t count = 1;
lua_newtable(L);

View File

@ -83,7 +83,7 @@ if t == "directory" then
local function add_dir(root, dir)
for i,file in ipairs(list_dir(path_concat(root, dir))) do
if file ~= ".." then
if file ~= ".." and file ~= "." then
local partial_file_path, full_file_path
if dir then

View File

@ -88,60 +88,6 @@ int raylua_listfiles(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(FILE *self)
{
mz_zip_zero_struct(&zip_file);
@ -174,11 +120,6 @@ int main(int argc, const char **argv)
lua_setglobal(L, "arg");
SetFilesystemOverride((FilesystemOverride){
.loadFileData = &raylua_loadFileData,
.loadFileText = &raylua_loadFileText,
});
FILE *self = raylua_open_self(argv[0]);
if (self == NULL) {

View File

@ -84,7 +84,7 @@ void SaveFileText(const char *fileName, char *text)
bool FileExists(const char *fileName)
bool IsFileExtension(const char *fileName, const char *ext)
bool DirectoryExists(const char *dirPath)
const char *GetExtension(const char *fileName)
const char *GetFileExtension(const char *fileName)
const char *GetFileName(const char *filePath)
const char *GetFileNameWithoutExt(const char *filePath)
const char *GetDirectoryPath(const char *filePath)
@ -191,6 +191,7 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
Image LoadImage(const char *fileName)
Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize)
Image LoadImageAnim(const char *fileName, int *frames)
Image LoadImageFromMemory(const char *fileType, const char *fileData, int dataSize)
void ExportImage(Image image, const char *fileName)
void ExportImageAsCode(Image image, const char *fileName)
Texture2D LoadTexture(const char *fileName)
@ -271,7 +272,8 @@ Font GetFontDefault(void)
Font LoadFont(const char *fileName)
Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCount)
Font LoadFontFromImage(Image image, Color key, int firstChar)
CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, int type)
Font LoadFontFromMemory(const char *fileType, const char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount)
CharInfo *LoadFontData(const char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount, int type)
Image GenImageFontAtlas(const CharInfo *chars, Rectangle **recs, int charsCount, int fontSize, int padding, int packMethod)
void UnloadFont(Font font)
void DrawFPS(int posX, int posY)
@ -402,6 +404,7 @@ void CloseAudioDevice(void)
bool IsAudioDeviceReady(void)
void SetMasterVolume(float volume)
Wave LoadWave(const char *fileName)
Wave LoadWaveFromMemory(const char *fileType, const char *fileData, int dataSize)
Sound LoadSound(const char *fileName)
Sound LoadSoundFromWave(Wave wave)
void UpdateSound(Sound sound, const void *data, int samplesCount)