Author Topic: Override print?  (Read 600 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Hero Member
  • *****
  • Posts: 882
Override print?
« on: June 25, 2019, 06:09:12 AM »
Hi Charles,

using a print statement without argument gives an error message (Linker found unidentified names). Using print "" or print chr(13,10) will solve the problem. I wonder if it's legitimate to use an overriding function?

Code: [Select]
'uses console

sub print
  'print ""
  print chr(13,10)
end sub 


'print
print "Hello"
print
print "Goodbye"

'waitkey

I am not sure if side effects are expected if I try to override print in this way?

Roland

jcfuller

  • Full Member
  • ***
  • Posts: 181
Re: Override print?
« Reply #1 on: June 25, 2019, 07:06:51 AM »
Roland,
  Why would you want to do that with a message box?
With console just use printl
Code: [Select]

use console
printl "Hello"
printl
printl "Goodbye"

waitkey

James

Arnold

  • Hero Member
  • *****
  • Posts: 882
Re: Override print?
« Reply #2 on: June 25, 2019, 09:48:10 AM »
Hi James,

this is true. Therefore in my example I commented out: uses console. Then printl will give an error in any case. But perhaps my question is only academic. Using print "" or print chr(13,10) will always work.

Roland

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4222
    • Oxygen Basic
Re: Override print?
« Reply #3 on: June 25, 2019, 12:31:21 PM »
Hi Roland,

You can create any number of override functions providing they do not contain optional or default params.

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4222
    • Oxygen Basic
Re: Override print?
« Reply #4 on: September 16, 2019, 05:59:16 AM »
Now there is a way of redefining or extending a function without causing recursion.

By using the term prior, you can access the previous definition:

Code: [Select]
sub print(string s)
  prior print(">>: "+s)
end sub

print "Hello" '>>: Hello

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 521
    • PluriBASIC
Re: Override print?
« Reply #5 on: September 19, 2019, 10:07:33 AM »
Hello Charles, Great feature, i have an inmedite use for it.

 Does prior only work in a module of the same name? What happens if you use if outside of a module of the same name? is it safe?

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4222
    • Oxygen Basic
Re: Override print?
« Reply #6 on: September 19, 2019, 11:05:28 AM »
Hi Brian,

prior should work anywhere. However there is a glitch specifically relating to prior print which will be fixed in 0.2.8

This is how it should work:
Code: [Select]
sub print( string s)
 prior print(">>: "+s)
end sub

print "Hello" '>>: Hello
prior print "Hello" 'Hello

and this is the workaround:

Code: [Select]
int a 'dummy return variable

sub print( string s)
  a=prior print(">>: "+s)
end sub

print "Hello" '>>: Hello
a=prior print "Hello" 'Hello

Arnold

  • Hero Member
  • *****
  • Posts: 882
Re: Override print?
« Reply #7 on: September 19, 2019, 03:53:59 PM »
Hi Charles,

there is a small problem in version 0.2.7 with examples\Dlls\TestHello64.o2bas. When I run the exe file then HelloW is not printed, no matter what I try. I also tried this code:

Code: [Select]
  $filename "TestHello64_w.exe"
  uses RTL64

  function HelloA(string s) as string
    return "HelloA "+s
  end function

  function HelloW(wstring s) as wstring
    return "HelloW "+s
  end function

  print HelloA "World!"
  print HelloW "World!"

and I get the same result.

I would also like to point to Asm32\AddrLabel.o2bas. I must use: print (hex [ecx]) to get the expected result. (But AddrStringLit.o2bas works as expected).

Roland

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4222
    • Oxygen Basic
Re: Override print?
« Reply #8 on: September 20, 2019, 05:01:37 AM »
Thanks, Roland.

I've fixed the problem in RTL64.inc.

Unfortunately print can no longer be used to display register content directly, due to additional tweaks which overwrite various registers. However you can use mbox instead. It is lower level, and takes a string expression or string pointer.
Code: [Select]
addr ecx,xx
mbox hex [ecx]
end

.xx
db 1 2 3 4



latest version 0.2.8 just posted :)