示例#1
0
文件: tolua_is.c 项目: r8d8/Urho3D
TOLUA_API void tolua_error (lua_State* L, const char* msg, tolua_Error* err)
{
    if (msg[0] == '#')
    {
        const char* expected = err->type;
        const char* provided = tolua_typename(L,err->index);
        if (msg[1]=='f')
        {
            int narg = err->index;
            if (err->array)
                luaL_error(L,"%s\n     argument #%d is array of '%s'; array of '%s' expected.\n",
                           msg+2,narg,provided,expected);
            else
                luaL_error(L,"%s\n     argument #%d is '%s'; '%s' expected.\n",
                           msg+2,narg,provided,expected);
        }
        else if (msg[1]=='v')
        {
            if (err->array)
                luaL_error(L,"%s\n     value is array of '%s'; array of '%s' expected.\n",
                           msg+2,provided,expected);
            else
                luaL_error(L,"%s\n     value is '%s'; '%s' expected.\n",
                           msg+2,provided,expected);
        }
    }
    else
        luaL_error(L,msg);
}
void luaval_to_native_err(lua_State* L,const char* msg,tolua_Error* err, const char* funcName)
{
    if (NULL == L || NULL == err || NULL == msg || 0 == strlen(msg))
        return;

    if (msg[0] == '#')
    {
        const char* expected = err->type;
        const char* provided = tolua_typename(L,err->index);
        if (msg[1]=='f')
        {
            int narg = err->index;
            if (err->array)
                CCLOG("%s\n     %s argument #%d is array of '%s'; array of '%s' expected.\n",msg+2,funcName,narg,provided,expected);
            else
                CCLOG("%s\n     %s argument #%d is '%s'; '%s' expected.\n",msg+2,funcName,narg,provided,expected);
        }
        else if (msg[1]=='v')
        {
            if (err->array)
                CCLOG("%s\n     %s value is array of '%s'; array of '%s' expected.\n",funcName,msg+2,provided,expected);
            else
                CCLOG("%s\n     %s value is '%s'; '%s' expected.\n",msg+2,funcName,provided,expected);
        }
    }
}
示例#3
0
  bool transduceStackValues(lua_State* from, lua_State* to, int start, int count) {
    int to_top = lua_gettop(to);
    for (int i = start; i < start + count; i++) {
      // Move all parameters to new environment
//      cout << lua_typename(from, lua_type(from, i)) << endl;
      switch (lua_type(from, i)) {
        case LUA_TNIL:
          lua_pushnil(to);
          break;
        case LUA_TNUMBER:
          lua_pushnumber(to, lua_tonumber(from, i));
          break;
        case LUA_TBOOLEAN:
          lua_pushboolean(to, lua_toboolean(from, i));
          break;
        case LUA_TSTRING:
          lua_pushstring(to, lua_tostring(from, i));
          break;
//        case LUA_TTABLE:  // TODO !
//          break;
        case LUA_TUSERDATA:
//          cout << "  Transducing " << tolua_typename(from, i) << endl;
          tolua_pushusertype(to, tolua_tousertype(from, i, NULL), tolua_typename(from, i));
          break;
        default:
          lua_settop(to, to_top);
          return false;
      }
    }
    return true;
  } 
示例#4
0
void PrintTable(lua_State *L, int tabCount)
{
    lua_pushnil(L);
    printf("{\n");
    while(lua_next(L, -2) != 0)
    {
        for (int c = 0; c < tabCount; c++) {
            printf("\t");
        }
        if(lua_isstring(L, -1))
            printf("\t%s = %s\n", lua_tostring(L, -2), lua_tostring(L, -1));
        else if(lua_isnumber(L, -1))
            printf("\t%s = %d\n", lua_tostring(L, -2), lua_tonumber(L, -1));
        //else if(lua_isfunction(L, -1))
        //    printf("\t%s = %s\n", lua_tostring(L, -2), lua_tostring(L, -1));
        else if(lua_istable(L, -1)) {
            printf("\t%s = ", lua_tostring(L, -2));
            PrintTable(L,tabCount+1);
        }
        else {
            int t = lua_type(L, -1);
            //printf("\t%s = %s\n", lua_tostring(L, -2), lua_typename(L, t));
            char* type = (char*)tolua_typename(L, -1);
            lua_pop(L, 1);
            printf("\t%s = %s\n", lua_tostring(L, -2), type);
            
        }
        lua_pop(L, 1);
    }
    printf("}\n");
}
示例#5
0
/* Default collect function
*/
TOLUA_API int tolua_default_collect (lua_State* tolua_S)
{
 const char *tname = tolua_typename(tolua_S, 1);
 void* self = tolua_tousertype(tolua_S,1,0);
 free(self);
 return 0;
}
LuaObject LuaGlobalSelector::toLuaObject( void ) const
{
	magicalAssert( !_key.empty(), "key should not be empty!" );
	lua_State* L = _L->cPtr();
	LuaObject lobj;
	lua_getglobal( L, _key.c_str() );

	switch( lua_type( L, -1 ) )
	{
	case LUA_TNIL:
		lobj = nullptr;
		break;
	case LUA_TBOOLEAN:
		lobj = (bool) lua_toboolean( L, -1 );
		break;
	case LUA_TNUMBER:
		lobj = (double) lua_tonumber( L, -1 );
		break;
	case LUA_TSTRING:
		lobj = lua_tostring( L, -1 );
		break;
	case LUA_TUSERDATA:
		{
			int top = lua_gettop( L );
			std::string type = tolua_typename( L, top );
			lua_pop( L, 1 );
			void* userdata = tolua_tousertype( L, top, 0 );
			lobj.set( userdata, type.c_str() );
		}
		break;
	case LUA_TFUNCTION:
		{
			LuaFunction lf;
			int handler = tolua_ext_tofunction( L, lua_gettop( L ), 0 );
			if( handler != 0 )
			{
				lf.bind( _L, handler );
			}
			lobj = lf;
		}
		break;
	case LUA_TTABLE:
		{
			LuaTable lt;
			int handler = tolua_ext_totable( L, lua_gettop( L ), 0 );
			if( handler != 0 )
			{
				lt.bind( _L, handler );
			}
			lobj = lt;
		}
		break;
	default:
		lobj = nullptr;
		break;
	}
	lua_pop( L, 1 );
	return lobj;
}
示例#7
0
Common::UString Stack::getExactTypeAt(int index) const {
	if (!checkIndex(index)) {
		return "none";
	}

	const Common::UString type = tolua_typename(&_luaState, index);
	lua_pop(&_luaState, 1);
	return type;
}
示例#8
0
/* Object type
*/
static int tolua_bnd_type (lua_State* L)
{
	tolua_typename(L,lua_gettop(L));
	return 1;
}