修复了一些bug

This commit is contained in:
2025-11-26 17:58:30 +08:00
parent 2f24d94db2
commit 88b0edfe6a
4 changed files with 18 additions and 3 deletions

View File

@@ -79,7 +79,7 @@ namespace Convention.RScript.Runner
if (varTypeName == "string") if (varTypeName == "string")
{ {
varType = typeof(string); varType = typeof(string);
varDefaultValue = varInitExpression == null ? string.Empty : varInitExpression; varDefaultValue = varInitExpression == null ? string.Empty : varInitExpression.Trim('\"');
} }
else if (varTypeName == "int") else if (varTypeName == "int")
{ {

View File

@@ -22,7 +22,14 @@ namespace Convention.RScript.Runner
// 还原上层命名空间的变量 // 还原上层命名空间的变量
foreach (var local in context.CurrentLocalSpaceVariableNames.Peek()) foreach (var local in context.CurrentLocalSpaceVariableNames.Peek())
{ {
parser.context.Variables[local] = context.Variables[local].data; if (context.Variables.ContainsKey(local))
{
parser.context.Variables[local] = context.Variables[local].data;
}
else
{
parser.context.Variables.Remove(local);
}
} }
context.CurrentLocalSpaceVariableNames.Pop(); context.CurrentLocalSpaceVariableNames.Pop();
// 弹栈 // 弹栈

View File

@@ -97,6 +97,14 @@ namespace Convention.RScript.Parser
this.context = context; this.context = context;
// 默认启用未定义标识符作为字符串的功能 // 默认启用未定义标识符作为字符串的功能
this.context.Options.UndefinedIdentifiersAsStrings = true; this.context.Options.UndefinedIdentifiersAsStrings = true;
// 启用大小写敏感
this.context.Options.CaseSensitive = true;
// 启用溢出检查
this.context.Options.Checked = true;
#if UNITY_EDITOR
// 浮点数使用float而非doubleUnity性能优化
this.context.Options.RealLiteralDataType = RealLiteralDataType.Single;
#endif
} }
private readonly Dictionary<string, Type> CompileGenericExpressionTypen = new(); private readonly Dictionary<string, Type> CompileGenericExpressionTypen = new();

View File

@@ -32,7 +32,7 @@ namespace Convention.RScript
else else
internalData = Activator.CreateInstance(type); internalData = Activator.CreateInstance(type);
} }
else if (type == typeof(object) || type == value.GetType()) else if (type == typeof(object) || type.IsAssignableFrom(value.GetType()))
internalData = value; internalData = value;
else else
internalData = Convert.ChangeType(value, type); internalData = Convert.ChangeType(value, type);