-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Double call 'dofile' for nut with 'newslot' #242
Comments
Uhmm sounds to me like this is what you would want to happen? new methods replace the old ones in already-existing slots... maybe you should make a small test case to post here... |
'!_table(self)->Get(key,res)' return 'false' and 'CallMetaMethod' does't set the new methods so 'if(rawcall) _table(self)->NewSlot(key,val); ' set the empty slot instead old. As result I lose all the existing methods for this slot. |
Calling |
'What are you using a _newslot metamethod for?' - in
|
Now it sounds like you're saying that you want newslot to run when the slot isn't new. Try using _set and _get instead? |
My task was initially to solve an issue with exported methods deleting after the second call of 'dofile'. I just wonder whether this action is a bug. I found the place in the code of the virtual machine squirrel (see my first message) where I see the logic of a single call of 'newslot' for every 'nut' file and the deletion of already exported methods. This issue is possible to solve by changing the code above to this one:
Are these fix valid? Can you advise how to test it? (in case this was really a bug) |
I still doubt anyone can understand what you're going on about without an example, which you haven't given. The most general way of using squirrel would be to have dofile define functions and if you run it again, the functions will be defined again. Sounds like that's what's happening for you. If you don't want that to happen, you have to take precautions to avoid it. It's unbelievable to me that you would try to modify such a key function in squirrel instead of understanding the way squirrel is meant to work. |
Example:
When I call |
this example is not useful. Only you know how you're binding SomeFunc3 and SomeFunc4. Can you make an example that doesn't involve c++ binding? |
"Can you make an example that doesn't involve c++ binding?" - the problem reproduce with c++ binding only.
|
So you're saying when you attempt to bind SomeFunc3 a second time using this code, it doesn't work? What values end up being bound? The intended method for the 2nd time, the intended method for the 1st time, or nothing at all or something like null? you keep vaguely saying Honestly I don't think anyone will ever help you unless you make a complete demo with a standalone .c file. |
Hi everyone!
If I call 'dofile' for the same 'nut' twice 'newslot' isn't called for the second time and all the exported methods (from the first call of 'newslot') are lost.
Is it OK?
I guess the problem is in this code.
bool SQVM::NewSlot(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr &val,bool bstatic)
{
if(type(key) == OT_NULL) { Raise_Error(_SC("null cannot be used as index")); return false; }
switch(type(self)) {
case OT_TABLE: {
bool rawcall = true;
if(_table(self)->_delegate) {
SQObjectPtr res;
if(!_table(self)->Get(key,res)) {
Push(self);Push(key);Push(val);
rawcall = !CallMetaMethod(_table(self),MT_NEWSLOT,3,res);
}
}
if(rawcall) _table(self)->NewSlot(key,val); //cannot fail
The text was updated successfully, but these errors were encountered: