mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +00:00
More work on slices
This commit is contained in:
parent
c08e5f51c2
commit
66b7a087c3
@ -238,7 +238,17 @@ def parse_header(header_name: str, output_file: str, ext_file: str, prefix: str,
|
||||
zig_arguments = ", ".join(zig_arguments)
|
||||
zig_call_args = ", ".join(zig_call_args)
|
||||
|
||||
if func_name in ["TextFormat", "LoadShader", "LoadShaderFromMemory", "LoadFontFromMemory"]:
|
||||
manual = [
|
||||
"TextFormat",
|
||||
"LoadShader",
|
||||
"ExportDataAsCode",
|
||||
"LoadFileData",
|
||||
"SaveFileData",
|
||||
"ExportDataAsCode",
|
||||
"LoadImageFromMemory"
|
||||
]
|
||||
|
||||
if func_name in manual or "FromMemory" in func_name:
|
||||
continue
|
||||
|
||||
zig_return = ziggify_type(func_name, return_type)
|
||||
|
@ -915,10 +915,6 @@ pub const SHADER_LOC_MAP_SPECULAR = ShaderLocationIndex.SHADER_LOC_MAP_METALNESS
|
||||
|
||||
const cdef = @import("raylib-zig-ext.zig");
|
||||
|
||||
pub fn textFormat(text: []const u8, args: anytype) []const u8 {
|
||||
return std.mem.span(@call(.{}, cdef.TextFormat, .{@ptrCast([*c]const u8, text)} ++ args));
|
||||
}
|
||||
|
||||
pub fn loadShader(vsFileName: ?[]const u8, fsFileName: ?[]const u8) Shader {
|
||||
var vsFileNameFinal = @as([*c]const u8, 0);
|
||||
var fsFileNameFinal = @as([*c]const u8, 0);
|
||||
@ -943,6 +939,26 @@ pub fn loadShaderFromMemory(vsCode: ?[]const u8, fsCode: ?[]const u8) Shader {
|
||||
return cdef.LoadShaderFromMemory(vsCodeFinal, fsCodeFinal);
|
||||
}
|
||||
|
||||
pub fn loadFileData(fileName: []const u8) []u8 {
|
||||
var bytesRead = 0;
|
||||
var res: []u8 = undefined;
|
||||
res.ptr = @ptrCast([*]u8, cdef.LoadFileData(@ptrCast([*c]const u8, fileName), @ptrCast([*c]c_uint, &bytesRead)));
|
||||
res.len = @intCast(usize, bytesRead);
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn saveFileData(fileName: []const u8, data: []anyopaque) bool {
|
||||
return cdef.SaveFileData(@ptrCast([*c]const u8, fileName), @ptrCast(*anyopaque, data.ptr), @intCast(c_uint, data.len));
|
||||
}
|
||||
|
||||
pub fn exportDataAsCode(data: []const u8, fileName: []const u8) bool {
|
||||
return cdef.ExportDataAsCode(@ptrCast([*c]const u8, data), @as(c_uint, data.len), @ptrCast([*c]const u8, fileName));
|
||||
}
|
||||
|
||||
pub fn loadImageFromMemory(fileType: []const u8, fileData: []const u8) Image {
|
||||
return cdef.LoadImageFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileData), @intCast(c_int, fileData.len));
|
||||
}
|
||||
|
||||
pub fn loadImageColors(image: Image) []Color {
|
||||
var res: []Color = undefined;
|
||||
res.ptr = @ptrCast([*]Color, cdef.LoadImageColors(image));
|
||||
@ -963,12 +979,12 @@ pub fn loadFontFromMemory(fileType: []const u8, fileData: ?[]const u8, fontSize:
|
||||
if (fileData) |fileDataSure| {
|
||||
fileDataFinal = @ptrCast([*c]const u8, fileDataSure);
|
||||
}
|
||||
return cdef.LoadFontFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileDataFinal), @as(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, fontChars.len));
|
||||
return cdef.LoadFontFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileDataFinal), @intCast(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @intCast(c_int, fontChars.len));
|
||||
}
|
||||
|
||||
pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: i32) []GlyphInfo {
|
||||
var res: []GlyphInfo = undefined;
|
||||
res.ptr = @ptrCast([*]GlyphInfo, cdef.LoadFontData(@ptrCast([*c]const u8, fileData), @as(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, fontChars.len), @as(c_int, ty)));
|
||||
res.ptr = @ptrCast([*]GlyphInfo, cdef.LoadFontData(@ptrCast([*c]const u8, fileData), @intCast(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @intCast(c_int, fontChars.len), @as(c_int, ty)));
|
||||
res.len = @intCast(usize, fontChars.len);
|
||||
return res;
|
||||
}
|
||||
@ -984,6 +1000,10 @@ pub fn loadCodepoints(text: []const u8) []i32 {
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn textFormat(text: []const u8, args: anytype) []const u8 {
|
||||
return std.mem.span(@call(.{}, cdef.TextFormat, .{@ptrCast([*c]const u8, text)} ++ args));
|
||||
}
|
||||
|
||||
pub fn textSplit(text: []const u8, delimiter: u8) [][*]const u8 {
|
||||
var count = 0;
|
||||
var res: [][*]const u8 = undefined;
|
||||
@ -1008,9 +1028,17 @@ pub fn loadModelAnimations(fileName: []const u8) []ModelAnimation {
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn loadWaveFromMemory(fileType: []const u8, fileData: []const u8) Wave {
|
||||
return cdef.LoadWaveFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileData), @as(c_int, fileData.len));
|
||||
}
|
||||
|
||||
pub fn loadWaveSamples(wave: Wave) []f32 {
|
||||
var res: []f32 = undefined;
|
||||
res.ptr = @ptrCast([*]f32, cdef.LoadWaveSamples(wave));
|
||||
res.len = @intCast(usize, wave.frameCount * wave.channels);
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn loadMusicStreamFromMemory(fileType: []const u8, data: []const u8) Music {
|
||||
return cdef.LoadMusicStreamFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, data), @as(c_int, data.len));
|
||||
}
|
||||
|
@ -915,10 +915,6 @@ pub const SHADER_LOC_MAP_SPECULAR = ShaderLocationIndex.SHADER_LOC_MAP_METALNESS
|
||||
|
||||
const cdef = @import("raylib-zig-ext.zig");
|
||||
|
||||
pub fn textFormat(text: []const u8, args: anytype) []const u8 {
|
||||
return std.mem.span(@call(.{}, cdef.TextFormat, .{@ptrCast([*c]const u8, text)} ++ args));
|
||||
}
|
||||
|
||||
pub fn loadShader(vsFileName: ?[]const u8, fsFileName: ?[]const u8) Shader {
|
||||
var vsFileNameFinal = @as([*c]const u8, 0);
|
||||
var fsFileNameFinal = @as([*c]const u8, 0);
|
||||
@ -943,6 +939,26 @@ pub fn loadShaderFromMemory(vsCode: ?[]const u8, fsCode: ?[]const u8) Shader {
|
||||
return cdef.LoadShaderFromMemory(vsCodeFinal, fsCodeFinal);
|
||||
}
|
||||
|
||||
pub fn loadFileData(fileName: []const u8) []u8 {
|
||||
var bytesRead = 0;
|
||||
var res: []u8 = undefined;
|
||||
res.ptr = @ptrCast([*]u8, cdef.LoadFileData(@ptrCast([*c]const u8, fileName), @ptrCast([*c]c_uint, &bytesRead)));
|
||||
res.len = @intCast(usize, bytesRead);
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn saveFileData(fileName: []const u8, data: []anyopaque) bool {
|
||||
return cdef.SaveFileData(@ptrCast([*c]const u8, fileName), @ptrCast(*anyopaque, data.ptr), @intCast(c_uint, data.len));
|
||||
}
|
||||
|
||||
pub fn exportDataAsCode(data: []const u8, fileName: []const u8) bool {
|
||||
return cdef.ExportDataAsCode(@ptrCast([*c]const u8, data), @as(c_uint, data.len), @ptrCast([*c]const u8, fileName));
|
||||
}
|
||||
|
||||
pub fn loadImageFromMemory(fileType: []const u8, fileData: []const u8) Image {
|
||||
return cdef.LoadImageFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileData), @intCast(c_int, fileData.len));
|
||||
}
|
||||
|
||||
pub fn loadImageColors(image: Image) []Color {
|
||||
var res: []Color = undefined;
|
||||
res.ptr = @ptrCast([*]Color, cdef.LoadImageColors(image));
|
||||
@ -963,12 +979,12 @@ pub fn loadFontFromMemory(fileType: []const u8, fileData: ?[]const u8, fontSize:
|
||||
if (fileData) |fileDataSure| {
|
||||
fileDataFinal = @ptrCast([*c]const u8, fileDataSure);
|
||||
}
|
||||
return cdef.LoadFontFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileDataFinal), @as(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, fontChars.len));
|
||||
return cdef.LoadFontFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileDataFinal), @intCast(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @intCast(c_int, fontChars.len));
|
||||
}
|
||||
|
||||
pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: i32) []GlyphInfo {
|
||||
var res: []GlyphInfo = undefined;
|
||||
res.ptr = @ptrCast([*]GlyphInfo, cdef.LoadFontData(@ptrCast([*c]const u8, fileData), @as(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, fontChars.len), @as(c_int, ty)));
|
||||
res.ptr = @ptrCast([*]GlyphInfo, cdef.LoadFontData(@ptrCast([*c]const u8, fileData), @intCast(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @intCast(c_int, fontChars.len), @as(c_int, ty)));
|
||||
res.len = @intCast(usize, fontChars.len);
|
||||
return res;
|
||||
}
|
||||
@ -984,6 +1000,10 @@ pub fn loadCodepoints(text: []const u8) []i32 {
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn textFormat(text: []const u8, args: anytype) []const u8 {
|
||||
return std.mem.span(@call(.{}, cdef.TextFormat, .{@ptrCast([*c]const u8, text)} ++ args));
|
||||
}
|
||||
|
||||
pub fn textSplit(text: []const u8, delimiter: u8) [][*]const u8 {
|
||||
var count = 0;
|
||||
var res: [][*]const u8 = undefined;
|
||||
@ -1008,6 +1028,10 @@ pub fn loadModelAnimations(fileName: []const u8) []ModelAnimation {
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn loadWaveFromMemory(fileType: []const u8, fileData: []const u8) Wave {
|
||||
return cdef.LoadWaveFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileData), @as(c_int, fileData.len));
|
||||
}
|
||||
|
||||
pub fn loadWaveSamples(wave: Wave) []f32 {
|
||||
var res: []f32 = undefined;
|
||||
res.ptr = @ptrCast([*]f32, cdef.LoadWaveSamples(wave));
|
||||
@ -1015,6 +1039,10 @@ pub fn loadWaveSamples(wave: Wave) []f32 {
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn loadMusicStreamFromMemory(fileType: []const u8, data: []const u8) Music {
|
||||
return cdef.LoadMusicStreamFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, data), @as(c_int, data.len));
|
||||
}
|
||||
|
||||
pub fn initWindow(width: i32, height: i32, title: []const u8) void {
|
||||
cdef.InitWindow(@as(c_int, width), @as(c_int, height), @ptrCast([*c]const u8, title));
|
||||
}
|
||||
@ -1431,22 +1459,10 @@ pub fn setSaveFileTextCallback(callback: SaveFileTextCallback) void {
|
||||
cdef.SetSaveFileTextCallback(callback);
|
||||
}
|
||||
|
||||
pub fn loadFileData(fileName: []const u8, bytesRead: *u32) []u8 {
|
||||
return std.mem.span(cdef.LoadFileData(@ptrCast([*c]const u8, fileName), @ptrCast([*c]c_uint, bytesRead)));
|
||||
}
|
||||
|
||||
pub fn unloadFileData(data: []u8) void {
|
||||
cdef.UnloadFileData(@ptrCast([*c]u8, data));
|
||||
}
|
||||
|
||||
pub fn saveFileData(fileName: []const u8, data: *anyopaque, bytesToWrite: u32) bool {
|
||||
return cdef.SaveFileData(@ptrCast([*c]const u8, fileName), data, @as(c_uint, bytesToWrite));
|
||||
}
|
||||
|
||||
pub fn exportDataAsCode(data: []const u8, size: u32, fileName: []const u8) bool {
|
||||
return cdef.ExportDataAsCode(@ptrCast([*c]const u8, data), @as(c_uint, size), @ptrCast([*c]const u8, fileName));
|
||||
}
|
||||
|
||||
pub fn loadFileText(fileName: []const u8) []u8 {
|
||||
return std.mem.span(cdef.LoadFileText(@ptrCast([*c]const u8, fileName)));
|
||||
}
|
||||
@ -1959,10 +1975,6 @@ pub fn loadImageAnim(fileName: []const u8, frames: []i32) Image {
|
||||
return cdef.LoadImageAnim(@ptrCast([*c]const u8, fileName), @ptrCast([*c]c_int, frames));
|
||||
}
|
||||
|
||||
pub fn loadImageFromMemory(fileType: []const u8, fileData: []const u8, dataSize: i32) Image {
|
||||
return cdef.LoadImageFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileData), @as(c_int, dataSize));
|
||||
}
|
||||
|
||||
pub fn loadImageFromTexture(texture: Texture2D) Image {
|
||||
return cdef.LoadImageFromTexture(texture);
|
||||
}
|
||||
@ -2791,10 +2803,6 @@ pub fn loadWave(fileName: []const u8) Wave {
|
||||
return cdef.LoadWave(@ptrCast([*c]const u8, fileName));
|
||||
}
|
||||
|
||||
pub fn loadWaveFromMemory(fileType: []const u8, fileData: []const u8, dataSize: i32) Wave {
|
||||
return cdef.LoadWaveFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileData), @as(c_int, dataSize));
|
||||
}
|
||||
|
||||
pub fn loadSound(fileName: []const u8) Sound {
|
||||
return cdef.LoadSound(@ptrCast([*c]const u8, fileName));
|
||||
}
|
||||
@ -2887,10 +2895,6 @@ pub fn loadMusicStream(fileName: []const u8) Music {
|
||||
return cdef.LoadMusicStream(@ptrCast([*c]const u8, fileName));
|
||||
}
|
||||
|
||||
pub fn loadMusicStreamFromMemory(fileType: []const u8, data: []const u8, dataSize: i32) Music {
|
||||
return cdef.LoadMusicStreamFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, data), @as(c_int, dataSize));
|
||||
}
|
||||
|
||||
pub fn unloadMusicStream(music: Music) void {
|
||||
cdef.UnloadMusicStream(music);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user