noeticwxb / luainterface

Automatically exported from code.google.com/p/luainterface
0 stars 0 forks source link

crash when lua["TableName'] return null several times #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
  LuaTable table=lua.GetTable("TablenName"); where "TableName" NOT EXISTS In Lua State.

when lua_getglobal(luastate,name) get nothing from luastate,"nil" will be at 
top of stack.if call "lua_getglobal(luastate,name)" many times,the stack will 
fill with nil and crash.

solution:
lua.cs:
public object this[string fullPath]
{
    get 
    {
        object returnValue=null;
        int oldTop=LuaDLL.lua_gettop(luaState);
        string[] path=fullPath.Split(new char[] { '.' });
        LuaDLL.lua_getglobal(luaState,path[0]);
        returnValue=translator.getObject(luaState,-1);
                if (returnValue == null) {

                    //by issingle 2010-12-20 23:06:36 
                    //说明: 如果没有获取到任何东西,需要清理一下堆栈,
                    //否则多次调用后,nil将把堆栈填满了
                    //if get nothing,we need pop nil,or the nil value
                    //will increase in stack.
                    //see:http://lua-users.org/lists/lua-l/2008-07/msg00099.html
                    LuaDLL.lua_pop(luaState, 1);
                    return null;
                }
        if(path.Length>1) 
        {
            string[] remainingPath=new string[path.Length-1];
                Array.Copy(path,1,remainingPath,0,path.Length-1);
                        returnValue=getObject(remainingPath);
        }
        LuaDLL.lua_settop(luaState,oldTop);
        return returnValue;
}

Maybe some place i dont know need fix too.

Original issue reported on code.google.com by isSin...@gmail.com on 20 Dec 2010 at 3:33

GoogleCodeExporter commented 8 years ago
oh~~~,faint.

my version  was modified by myself,the google code version is OK.
PELEASE CLOSE THIS ISSUE.

SORRY -_-!

Original comment by isSin...@gmail.com on 20 Dec 2010 at 3:41

GoogleCodeExporter commented 8 years ago
Closing as per request by submitter.

Original comment by eonstorm@gmail.com on 8 Feb 2011 at 7:01