本文整理汇总了C#中NLua.ObjectTranslator类的典型用法代码示例。如果您正苦于以下问题:C# ObjectTranslator类的具体用法?C# ObjectTranslator怎么用?C# ObjectTranslator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectTranslator类属于NLua命名空间,在下文中一共展示了ObjectTranslator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckType
public CheckType(ObjectTranslator translator)
{
this.translator = translator;
extractValues.Add(GetExtractDictionaryKey(typeof(object)), new ExtractValue(GetAsObject));
extractValues.Add(GetExtractDictionaryKey(typeof(sbyte)), new ExtractValue(GetAsSbyte));
extractValues.Add(GetExtractDictionaryKey(typeof(byte)), new ExtractValue(GetAsByte));
extractValues.Add(GetExtractDictionaryKey(typeof(short)), new ExtractValue(GetAsShort));
extractValues.Add(GetExtractDictionaryKey(typeof(ushort)), new ExtractValue(GetAsUshort));
extractValues.Add(GetExtractDictionaryKey(typeof(int)), new ExtractValue(GetAsInt));
extractValues.Add(GetExtractDictionaryKey(typeof(uint)), new ExtractValue(GetAsUint));
extractValues.Add(GetExtractDictionaryKey(typeof(long)), new ExtractValue(GetAsLong));
extractValues.Add(GetExtractDictionaryKey(typeof(ulong)), new ExtractValue(GetAsUlong));
extractValues.Add(GetExtractDictionaryKey(typeof(double)), new ExtractValue(GetAsDouble));
extractValues.Add(GetExtractDictionaryKey(typeof(char)), new ExtractValue(GetAsChar));
extractValues.Add(GetExtractDictionaryKey(typeof(float)), new ExtractValue(GetAsFloat));
extractValues.Add(GetExtractDictionaryKey(typeof(decimal)), new ExtractValue(GetAsDecimal));
extractValues.Add(GetExtractDictionaryKey(typeof(bool)), new ExtractValue(GetAsBoolean));
extractValues.Add(GetExtractDictionaryKey(typeof(string)), new ExtractValue(GetAsString));
extractValues.Add(GetExtractDictionaryKey(typeof(char[])), new ExtractValue (GetAsCharArray));
extractValues.Add(GetExtractDictionaryKey(typeof(LuaFunction)), new ExtractValue(GetAsFunction));
extractValues.Add(GetExtractDictionaryKey(typeof(LuaTable)), new ExtractValue(GetAsTable));
extractValues.Add(GetExtractDictionaryKey(typeof(Dictionary<object,object>)), new ExtractValue(GetAsDictionary));
extractValues.Add(GetExtractDictionaryKey(typeof(LuaUserData)), new ExtractValue(GetAsUserdata));
extractNetObject = new ExtractValue (GetAsNetObject);
}
示例2: MetaFunctions
public MetaFunctions (ObjectTranslator translator)
{
this.translator = translator;
gcFunction = new LuaNativeFunction (MetaFunctions.CollectObject);
toStringFunction = new LuaNativeFunction (MetaFunctions.ToStringLua);
indexFunction = new LuaNativeFunction (MetaFunctions.GetMethod);
newindexFunction = new LuaNativeFunction (MetaFunctions.SetFieldOrProperty);
baseIndexFunction = new LuaNativeFunction (MetaFunctions.GetBaseMethod);
callConstructorFunction = new LuaNativeFunction (MetaFunctions.CallConstructor);
classIndexFunction = new LuaNativeFunction (MetaFunctions.GetClassMethod);
classNewindexFunction = new LuaNativeFunction (MetaFunctions.SetClassFieldOrProperty);
execDelegateFunction = new LuaNativeFunction (MetaFunctions.RunFunctionDelegate);
}
示例3: MetaFunctions
public MetaFunctions (ObjectTranslator translator)
{
this.translator = translator;
gcFunction = new LuaCore.lua_CFunction (MetaFunctions.collectObject);
toStringFunction = new LuaCore.lua_CFunction (MetaFunctions.toString);
indexFunction = new LuaCore.lua_CFunction (MetaFunctions.getMethod);
newindexFunction = new LuaCore.lua_CFunction (MetaFunctions.setFieldOrProperty);
baseIndexFunction = new LuaCore.lua_CFunction (MetaFunctions.getBaseMethod);
callConstructorFunction = new LuaCore.lua_CFunction (MetaFunctions.callConstructor);
classIndexFunction = new LuaCore.lua_CFunction (MetaFunctions.getClassMethod);
classNewindexFunction = new LuaCore.lua_CFunction (MetaFunctions.setClassFieldOrProperty);
execDelegateFunction = new LuaCore.lua_CFunction (MetaFunctions.runFunctionDelegate);
}
示例4: CheckType
public CheckType(ObjectTranslator translator)
{
this.translator = translator;
extractValues.Add (typeof(object).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsObject));
extractValues.Add (typeof(sbyte).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsSbyte));
extractValues.Add (typeof(byte).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsByte));
extractValues.Add (typeof(short).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsShort));
extractValues.Add (typeof(ushort).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUshort));
extractValues.Add (typeof(int).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsInt));
extractValues.Add (typeof(uint).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUint));
extractValues.Add (typeof(long).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsLong));
extractValues.Add (typeof(ulong).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUlong));
extractValues.Add (typeof(double).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsDouble));
extractValues.Add (typeof(char).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsChar));
extractValues.Add (typeof(float).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsFloat));
extractValues.Add (typeof(decimal).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsDecimal));
extractValues.Add (typeof(bool).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsBoolean));
extractValues.Add (typeof(string).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsString));
extractValues.Add (typeof(LuaFunction).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsFunction));
extractValues.Add (typeof(LuaTable).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsTable));
extractValues.Add (typeof(LuaUserData).TypeHandle.Value.ToInt64 (), new ExtractValue (getAsUserdata));
extractNetObject = new ExtractValue (getAsNetObject);
}
示例5: RunFunctionDelegate
private static int RunFunctionDelegate (LuaState luaState, ObjectTranslator translator)
{
LuaNativeFunction func = (LuaNativeFunction)translator.GetRawNetObject (luaState, 1);
LuaLib.LuaRemove (luaState, 1);
return func (luaState);
}
示例6: MatchOperator
static int MatchOperator (LuaState luaState, string operation, ObjectTranslator translator)
{
var validOperator = new MethodCache ();
object target = GetTargetObject (luaState, operation, translator);
if (target == null) {
translator.ThrowError (luaState, "Cannot call " + operation + " on a nil object");
LuaLib.LuaPushNil (luaState);
return 1;
}
Type type = target.GetType ();
var operators = type.GetMethods (operation, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
foreach (var op in operators) {
bool isOk = translator.MatchParameters (luaState, op, ref validOperator);
if (!isOk)
continue;
object result;
if (op.IsStatic)
result = op.Invoke (null, validOperator.args);
else
result = op.Invoke (target, validOperator.args);
translator.Push (luaState, result);
return 1;
}
translator.ThrowError (luaState, "Cannot call (" + operation + ") on object type " + type.Name);
LuaLib.LuaPushNil (luaState);
return 1;
}
示例7: GetTargetObject
static object GetTargetObject (LuaState luaState, string operation, ObjectTranslator translator)
{
Type t;
object target = translator.GetRawNetObject (luaState, 1);
if (target != null) {
t = target.GetType ();
if (t.HasMethod (operation))
return target;
}
target = translator.GetRawNetObject (luaState, 2);
if (target != null) {
t = target.GetType ();
if (t.HasMethod (operation))
return target;
}
return null;
}
示例8: ClassGenerator
public ClassGenerator(ObjectTranslator translator, Type klass)
{
this.translator = translator;
this.klass = klass;
}
示例9: Lua
public Lua ()
{
luaState = LuaLib.luaL_newstate (); // steffenj: Lua 5.1.1 API change (lua_open is gone)
LuaLib.luaL_openlibs (luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
LuaLib.lua_pushstring (luaState, "LUAINTERFACE LOADED");
LuaLib.lua_pushboolean (luaState, true);
LuaLib.lua_settable (luaState, (int)LuaIndexes.Registry);
LuaLib.lua_newtable (luaState);
LuaLib.lua_setglobal (luaState, "luanet");
LuaLib.lua_pushvalue (luaState, (int)LuaIndexes.Globals);
LuaLib.lua_getglobal (luaState, "luanet");
LuaLib.lua_pushstring (luaState, "getmetatable");
LuaLib.lua_getglobal (luaState, "getmetatable");
LuaLib.lua_settable (luaState, -3);
LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals);
translator = new ObjectTranslator (this, luaState);
ObjectTranslatorPool.Instance.Add (luaState, translator);
LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals);
LuaLib.luaL_dostring (luaState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring
// We need to keep this in a managed reference so the delegate doesn't get garbage collected
panicCallback = new LuaCore.lua_CFunction (PanicCallback);
LuaLib.lua_atpanic (luaState, panicCallback);
}
示例10: MetaFunctions
public MetaFunctions (ObjectTranslator translator)
{
this.translator = translator;
GcFunction = new LuaNativeFunction (MetaFunctions.CollectObject);
ToStringFunction = new LuaNativeFunction (MetaFunctions.ToStringLua);
IndexFunction = new LuaNativeFunction (MetaFunctions.GetMethod);
NewIndexFunction = new LuaNativeFunction (MetaFunctions.SetFieldOrProperty);
BaseIndexFunction = new LuaNativeFunction (MetaFunctions.GetBaseMethod);
CallConstructorFunction = new LuaNativeFunction (MetaFunctions.CallConstructor);
ClassIndexFunction = new LuaNativeFunction (MetaFunctions.GetClassMethod);
ClassNewindexFunction = new LuaNativeFunction (MetaFunctions.SetClassFieldOrProperty);
ExecuteDelegateFunction = new LuaNativeFunction (MetaFunctions.RunFunctionDelegate);
AddFunction = new LuaNativeFunction (MetaFunctions.AddLua);
SubtractFunction = new LuaNativeFunction (MetaFunctions.SubtractLua);
MultiplyFunction = new LuaNativeFunction (MetaFunctions.MultiplyLua);
DivisionFunction = new LuaNativeFunction (MetaFunctions.DivideLua);
ModulosFunction = new LuaNativeFunction (MetaFunctions.ModLua);
UnaryNegationFunction = new LuaNativeFunction (MetaFunctions.UnaryNegationLua);
EqualFunction = new LuaNativeFunction (MetaFunctions.EqualLua);
LessThanFunction = new LuaNativeFunction (MetaFunctions.LessThanLua);
LessThanOrEqualFunction = new LuaNativeFunction (MetaFunctions.LessThanOrEqualLua);
}
示例11: UnaryNegationLua
static int UnaryNegationLua (LuaState luaState, ObjectTranslator translator)
{
object obj1 = translator.GetRawNetObject (luaState, 1);
if (obj1 == null) {
translator.ThrowError (luaState, "Cannot negate a nil object");
LuaLib.LuaPushNil (luaState);
return 1;
}
Type type = obj1.GetType ();
MethodInfo opUnaryNegation = type.GetMethod ("op_UnaryNegation");
if (opUnaryNegation == null) {
translator.ThrowError (luaState, "Cannot negate object (" + type.Name + " does not overload the operator -)");
LuaLib.LuaPushNil (luaState);
return 1;
}
obj1 = opUnaryNegation.Invoke (obj1, new object [] { obj1 });
translator.Push (luaState, obj1);
return 1;
}
示例12: CollectObject
private static int CollectObject (LuaState luaState, ObjectTranslator translator)
{
int udata = LuaLib.LuaNetRawNetObj (luaState, 1);
if (udata != -1)
translator.CollectObject (udata);
return 0;
}
示例13: dumpStack
/// <summary>
/// Debug tool to dump the lua stack
/// </summary>
/// FIXME, move somewhere else
public static void dumpStack (ObjectTranslator translator, LuaCore.lua_State luaState)
{
int depth = LuaLib.lua_gettop (luaState);
Debug.WriteLine ("lua stack depth: " + depth);
for (int i = 1; i <= depth; i++) {
var type = LuaLib.lua_type (luaState, i);
// we dump stacks when deep in calls, calling typename while the stack is in flux can fail sometimes, so manually check for key types
string typestr = (type == LuaTypes.Table) ? "table" : LuaLib.lua_typename (luaState, type);
string strrep = LuaLib.lua_tostring (luaState, i).ToString ();
if (type == LuaTypes.UserData) {
object obj = translator.getRawNetObject (luaState, i);
strrep = obj.ToString ();
}
#if WINDOWS_PHONE
Debug.WriteLine("{0}: ({1}) {2}", i, typestr, strrep);
#elif !SILVERLIGHT
Debug.Print ("{0}: ({1}) {2}", i, typestr, strrep);
#endif
}
}
示例14: toString
private static int toString (LuaCore.lua_State luaState, ObjectTranslator translator)
{
object obj = translator.getRawNetObject (luaState, 1);
if (!obj.IsNull ())
translator.push (luaState, obj.ToString () + ": " + obj.GetHashCode ());
else
LuaLib.lua_pushnil (luaState);
return 1;
}
示例15: collectObject
private static int collectObject (LuaCore.lua_State luaState, ObjectTranslator translator)
{
int udata = LuaLib.luanet_rawnetobj (luaState, 1);
if (udata != -1)
translator.collectObject (udata);
return 0;
}