when should #emit be used
#1

title says it all:

when should #emit be used?
Reply
#2

you dont need it, normally.
but it comes in handy for debugging stuff.

for example, static variables are of course static
and thus remain somewhere in the memory.
the following code proves that these Variables
can still be accessed, if you have their address.

pawn Code:
#include <a_samp>

public OnFilterScriptInit()
{
    printf("static abc: %d",ReadAmxMemory(myfunc()));
    return 1;
}

myfunc()
{
    static abc=200;//remains after execution!
    return ref(abc);
}

ref(...)
{
    assert(numargs() == 1);
    #emit load.s.pri 12 // first argument
    #emit retn
    return 0; // make compiler happy
}

ReadAmxMemory(address)
{
    #emit lref.s.pri address
    #emit retn
    return 0; // make compiler happy
}
like it's said in the comments, "return 0" is just there so that
the compiler is "happy" and not throwing some warnings.
"return 0" actually never gets executed as "#emit retn" jumps back to the program pointer, decreasing the stack pointer by 1
What happens here is
1) ReadAmxMemory // reading from an address, specifyed by us
2) create a static variable "abc" and return a reference of abc for ReadAmxMemory
3) Now ReadAmxMemory has the address of abc after myfunc got executed
4) it'll print "static abc: 200", proving that stic really means static :P

ye... but really, you dont need it.

doing
pawn Code:
i++;
instead of
pawn Code:
#emit INC i
is fine too
Reply
#3

The poster above me is right. All the possible needs of #emit have been SO FAR simplificated in libraries (amx_assembly as the lower level, y_va/md-sort/y_inline/packed-safe format (and others ready-to-use libraries) as the higher level and y_amx as the intermediate level.

You should normally never need to use #emit by yourself nowadays.
Reply
#4

https://sampforum.blast.hk/showthread.php?tid=315531

I think the first line sums it up.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)