mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 18:46:43 +00:00
added file:readAll() to BinaryReadHandle
This commit is contained in:
parent
c2aca7a7af
commit
41216610d4
1 changed files with 20 additions and 0 deletions
|
@ -12,6 +12,7 @@ public class BinaryReadHandle
|
||||||
|
|
||||||
private static readonly Dictionary<string, LuaFunction> functions = new()
|
private static readonly Dictionary<string, LuaFunction> functions = new()
|
||||||
{
|
{
|
||||||
|
["readAll"] = L_ReadAll,
|
||||||
["nextByte"] = L_NextByte,
|
["nextByte"] = L_NextByte,
|
||||||
["nextShort"] = L_NextShort,
|
["nextShort"] = L_NextShort,
|
||||||
["nextInt"] = L_NextInt,
|
["nextInt"] = L_NextInt,
|
||||||
|
@ -56,6 +57,25 @@ public class BinaryReadHandle
|
||||||
L.SetMetaTable(-2);
|
L.SetMetaTable(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int L_ReadAll(IntPtr state)
|
||||||
|
{
|
||||||
|
var L = Lua.FromIntPtr(state);
|
||||||
|
|
||||||
|
var stream = L.CheckObject<BinaryReader>(1, ObjectType, false);
|
||||||
|
|
||||||
|
if (stream is null)
|
||||||
|
L.Error("handle is closed");
|
||||||
|
|
||||||
|
if (stream.BaseStream.Position == stream.BaseStream.Length)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
var chars = stream.ReadChars((int)stream.BaseStream.Length);
|
||||||
|
var buffer = Encoding.ASCII.GetBytes(chars);
|
||||||
|
|
||||||
|
L.PushBuffer(buffer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
private static int L_NextByte(IntPtr state)
|
private static int L_NextByte(IntPtr state)
|
||||||
{
|
{
|
||||||
var L = Lua.FromIntPtr(state);
|
var L = Lua.FromIntPtr(state);
|
||||||
|
|
Loading…
Reference in a new issue