Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Plugins

Ziron_GetStringValue Eaxmple

A community discussion post from the original code:zIRON forum.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

Ziron_GetStringValue Eaxmple

could you please post an example that demonstrate the Ziron_GetStringValue Function.

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

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

There is a bug, that i have fixed haha, anyways here is an example

const strLoaded = 'Test plugin has loaded!';

function event_KeyTest() {
	//first get string value of KeyTest
	eax = Ziron_GetStringValue();
	Ziron_ShowMessage(eax);

	eax = expectNextToken(zirConstString);
	if (eax == -1) {
		Ziron_FatalError('No constant string found');
		return true;
	}
	
	eax = Ziron_GetStringValue(); //get the string contents of 'the string'
	Ziron_ShowMessage(eax);
	
	eax = true;
}

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

  //register our keyword
  Ziron_RegisterKeyword('KeyTest', @event_Test);
  
  return strLoaded;
}

and usage:

program WIN32CUI 'test';

#include 'console.zir';

eax = 1;
print('eax = ', eax:int, '\r\n');

KeyTest 'my string';

print('eax = ', eax:int, '\r\n');

wait_key(nil);
ExitProcess(0);

this should output

KeyTest

my string

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , here is my first step in creating Basic-like syntax , but have some problems.

so i want to pares this line

Dim Var as int32;

SO here is the Basic PlugIn

program WIN32DLL 'BASIC PLUGIN';

#include 'zirplug/framework.zir';

//////////////////////////////

const strLoaded = 'Basic plugin has loaded!';

function event_Dim() {
    uses edi;  
    eax = Ziron_ExpectNextToken(zirIdent);
	if (eax == -1) {
		Ziron_FatalError('Expected Variable Name');
		return true;
	}
		
    eax =  Ziron_GetStringValue();
	
    Ziron_ShowMessage(eax);   // this must print 'Var' but is does not 
         
    eax = Ziron_ExpectNextToken(zirAs);
	if (eax == -1) {
		Ziron_FatalError('Expected as Keyword');
		return true;
	}
	
	eax = Ziron_ExpectNextToken(zirDATA_TYPE);
	if (eax == -1) {
		Ziron_FatalError('Expected data type');
		return true;
	}
	edi = Ziron_GetTypeSize();
	
	
	return true;
}

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

	//register our keyword
	Ziron_RegisterKeyword('Dim', @event_Dim);
	
	return strLoaded;
}

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

  return false;
}

exports InitPlugin;

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

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

i have tested with ver 1.1.26.1 alpha

it works fine , i will keep playing with Basic syntax.

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

Colin admin
Posts
928
Threads
49
Location
Bulgaria

did you get latest update i sent in PM ?

Colin admin
Posts
928
Threads
49
Location
Bulgaria

ok posted too late :)

Colin admin
Posts
928
Threads
49
Location
Bulgaria

btw, looking good, i look forward to your progress :)

ps:

  eax = Ziron_ExpectNextToken(zirDATA_TYPE);
  if (eax == -1) {
    Ziron_FatalError('Expected data type');
    return true;
  }
  edi = Ziron_GetTypeSize();
  

this here can be again getstringvalue, then you can build a buffer to output the ziron syntax 'datatype_str ident_str' via Ziron_Execute('...

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

oh , got access violation.

function  H_strcpy(Dword dst,src)
{ 
  Eax = dst; 
  Edx = src; 
  push Eax;
  BL =  [Edx]; 
  while ( BL != 0)  
   { 
      [Eax] = BL; 
      Eax++; Edx++; 
      BL =  [Edx]; 
   }  
  [Eax] = 0;
  pop Eax;
} 

function H_strcat(Dword dst,src) 
{ 
  Eax = dst; 
  Edx = src;
  push Eax;
  while (byte [Eax] != 0) { Eax++; } 
  while (byte [Edx] != 0)  
   { 
      BL =  [Edx]; 
      [Eax] = BL;  
      Edx++; Eax++; 
   } 
  [Eax] = 0;
  pop Eax;
} 


function event_Dim() {
    uses edi;  
    char var[255];  
    char buf[1024]; 
       
    eax = Ziron_ExpectNextToken(zirIdent);
    if (eax == -1) {
		Ziron_FatalError('Expected Variable Name');
		return true;
     }
    eax =  Ziron_GetStringValue();
    H_strcpy(@var,eax);
    Ziron_ShowMessage(@var);
         
    eax = Ziron_ExpectNextToken(zirAs);
    if (eax == -1) {
		Ziron_FatalError('Expected as Keyword');
		return true;
     }
    eax = Ziron_ExpectNextToken(zirDATA_TYPE);
    if (eax == -1) {
		Ziron_FatalError('Expected data type');
		return true;
     }
    edi = Ziron_GetTypeSize();
    eax =  Ziron_GetStringValue();
    Ziron_ShowMessage(eax);
    
    H_strcat(@buf,eax); 
    H_strcat(@buf,' ');  
    H_strcat(@buf,@var);
    H_strcat(@buf,';');  
    H_strcat(@buf,'\r\n'); 
    Ziron_ShowMessage(@buf);

    
}

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