ObjectCaster

使用例子1

Instance().GetLuaEnv().DoString("return collectgarbage('count')")[0]);
//LuaEnv.cs
public object[] DoString(byte[] chunk, string chunkName = "chunk", LuaTable env = null)
{
    //......
    if (LuaAPI.lua_pcall(_L, 0, -1, errFunc) == 0)
    {
        LuaAPI.lua_remove(_L, errFunc);
        return translator.popValues(_L, oldTop);
    }
    //......        
}
//ObjectTranslator.cs
internal object[] popValues(RealStatePtr L,int oldTop)
{
    //...
    ArrayList returnValues=new ArrayList();
    for(int i=oldTop+1;i<=newTop;i++)
    {
        returnValues.Add(GetObject(L,i));
    }
    //...
}
internal object GetObject(RealStatePtr L,int index)
{
    return (objectCasters.GetCaster(typeof(object))(L, index, null));
}

其实简单来说就是lua层的未知的值传给C#,C#需要把Lua栈种的值转为C#类型

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

大纲

Share the Post:
滚动至顶部