Register | Login
Forum Index > Source Help > Ziron_RegisterUFunction example
Author Message
Pages: 1
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[892] Ziron_RegisterUFunction example - posted: 2011-11-27 21:21:16

hi Colin

can you please a working example of Ziron_RegisterUFunction function please.

http://www.freewebs.com/ogremagic/index.htm
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[895] - posted: 2011-11-28 16:55:55

Hi , i really need a working example of Ziron_RegisterUFunction function.

and how to ues Ziron_CallUFunc .

http://www.freewebs.com/ogremagic/index.htm
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[897] - posted: 2011-11-28 20:50:10
Hi Emil, i have written a sample, but i'm making some changes and adding a new event before i post the sample, hopefully soon.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[899] - posted: 2011-11-28 22:48:19
ok here is sample plugin of using these 2...

Code:
program WIN32DLL 'test plugin';

#include 'zirplug/framework.zir';
#include 'strings.zir';

const strLoaded = 'Sleep seconds plugin has loaded';

DWord u_Sleep_S;

function event_ssleep() {
  if (u_Sleep_S == 0) {
    return false;
  }

  uses edi;
  char myBuf[64];

  eax = Ziron_ExpectNextToken(zirNumber);
  if (eax == -1) {
    Ziron_FatalError('ssleep an integer value');
    return true;
  }  
  
  edi = Ziron_GetStringValue();
    
  myBuf = 0;
  
  strJoin(@myBuf, '(', edi, ')', 64);
  
  eax = Ziron_ExpectNextToken(zirSemi_Colon);
  if (eax == -1) {
    Ziron_FatalError('ssleep expected ; after second sleep value');
    return true;
  }    
  
  //now call the function (will return false if failed
  Ziron_CallUFunc(u_Sleep_S, @myBuf);
  
  return eax;
}


function InitPlugin(pointer pGetF) {
  Ziron_LoadAll(pGetF); //use framework utility function to load all

  Ziron_RegisterKeyword('ssleep', @event_ssleep);
  
  return strLoaded;
}

procedure ProgramBegin(char* apptype) {
  //note that submitting includes should never be done inside InitPlugin.
  Ziron_Exec('#include \'kernel32.zir\';'); //required for winapi function sleep

  u_Sleep_S = Ziron_RegisterUFunction(
    'function Sleep_S(DWord seconds) {'
      + ' eax = seconds;'
      + ' imul eax, 1000'
      + ' sleep(eax); }'
  );
}

entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
  if (iReason == DLL_PROCESS_ATTACH) {
    return true;
  }

  return false;
}

exports InitPlugin, ProgramBegin;


I will release the beta update after i finish adding another pf function.

this plugin would allow the usage of the following code inside a source:
Code:
ssleep 5;


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[901] - posted: 2011-11-28 23:44:04
i've updated the beta.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 639
Topics: 104

Location:
Alex, Egypt
[904] - posted: 2011-11-29 20:25:41

nice example.

l have add this for the sake of the simple strjoin , so i can use Ziron_GetStringValue directly in strjoin function.
Code:
inline function Ziron_GetStrValue()
{
   edx = Ziron_GetStringValue();
   $return edx;
}


so i can use this
Code:
  myBuf = 0;
  strJoin(@myBuf, '(', Ziron_GetStrValue(), ')', 64);


http://www.freewebs.com/ogremagic/index.htm
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 1 user(s) online. 0 member(s) and 1 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1850 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2025 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd