SA-MP Forums Archive
[Include] TDW CJump - nonlocal gotos in Pawn - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] TDW CJump - nonlocal gotos in Pawn (/showthread.php?tid=638990)



TDW CJump - nonlocal gotos in Pawn - VVWVV - 09.08.2017

TDW CJump
Description
This library provides you the opportunity to use nonlocal gotos as well as in C language. It is important to note that this one supports JIT-plugin.
Documentation
In Pawn there is a goto operator which provides an unconditional jump from the 'goto' to a labeled statement in the same function. This operator can only jump within the same function, but the library provides a nonlocal unconditional jump between functions.

Functions
NameDescription
setjmpSaves the current environment into the variable for later use by the function longjmp.
Parameters:
  • env[JmpBuf] - buffer for storing environments.
  • &retval - the reference to a variable into which will be written the value from the function longjmp.
longjmpRestores the environment saved by the function setjmp.
Parameters:
  • env[JmpBuf] - buffer for storing environments.
  • val - return value.
Example
pawn Код:
new jmp[JmpBuf];

main() {
    new ret;
    setjmp(jmp, ret);  // save the current environment into the buffer.

    print(!"main()");  // this code will be executed several times.

    if (ret != 2) {    // we need to use the condition to avoid an infinite loop.
        somefunc(ret);
    }
}

somefunc(ret)
{
    print(!"somefunc()");
    longjmp(jmp, ret+1);  // global goto.
}
Download
github
Author: VVWVV
Licensed under the zlib.



Re: TDW CJump - nonlocal gotos in Pawn - Xeon™ - 11.08.2017

based on script, Good job.

i bet the most of people (me too ) here, don't know what is this.
suggestion: you should add more informations.


Re: TDW CJump - nonlocal gotos in Pawn - VVWVV - 11.08.2017

Quote:
Originally Posted by XeonMaster
Посмотреть сообщение
based on script, Good job.

i bet the most of people (me too ) here, don't know what is this.
suggestion: you should add more informations.
Thank you!

I added more information in the documentation section.