Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Lua.Unity/Assets/Lua.Unity/Editor/LuacAssetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void OnInspectorGUI()
if (asset == null) asset = (LuacAsset)serializedObject.targetObject;
if (bytes == null || !asset.bytes.AsSpan().SequenceEqual(bytes))
{
var prototype = LuaCompiler.UnDump(asset.bytes.AsSpan(), asset.name);
var prototype = Prototype.FromByteCode(asset.bytes.AsSpan(), asset.name);
if (sb == null)
sb = new StringBuilder();
sb.Clear();
Expand Down
28 changes: 0 additions & 28 deletions src/Lua/CodeAnalysis/Compilation/LuaCompiler.cs

This file was deleted.

33 changes: 33 additions & 0 deletions src/Lua/Runtime/Prototype.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Lua.CodeAnalysis;
using Lua.CodeAnalysis.Compilation;
using System.Buffers;

namespace Lua.Runtime;

Expand Down Expand Up @@ -29,4 +31,35 @@ UpValueDesc[] upValues
public readonly int LineDefined = lineDefined, LastLineDefined = lastLineDefined;
public readonly int ParameterCount = parameterCount, MaxStackSize = maxStackSize;
public readonly bool HasVariableArguments = hasVariableArguments;


/// <summary>
/// Lua bytecode signature. If the bytes start with this signature, they are considered as Lua bytecode.
/// </summary>
public static ReadOnlySpan<byte> LuaByteCodeSignature => Header.LuaSignature;

/// <summary>
/// Converts a Lua bytecode to a Prototype object.
/// </summary>
/// <param name="span">binary bytecode</param>
/// <param name="name">chunk name</param>
/// <returns></returns>
public static Prototype FromByteCode(ReadOnlySpan<byte> span, ReadOnlySpan<char> name) => Parser.UnDump(span, name);

/// <summary>
/// Converts a Prototype object to a Lua bytecode.
/// </summary>
/// <param name="useLittleEndian">true if the bytecode should be in little endian format, false if it should be in big endian format</param>
/// <returns>binary bytecode</returns>
public byte[] ToByteCode(bool useLittleEndian = true) => Parser.Dump(this, useLittleEndian);

/// <summary>
/// Writes the Lua bytecode to a buffer writer.
/// </summary>
/// <param name="bufferWriter">the buffer writer to write the bytecode to</param>
/// <param name="useLittleEndian">true if the bytecode should be in little endian format, false if it should be in big endian format</param>
public void WriteByteCode(IBufferWriter<byte> bufferWriter, bool useLittleEndian = true)
{
Parser.Dump(this, bufferWriter, useLittleEndian);
}
}