YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

SQVM::Set - bug or not?
VoidSpirit
#1 Posted : Tuesday, December 27, 2016 3:15:21 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/27/2016(UTC)
Posts: 7

Thanks: 0 times
Was thanked: 2 time(s) in 2 post(s)
Hello!

I tryed to make a delegate for user data and set to it a '_set' metamethod. But in SQVM::Set I see:
in first switch default section contains an error raising with types other than table, instance, array. Thus
an execution does not continue with data user type and FallBackSet does not work;
I have removed an error raising and method works right. Is it a bug or my mistake?
absence
#2 Posted : Friday, December 30, 2016 4:20:26 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 109
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
Probably no bug. The default SET should not be called for other types than those you mentioned.
I anticipate your issue is about delegation being the wrong way, maybe?

(However, I'm not sure if I got what you want to achieve or what exactly you did for that, please provide more detailed info)
VoidSpirit
#3 Posted : Sunday, January 1, 2017 5:49:32 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/27/2016(UTC)
Posts: 7

Thanks: 0 times
Was thanked: 2 time(s) in 2 post(s)
I want enter my application classes into squirrel system throw user data, with custom setting and getting properties. Thus I need both _set and _get metamethods. Other way userdata useless without normal delegate's functionality
fagiano
#4 Posted : Monday, January 2, 2017 7:52:07 AM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,056

Thanks: 0 times
Was thanked: 78 time(s) in 60 post(s)
"userdata" should have a _set metademothd working. That is a bug, ops, sorry!. This is most probably because since I introduced classes with "user data size" sq_setclassudsize(), userdata has become borderline obsolete as classes tend to be more efficient most of the time, so it hasn't been used much.
Anyway no its no excuse, it should still work.

this should fix it as you already figured it out
Code:

bool SQVM::Set(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr &val,SQInteger selfidx)
{
    switch(type(self)){
    case OT_TABLE:
        if(_table(self)->Set(key,val)) return true;
        break;
    case OT_INSTANCE:
        if(_instance(self)->Set(key,val)) return true;
        break;
    case OT_ARRAY:
        if(!sq_isnumeric(key)) { Raise_Error(_SC("indexing %s with %s"),GetTypeName(self),GetTypeName(key)); return false; }
        if(!_array(self)->Set(tointeger(key),val)) {
            Raise_IdxError(key);
            return false;
        }
        return true;
    case OT_USERDATA: break; //must fallback
    default:
        Raise_Error(_SC("trying to set '%s'"),GetTypeName(self));
        return false;
    }

    switch(FallBackSet(self,key,val)) {
        case FALLBACK_OK: return true; //okie
        case FALLBACK_NO_MATCH: break; //keep falling back
        case FALLBACK_ERROR: return false; // the metamethod failed
    }
    if(selfidx == 0) {
        if(_table(_roottable)->Set(key,val))
            return true;
    }
    Raise_IdxError(key);
    return false;
}


ciao
Alberto
Follow me on Twitter @squirrellang
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.084 seconds.