UnWrapObject() public static method

Unwaps an object comming from LuaInterface for use in DynamicLua.
public static UnWrapObject ( object wrapped, NLua.Lua state, string name = null ) : object
wrapped object
state NLua.Lua
name string
return object
Example #1
0
        public override bool TryConvert(ConvertBinder binder, out object result)
        {
            result = null;

            if (binder.Type == typeof(object[]))
            {
                result = array;
                return(true);
            }

            if (array.Length != 1)
            {
                return(false);
            }

            if (array[0].GetType() == typeof(LuaTable) || array[0].GetType() == typeof(LuaFunction))
            {
                result = LuaHelper.UnWrapObject(array[0], state);
                return(true);
            }

            if (array[0].GetType() != binder.Type)
            {
                return(false);
            }

            result = Convert.ChangeType(array[0], binder.Type);
            return(true);
        }
Example #2
0
        private object GetTableValue(string name)
        {
            LuaFunction func = GetMetaFunction("index");

            if (func != null) //metatable and metamethod set
            {
                return(LuaHelper.UnWrapObject(func.Call(table, name)[0], state, path + "." + name));
            }
            else
            {
                return(LuaHelper.UnWrapObject(table[name], state, path + "." + name));
            }
        }
Example #3
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            int index;

            result = null;
            if (!int.TryParse(binder.Name, out index))
            {
                return(false);
            }
            if (index >= array.Length)
            {
                return(false);
            }

            result = LuaHelper.UnWrapObject(array[index], state);
            return(true);
        }
Example #4
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            int index;

            result = null;
            if (!int.TryParse(indexes[0].ToString(), out index))
            {
                return(false);
            }
            if (index >= array.Length)
            {
                return(false);
            }

            result = LuaHelper.UnWrapObject(array[index], state);
            return(true);
        }
Example #5
0
        private object GetTableValue(string name)
        {
            object val = table[name];

            if (val != null)
            {
                return(LuaHelper.UnWrapObject(val, state, path + "." + name));
            }

            //not found, check __index of metatable

            LuaFunction func = GetMetaFunction("index");

            if (func != null) //metatable and metamethod set
            {
                return(LuaHelper.UnWrapObject(func.Call(table, name)[0], state, path + "." + name));
            }
            else
            {
                return(null);
            }
        }
Example #6
0
 public dynamic GetMetatable()
 {
     return(LuaHelper.UnWrapObject(state.DoString(String.Format("return getmetatable({0})", path), "DynamicLua internal operation")[0], state));
 }
Example #7
0
 private object GetLuaValue(string name)
 {
     return(LuaHelper.UnWrapObject(lua[name], lua, name));
 }