Callbacks with a limited scope
#1

Hi, is it possible to create callbacks with a limited scope? I need callbacks which are available only in the include file. I know that it is possible to create functions with a limited scope through "static".

Код:
//For instance, file "some_inc.inc"
static SomeFunc() { } //wiil be available only in this file
How can I do the same thing with callbacks? Is this possible?

Why I need this? Because I can't use timers for functions.
Reply
#2

This is possible
I just checked.
If someone interested, I used:
Код:
//File "some_inc.inc"
static @SomeFunc();
static @SomeFunc() { }
//@SomeFunc is available only in this file.
P.S.
But it works a little bit different rather than "static" functions.
If someone has other methods, please share.
Reply
#3

Any ideas? (up)
Reply
#4

Declare static variable & function wille make them only available in the current file. There is no other better method. What's the problem with the "static" keyword?
Reply
#5

Thank you for answers.
Reply
#6

But there is a bug of the compiler. As DC (Daniel_Cortez) tested, there is some possible way to do it.

myinc.inc
PHP код:
static @SomeFunc();
static @
SomeFunc()
{
    
emit const.pri 0;

main.p:
PHP код:
#include "myinc.inc"
 
@SomeFunc();
@
SomeFunc()
{
    
emit const.pri 1;
}
 
main()
{
    @
SomeFunc();

Output pawndisasm:
PHP код:
00000000  halt 00000000
 
00000008  proc     
; @SomeFunc
0000000c  
const.pri 00000000
00000014  zero
.pri
00000018  retn
 
0000001c  proc     
; @SomeFunc
00000020  
const.pri 00000001
00000028  zero
.pri
0000002c  retn
 
00000030  proc
00000034  push
.c 00000000
0000003c  call 0000001c    
; @SomeFunc
00000044  zero
.pri
00000048  retn 
But you cannot know which one is exactly will be called and in which file
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
That seems pretty clear and correct to me. It calls the one visible in the current scope (0000001c in the assembly).
And you want to say that this is what I wanted?
Reply
#8

And as I understood, it doesn't work as seemed to ******:
Reply
#9

you dont want to create global function but you want to call it from other include?
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
That's different to what you posted before, where you were just talking about direct calls. In that case, the function by "main" being called was correct. This code is something different, and would seem to be a bug.

Edit: But this method isn't overly useful, as it requires having two copies of the function - one public shadowing the static version.
Yes, you were right, sorry)


But I need timers. If I use timers the result is different
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)