Native stack overflow on _get

Started by EK.IceFlake, Feb 28, 2017, 12:18 PM

Previous topic - Next topic

EK.IceFlake

Quote from: happymint on Feb 28, 2017, 05:44 PMWith some serious workarounds this is achievable. Not pretty but achievable.

class CPlayer
{
    value = null;
    function constructor(v) { value = v; }
}

// We use this approach so that squirrel can see and use
//  the function names in debug messages even after we clone them.
AccountDelegates <- {
    function _get(idx) {
        ::print(this.value);
        return null;
    }
    function _set(idx, val) {
        ::print(this.value);
        return idx;
    }
};

CPlayer.newmember("Account", null);
// Delegates are referenced with a weak reference.
// Therefore, they must be referenced somewhere with a strong reference.
CPlayer.newmember("AccountDelegates", null);

// Construct an instance
local p = CPlayer(23);

// Forcefully bind a predefined environment
p.AccountDelegates = {
    _get = AccountDelegates._get.bindenv(p),
    _set = AccountDelegates._set.bindenv(p),
};
// Finally, create the table with our delegates
p.Account = {}.setdelegate(p.AccountDelegates);

p.Account.test = "1";
That would require some changes to the official plugin so that events would work properly. I guess I'd be better off making an account system on your plugin.

.

Quote from: EK.IceFlake on Feb 28, 2017, 05:56 PM... I guess I'd be better off making an account system on your plugin.

I'm working on the same thing. But I just nuked my Windows since my previous post so now I have to set my stuff up before I can do anything again :D
.