Checking if a function exists at compile time: native function failed at run time -
dusk - 27.03.2014
I need to check if a function is defined(for an include). So I wrote this code:
pawn Код:
#if !defined fcreate
stock fcreate(const filename[])
{
printf("Fcreatea: start");
if(!fexist(filename))
{
printf("Fcreatea: the file does Not exist");
new File:file = fopen(filename,io_write);
printf("Fcreatea: file opened");
return fclose(file);
}
return 0;
}
#endif
And a backtrace from crashdetect:
pawn Код:
[18:49:49] [debug] Run time error 10: "Native function failed"
[18:49:49] [debug] fread
[18:49:49] [debug] AMX backtrace:
[18:49:49] [debug] #0 00000c50 in public OnGameModeInit () from speed.amx
I used the function in OnGameModeInit hook:
pawn Код:
printf("File does NOT exist");
fcreate(BAN_FILE_NAME);
I left those prints there for a reason. This is the last thing printed out before "Native function failed":
pawn Код:
[18:49:49] File does NOT exist
Which is just before calling the function "fcreate"
If I remove the #if !defined part, it runs just like it should. But this is not a sollution.
All ideas will be appreciated
Re: Checking if a function exists at compile time: native function failed at run time -
RajatPawar - 27.03.2014
To check for the existance of a function, use
https://sampwiki.blast.hk/wiki/Funcidx (works only for publics)
Re: Checking if a function exists at compile time: native function failed at run time -
dusk - 27.03.2014
That doesn't really help..(I think) I need to define it if it doesn't exist
Re: Checking if a function exists at compile time: native function failed at run time -
Konstantinos - 27.03.2014
Unless you do it with
#define:
pawn Код:
#if !defined fcreate
#define fcreate(%0); if (!fexist(%0)) { new File:file = fopen(%0,io_write); if(file) fclose(file); }
#endif
Re: Checking if a function exists at compile time: native function failed at run time -
dusk - 27.03.2014
Quote:
Originally Posted by Konstantinos
Unless you do it with #define:
pawn Код:
#if !defined fcreate #define fcreate(%0); if (!fexist(%0)) { new File:file = fopen(%0,io_write); if(file) fclose(file); } #endif
|
Well that works, thanks
Re: Checking if a function exists at compile time: native function failed at run time -
RajatPawar - 27.03.2014
EDIT: Late! Ignore. Sorry, didn't actually read the post, just replied by the title! You want to check if a function exists somewhere else, and if not, then define it? Can you actually run a test with an empty print stock? A stock that simply prints. The problem may be in your stock. IIRC, file functions crash when the file handle is invalid, etc. So checks for that.. I can't view your code, sorry, on mobile.
Re: Checking if a function exists at compile time: native function failed at run time -
dusk - 27.03.2014
Quote:
Originally Posted by Rajat_Pawar
EDIT: Late! Ignore. Sorry, didn't actually read the post, just replied by the title! You want to check if a function exists somewhere else, and if not, then define it? Can you actually run a test with an empty print stock? A stock that simply prints. The problem may be in your stock. IIRC, file functions crash when the file handle is invalid, etc. So checks for that.. I can't view your code, sorry, on mobile.
|
I did create a simple stock... All it did was print a string... It still crashed..
Re: Checking if a function exists at compile time: native function failed at run time -
dusk - 29.03.2014
bump
Re: Checking if a function exists at compile time: native function failed at run time -
RajatPawar - 29.03.2014
Quote:
Originally Posted by dusk
Well that works, thanks
|
Hi! Didn't you reply that it worked?
Re: Checking if a function exists at compile time: native function failed at run time -
dusk - 29.03.2014
I did... I guess bumping has become a habbit for me.