Reimplementation of DoString with lua/cl_lua commands and fix Lua scripts not being loaded properly
This commit is contained in:
committed by
Maplewheels
parent
f0f09c20fa
commit
67d3d5f587
@@ -11,7 +11,7 @@ namespace Barotrauma
|
||||
internal class LuaUserData
|
||||
{
|
||||
[Obsolete("Use IPluginManagementService::GetTypesByName()")]
|
||||
public static Type GetType(string typeName) => GameMain.LuaCs.PluginManagementService.GetType(typeName); //LuaCsSetup.GetType(typeName);
|
||||
public static Type GetType(string typeName) => GameMain.LuaCs.PluginManagementService.GetType(typeName, includeInterfaces: true); //LuaCsSetup.GetType(typeName);
|
||||
|
||||
public static IUserDataDescriptor RegisterType(string typeName)
|
||||
{
|
||||
|
||||
+18
-5
@@ -99,6 +99,22 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
||||
return new FluentResults.Result().WithReasons(cacheRes.Value.SelectMany(cr => cr.Item2.Reasons));
|
||||
}
|
||||
|
||||
public FluentResults.Result<DynValue> DoString(string code)
|
||||
{
|
||||
IService.CheckDisposed(this);
|
||||
if (_script == null || !IsRunning) { throw new Exception("Disposed"); }
|
||||
|
||||
try
|
||||
{
|
||||
var result = _script.DoString(code);
|
||||
return FluentResults.Result.Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return FluentResults.Result.Fail(new ExceptionalError(ex));
|
||||
}
|
||||
}
|
||||
|
||||
private DynValue DoFile(string file, Table? globalContext = null, string? codeStringFriendly = null)
|
||||
{
|
||||
if (_script == null)
|
||||
@@ -205,16 +221,13 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
||||
|
||||
var result = FluentResults.Result.Ok();
|
||||
|
||||
List<ILuaScriptResourceInfo> initializationScripts = executionOrder.Where(x => x.OwnerPackage.Name == "LuaCsForBarotrauma").ToList();
|
||||
List<ILuaScriptResourceInfo> otherScripts = executionOrder.Except(initializationScripts).ToList();
|
||||
|
||||
foreach (ILuaScriptResourceInfo resource in initializationScripts)
|
||||
foreach (ILuaScriptResourceInfo resource in executionOrder.Where(l => l.IsAutorun))
|
||||
{
|
||||
foreach (ContentPath filePath in resource.FilePaths)
|
||||
{
|
||||
try
|
||||
{
|
||||
_script?.Call(_script.LoadFile(filePath.FullPath), Path.GetDirectoryName(resource.OwnerPackage.Path), otherScripts.ToList());
|
||||
_script?.Call(_script.LoadFile(filePath.FullPath), Path.GetDirectoryName(resource.OwnerPackage.Path));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
+1
@@ -17,6 +17,7 @@ public interface ILuaScriptManagementService : IReusableService
|
||||
#region Script_Ops
|
||||
|
||||
object? GetGlobalTableValue(string tableName);
|
||||
FluentResults.Result<DynValue> DoString(string code);
|
||||
|
||||
/// <summary>
|
||||
/// Parses and loads script sources (code) into a memory cache without executing it.
|
||||
|
||||
Reference in New Issue
Block a user