本文整理汇总了C#中Scorpio.ScriptObject类的典型用法代码示例。如果您正苦于以下问题:C# ScriptObject类的具体用法?C# ScriptObject怎么用?C# ScriptObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScriptObject类属于Scorpio命名空间,在下文中一共展示了ScriptObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Call
public override object Call(ScriptObject[] parameters) {
try {
return m_Handle.Call(parameters);
} catch (System.Exception ex) {
throw new ExecutionException(m_Script, "CallFunction [" + Name + "] is error : " + ex.ToString());
}
}
示例2: AssignCompute
public override ScriptObject AssignCompute(TokenType type, ScriptObject obj) {
if (type == TokenType.AssignPlus) {
m_Value += obj.ToString();
return this;
}
throw new ExecutionException(m_Script, this, "String类型 操作符[" + type + "]不支持");
}
示例3: call
public object call(params object[] args)
{
int length = args.Length;
ScriptObject[] parameters = new ScriptObject[length];
for (int i = 0; i < length; ++i) parameters[i] = m_Script.CreateObject(args[i]);
return Call(parameters);
}
示例4: Compute
public override ScriptObject Compute(TokenType type, ScriptObject value) {
if (type != TokenType.Plus) { return base.Compute(type, value); }
ScriptTable table = value as ScriptTable;
if (table == null) throw new ExecutionException(m_Script, this, "table [+] 操作只限两个[table]之间,传入数据类型:" + value.Type);
ScriptTable ret = m_Script.CreateTable();
ScriptObject obj = null;
ScriptScriptFunction func = null;
foreach (KeyValuePair<object, ScriptObject> pair in m_listObject) {
obj = pair.Value.Clone();
if (obj is ScriptScriptFunction) {
func = (ScriptScriptFunction)obj;
if (!func.IsStaticFunction) func.SetTable(ret);
}
ret.m_listObject[pair.Key] = obj;
}
foreach (KeyValuePair<object, ScriptObject> pair in table.m_listObject) {
obj = pair.Value.Clone();
if (obj is ScriptScriptFunction) {
func = (ScriptScriptFunction)obj;
if (!func.IsStaticFunction) func.SetTable(ret);
}
ret.m_listObject[pair.Key] = obj;
}
return ret;
}
示例5: Call
public object Call(ScriptObject[] args)
{
if (args == null || args.Length == 0) return null;
string messagePattern = (args[0] as ScriptString).Value;
if (args.Length == 1) return messagePattern;
StringBuilder sbuf = new StringBuilder();
int L;
if (args[1] is ScriptArray) {
L = 0;
args = ((ScriptArray)args[1]).ToArray();
} else {
L = 1;
}
int length = args.Length;
int i = 0, j = 0;
for (; L < length; L++) {
j = messagePattern.IndexOf(DELIM_STR, i);
if (j == -1) {
if (i == 0) {
return messagePattern;
} else {
sbuf.Append(messagePattern.Substring(i));
return sbuf.ToString();
}
} else {
sbuf.Append(messagePattern.Substring(i, j - i));
sbuf.Append(args[L].ToString());
i = j + 2;
}
}
sbuf.Append(messagePattern.Substring(i));
return sbuf.ToString();
}
示例6: Call
public object Call(ScriptObject[] args)
{
string messagePattern = (args[0] as ScriptString).Value;
if (args.Length == 1) return messagePattern;
if (args.Length == 3)
return messagePattern.Substring((args[1] as ScriptNumber).ToInt32(), (args[2] as ScriptNumber).ToInt32());
else
return messagePattern.Substring((args[1] as ScriptNumber).ToInt32());
}
示例7: Call
public object Call(ScriptObject[] args)
{
if (m_Enumerator.MoveNext()) {
ScriptTable table = m_Script.CreateTable();
table.SetValue("key", m_Script.CreateObject(m_Index++));
table.SetValue("value", m_Enumerator.Current);
return table;
}
return null;
}
示例8: SetValue
/// <summary> 设置一个类变量 </summary>
public void SetValue(object obj, string name, ScriptObject value)
{
UserdataField field = GetField(name);
if (field == null) throw new ExecutionException(m_Script, "SetValue Type[" + m_Type + "] 变量 [" + name + "] 不存在");
try {
field.SetValue(obj, Util.ChangeType(m_Script, value, field.FieldType));
} catch (System.Exception e) {
throw new ExecutionException(m_Script, "不能从源类型:" + (value == null || value.IsNull ? "null" : value.ObjectValue.GetType().Name) + " 转换成目标类型:" + field.FieldType.Name + " : " + e.ToString());
}
}
示例9: CanChangeType
public static bool CanChangeType(ScriptObject[] pars, Type[] types)
{
if (pars.Length != types.Length)
return false;
for (int i = 0; i < pars.Length;++i ) {
if (!CanChangeType(pars[i], types[i]))
return false;
}
return true;
}
示例10: Call
public object Call(ScriptObject[] args) {
int num = args.Length;
if (num == 0) return 0f;
double num2 = (args[0] as ScriptNumber).ToDouble();
for (int i = 1; i < num; i++) {
double num3 = (args[i] as ScriptNumber).ToDouble();
if (num3 > num2)
num2 = num3;
}
return num2;
}
示例11: SetVariableObject
private bool SetVariableObject(string name, ScriptObject obj)
{
if (m_variableDictionary.ContainsKey(name)) {
m_variableDictionary[name] = obj.Assign();
return true;
}
if (m_parent != null) {
return m_parent.SetVariableObject(name, obj);
}
return false;
}
示例12: Call
public object Call(String strName, params object[] args)
{
ScriptObject obj = m_GlobalTable.GetValue(strName);
if (obj is ScriptNull) throw new ScriptException("找不到变量[" + strName + "]");
int length = args.Length;
ScriptObject[] parameters = new ScriptObject[length];
for (int i = 0; i < length;++i ) {
parameters[i] = CreateObject(args[i]);
}
m_StackInfoStack.Clear();
return obj.Call(parameters);
}
示例13: Call
public object Call(object obj, ScriptObject[] parameters)
{
if (m_Count == 0) throw new ExecutionException(m_Script, "找不到函数 [" + MethodName + "]");
FunctionMethod methodInfo = null;
if (m_Count == 1) {
methodInfo = m_Methods[0];
if (!methodInfo.IsValid) throw new ExecutionException(m_Script, "Type[" + m_Type.ToString() + "] 找不到合适的函数 [" + MethodName + "]");
} else {
foreach (FunctionMethod method in m_Methods) {
if (method.IsValid && Util.CanChangeType(parameters, method.ParameterType)) {
methodInfo = method;
break;
}
}
}
try {
if (methodInfo != null && !methodInfo.Params) {
int length = methodInfo.ParameterType.Length;
object[] objs = methodInfo.Args;
for (int i = 0; i < length; i++)
objs[i] = Util.ChangeType(m_Script, parameters[i], methodInfo.ParameterType[i]);
return methodInfo.Invoke(obj, m_Type);
} else {
foreach (FunctionMethod method in m_Methods) {
int length = method.ParameterType.Length;
if (method.Params && parameters.Length >= length - 1) {
bool fit = true;
for (int i = 0; i < parameters.Length; ++i) {
if (!Util.CanChangeType(parameters[i], i >= length - 1 ? method.ParamType : method.ParameterType[i])) {
fit = false;
break;
}
}
if (fit) {
object[] objs = method.Args;
for (int i = 0; i < length - 1; ++i)
objs[i] = Util.ChangeType(m_Script, parameters[i], method.ParameterType[i]);
Array array = Array.CreateInstance(method.ParamType, parameters.Length - length + 1);
for (int i = length - 1; i < parameters.Length; ++i)
array.SetValue(Util.ChangeType(m_Script, parameters[i], method.ParamType), i - length + 1);
objs[length - 1] = array;
return method.Invoke(obj, m_Type);
}
}
}
}
} catch (System.Exception e) {
throw new ExecutionException(m_Script, "Type[" + m_Type.ToString() + "] 调用函数出错 [" + MethodName + "] : " + e.ToString());
}
throw new ExecutionException(m_Script, "Type[" + m_Type.ToString() + "] 找不到合适的函数 [" + MethodName + "]");
}
示例14: Call
public override object Call(ScriptObject[] parameters)
{
int length = parameters.Length;
Util.Assert(length > 0, m_script, "length > 0");
if (length > 1) {
ScriptObject[] pars = new ScriptObject[parameters.Length - 1];
Array.Copy(parameters, 1, pars, 0, pars.Length);
if (parameters[0] is ScriptNumber)
return m_Method.Call(Util.ChangeType_impl(parameters[0].ObjectValue, m_Type), pars);
else
return m_Method.Call(parameters[0].ObjectValue, pars);
} else {
return m_Method.Call(parameters[0].ObjectValue, new ScriptObject[0]);
}
}
示例15: Compare
public override bool Compare(TokenType type, ScriptObject obj) {
ScriptString val = obj as ScriptString;
if (val == null) throw new ExecutionException(m_Script, this, "字符串比较 右边必须为字符串类型");
switch (type) {
case TokenType.Greater:
return string.Compare(m_Value, val.m_Value) > 0;
case TokenType.GreaterOrEqual:
return string.Compare(m_Value, val.m_Value) >= 0;
case TokenType.Less:
return string.Compare(m_Value, val.m_Value) < 0;
case TokenType.LessOrEqual:
return string.Compare(m_Value, val.m_Value) <= 0;
default:
throw new ExecutionException(m_Script, this, "String类型 操作符[" + type + "]不支持");
}
}