Ziron_SetFileBuffer function
well , could you please provide some example that uses the new function Ziron_SetFileBuffer.
http://www.freewebs.com/ogremagic/index.htm
well , could you please provide some example that uses the new function Ziron_SetFileBuffer.
http://www.freewebs.com/ogremagic/index.htm
i have not tested this but a quick example is:
function FileEntry(DWord handle; char* strCode) {
const maxLen = 512;
//create a buffer
char myBuffer[maxLen];
if (handle == 0) {
strlcpy(@myBuffer, 'program WIN32CUI \'test\'; #include \'console.zir\'; print(\'hello world!\r\n\'); wait_key(nil); ExitProcess(0);', 104);
//set the buffer
Ziron_SetFileBuffer(handle, @myBuffer, 104);
}
}
you would then export this function
exports InitPlugin, FileEntry;
now basically when this plugin is loaded, it will replace the main file with the above code, basically forcing the application to only compile a small hello world sample.
of course since this is static replacement you can just do:
function FileEntry(DWord handle; char* strCode) {
if (handle == 0) {
//set the buffer
Ziron_SetFileBuffer(handle, 'program WIN32CUI \'test\'; #include \'console.zir\'; print(\'hello world!\r\n\'); wait_key(nil); ExitProcess(0);', 104);
}
}
so the idea behind these functions is you are able to preprocess the file, change things (then set the new file buffer) and then ziron will compile/assemble the file as if it is the original :)
very good , thanks.
is the second argument of FileEntry is the address of original file buffer ?
and is the first argument is not zero , who can we make use of it ?
http://www.freewebs.com/ogremagic/index.htm
the first argument is a ziron handle to the file that is being entered, so for example
most likely the first included file will be id 1, and so on.. so for each included file you would preprocess the file and pass it back with the handle that was passed, i just checked for 0 as example of replacing the main file..
the second argument yes is the char pointer to the actually internal buffer and should not be changed directly, you would scan through this code and place your changed version into your own buffer, then pass it via Ziron_SetFileBuffer.
hope you understand :)
is that mean , Ziron will call FileEntry function many times ( per included file),
and we have to check that by first param?
http://www.freewebs.com/ogremagic/index.htm
it will call it only when a new file is opened and a new internal buffer is being created for the file...
so...
program WIN32CUI 'temp';
#include 'kernel32.zir';
ExitProcess(0);
in this situation, FileEntry will be called a twice, the first is the actual project file (the code above) and the second will be the entrance to the inclued file 'kernel32.zir'
of course if you include 'console.zir' it also has its own included files, so it will also be called when they are entered
program WIN32CUI 'temp';
#include 'kernel32.zir';
#include 'kernel32.zir';
ExitProcess(0);
this above would still be twice, because the second include is ignored.
ok, the next code gives this error
List index out of bounds (2)
function GetNextLine(char* strbuf; pointer dest)
{
global int32 incr;
uses esi edi;
eax = xor;
ecx = incr;
esi = strbuf;
add esi, ecx
edi = dest;
while(char[esi] != 0)
{
if (word[esi] == "\r\n")
{
eax += 2;
break;
}
bl = char[Esi];
char[edi] = bl;
eax++;
esi++;
edi++;
}
char[edi] = 0;
add ecx, eax
incr = ecx;
}
function FileEntry(DWord handle; char* strCode)
{
const maxLen = 512;
//create a buffer
char myBuffer[maxLen];
//preprocess the main file
if (handle == 0)
{
push edi
edi = GetNextLine(strCode,@myBuffer);
while(edi > 0)
{
Ziron_ShowMessage(@myBuffer);
edi = GetNextLine(strCode,@myBuffer);
}
pop edi
}
}
http://www.freewebs.com/ogremagic/index.htm
i do not see any problems in this code, the problem must lie in another part of the code
EDIT: i see the problem, i will fix this and re-update package shortly - else i tested and have your code compiled and works fine.