I found nice tutor about
#emit on samp forums. I'm trying to call public function, here is a code:
PHP Code:
#include <amxmodx>
public Func(const iVar)
{
server_print(" * Func called, var is %d", iVar);
}
public plugin_init()
{
new iPointer, iVar = random_num(0, 255);
server_print(" * plugin_init: random_num is %d", iVar);
// Get pointer to function
#emit CONST.pri Func
#emit STOR.S.pri iPointer
// Push variable
#emit LOAD.S.pri iVar
#emit PUSH.pri
// Bytes passed to "Func"
#emit PUSH.C 4
// Call "Func"
#emit LOAD.S.pri iPointer
#emit CALL.pri
}
It works fine, but i don't know how to get function pointer by funcidx. I tried insctructions from tutor above, but server crashes. I tried to use this code to get pointer by idx:
PHP Code:
new
idx = funcidx("Func1"),
pointer;
// Get the pointer to the public function list.
#emit LCTRL 1
#emit NEG
#emit ADD.C 32
#emit STOR.S.pri pointer
#emit LREF.S.alt pointer
// Get the pointer to the function at the given index.
#emit LCTRL 1
#emit NEG
#emit ADD
#emit LOAD.S.alt idx
#emit SHL.C.alt 3
#emit ADD
#emit STOR.S.pri pointer
#emit LREF.S.pri pointer
#emit STOR.S.pri pointer
Any ideas?
__________________