asm-test.pwn 883 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <a_samp>
  2. #include "..\asm"
  3. #include "..\dynamic_call"
  4. forward HandleAsmError(ctx[AsmContext], AsmError:error);
  5. main() {
  6. // Have to use print() somewhere to make GetNativeAddressFromName() work.
  7. print("Doing #emit at runtime!");
  8. new code[10];
  9. new ctx[AsmContext];
  10. AsmInit(ctx, code);
  11. AsmSetErrorHandler(ctx, GetPublicAddressFromName("HandleAsmError"));
  12. // Build a function that prints a string and returns:
  13. //
  14. // PrintString(const string[]) {
  15. // printf(string);
  16. // }
  17. //
  18. // NOTE: "print" must be called somwhere else in order to for this work!
  19. @emit proc
  20. @emit push.arg 0
  21. @emit push.num.args 1
  22. @emit sysreq "print"
  23. @emit pop.args 1
  24. @emit retn
  25. if (AsmGetError(ctx) == ASM_ERROR_NONE) {
  26. CallFunction(AsmGetCode(ctx), ref("Hello!"));
  27. }
  28. }
  29. public HandleAsmError(ctx[AsmContext]) {
  30. printf("AsmError: %d", _:AsmGetError(ctx));
  31. }