Howto Re-define functions

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by pbdep.


Hi All,

How do I redefine functions from PB?

PP = print
PP = *print

etc...

I want to achief this ->

OpenConsole()
PP("Hello")
Delay(5000)

Any tips?

Thanks, Norman.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Just make a procedure to do it. In fact, using procedures this way is
a fantastic method to creating your own custom PureBasic commands. :)

Code: Select all

Procedure PP(text$)
  PrintN(text$)
EndProcedure
;
OpenConsole()
PP("hello")
Delay(5000)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by pbdep.
Originally posted by PB

Just make a procedure to do it. In fact, using procedures this way is
a fantastic method to creating your own custom PureBasic commands. :)

Code: Select all

Procedure PP(text$)
  PrintN(text$)
EndProcedure
;
OpenConsole()
PP("hello")
Delay(5000)

Hahahah... Noooooo your not getting away with this one :wink:

I need hardcoded assigment :wink: Give me another pointer :wink:
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Hahahah... Noooooo your not getting away with this one :wink:
> I need hardcoded assigment :wink: Give me another pointer :wink:

:) Sorry, but I don't understand... wasn't that what you wanted?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by pbdep.
Originally posted by PB

> Hahahah... Noooooo your not getting away with this one :wink:
> I need hardcoded assigment :wink: Give me another pointer :wink:

:) Sorry, but I don't understand... wasn't that what you wanted?
Hi PB,

Well basicly using the Procedure option is assigning an
already declared function inside another procedure,
so thats double-up :)

Im intrested in how Dynamic PureBasic is.

Basicly what i found outright now is that al the functions
are static. This mean there is no possibility to redefine
functions. Which does make PB more static than I hoped.

I.e. if you want to create flexible functions without
rewriting the functions you can use the build-in functions.

So i would assume that the function print() or Val() can be renamed
by addressing the NEW-Name towards the internal Pointer of the function inside the Compiler or Library. That would make ->

; the following is not possible because PB does not allow
; *PP unasigned as a function, array...
*PP = *print()

; The follwing could return the string "print" or "pb_print"
; from the compiler, but it does not...
PP = *print
PeekS(*PP)

; This also does not work
*PP = *print ; PP points to the Addresslocation of print
PeekS(*PP)



So finaly what do i want to achive is to get all the the contstant
functions from the compiler.

Secondly I want to be able to write a Dialect in PureBasic.

And at last, I want to have an Insight on PB :wink:

Regards,
Norman.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Originally posted by pbdep

Basicly what i found outright now is that al the functions
are static. This mean there is no possibility to redefine
functions. Which does make PB more static than I hoped.
You can have dynamic functions if you use procedures (I know this is not what you want, but it might help). However, you will manually need to manage the calling of these functions, you cannot simply have a line in your code such as

myfunction()

And expect to be able to change what code that code calls. Because the compiler generates some assembly that goes along the lines of

JSR p_myfunction

Where p_myfunction is a label in the assembly language or library files. There is also no naming information in the executable, so if you wanted to hack around with stuff like that you would need to do it before the compiler executed, or between the compiler and assembler.

You could probably get the address of a PB command by using some inline assembly like this (I don't know x86 so this probably is not correct):

Code: Select all

function.l ; Declare variable before using it in inline asmLEA eax, [_PB_MessageRequester@12] ; what's the deal with the @12 anyway? The number of bytes on the stack?
MOV dword [v_function], eax
I do not know how you could force the PB command to be included in the executable though, without writing a call to it in your code somewhere, or fiddling with the output ASM before re-assembling it.

But you could manually manage a table of pointers to commands, the pointers you could replace with your own functions. You could then use the CallFunction command (I think) to call the functions.


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.40)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Code: Select all

Procedure MyFunction(Argument1, Argument2, Argument3)
  ;
  ; First Procedure
  ;
EndProcedure

Procedure AnotherFunction(Argument1, Argument2, Argument3)
  ;
  ; Second Procedure
  ;
EndProcedure


If whatever = something              ; dinamically select Procedure
  Function.l = @MyFunction()
Else
  Function.l = @AnotherFunction()
Endif

; call selected Procedure (no ASM needed.)

CallFunctionFast(Function.l, Argument1, Argument2, Argument3)

---

Maye this helps...

Timo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Timo's solution is the prefered one. Who said than PB is static ? :).

Fred - AlphaSND
Post Reply