|
|
@@ -1,5 +1,4 @@
|
|
|
using System.Buffers;
|
|
|
-using Lua.Runtime;
|
|
|
using Lua.CodeAnalysis.Compilation;
|
|
|
using Lua.CodeAnalysis.Syntax;
|
|
|
|
|
|
@@ -7,24 +6,11 @@ namespace Lua;
|
|
|
|
|
|
public static class LuaStateExtensions
|
|
|
{
|
|
|
- public static ValueTask<int> RunAsync(this LuaState state, Chunk chunk, Memory<LuaValue> buffer, CancellationToken cancellationToken = default)
|
|
|
- {
|
|
|
- return new Closure(state, chunk).InvokeAsync(new()
|
|
|
- {
|
|
|
- State = state,
|
|
|
- ArgumentCount = 0,
|
|
|
- StackPosition = state.Stack.Count,
|
|
|
- SourcePosition = null,
|
|
|
- RootChunkName = chunk.Name ?? LuaState.DefaultChunkName,
|
|
|
- ChunkName = chunk.Name ?? LuaState.DefaultChunkName,
|
|
|
- }, buffer, cancellationToken);
|
|
|
- }
|
|
|
-
|
|
|
public static ValueTask<int> DoStringAsync(this LuaState state, string source, Memory<LuaValue> buffer, string? chunkName = null, CancellationToken cancellationToken = default)
|
|
|
{
|
|
|
var syntaxTree = LuaSyntaxTree.Parse(source);
|
|
|
var chunk = LuaCompiler.Default.Compile(syntaxTree, chunkName);
|
|
|
- return RunAsync(state, chunk, buffer, cancellationToken);
|
|
|
+ return state.RunAsync(chunk, buffer, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static async ValueTask<LuaValue[]> DoStringAsync(this LuaState state, string source, string? chunkName = null, CancellationToken cancellationToken = default)
|
|
|
@@ -47,7 +33,7 @@ public static class LuaStateExtensions
|
|
|
var fileName = Path.GetFileName(path);
|
|
|
var syntaxTree = LuaSyntaxTree.Parse(text, fileName);
|
|
|
var chunk = LuaCompiler.Default.Compile(syntaxTree, fileName);
|
|
|
- return await RunAsync(state, chunk, buffer, cancellationToken);
|
|
|
+ return await state.RunAsync(chunk, buffer, cancellationToken);
|
|
|
}
|
|
|
|
|
|
public static async ValueTask<LuaValue[]> DoFileAsync(this LuaState state, string path, CancellationToken cancellationToken = default)
|