Code: Select all
Read.s s
Debug s
; vs:
Debug ReadS
Debug ReadS()
Thanks!
Code: Select all
Read.s s
Debug s
; vs:
Debug ReadS
Code: Select all
Debug PeekS(?MyString)
DataSection
MyString:
Data.s "Hello"
EndDataSection
And how do you read numerous strings of unknown length, using PeekS?skywalk wrote:Ummm, we already have Peek() functions...![]()
Code: Select all
Debug PeekS(?MyString) DataSection MyString: Data.s "Hello" EndDataSection
Code: Select all
Procedure.s ReadS()
Protected string.s
Read.s string
ProcedureReturn string
EndProcedure
Restore StringStuff
Debug ReadS()
Debug ReadS()
Debug ReadS()
Debug ReadS()
Debug ReadS()
DataSection
StringStuff:
Data.s "Hello"
Data.s "Wolrd"
Data.s "How"
Data.s "Are"
Data.s "You?"
EndDataSection
Code: Select all
Macro NEXTDATA_Str(DataLabel)
*DataLabel + (MemoryStringLength(*DataLabel) + 1) * SizeOf(Character)
EndMacro
Define.i *p = ?MyString
Define.s s$
Repeat
s$ = PeekS(*p): NEXTDATA_Str(p)
Debug s$
Until s$ = "Q"
DataSection
MyString:
Data.s "Hello"
Data.s "Hello2", "Hello33"
Data.s "Hello444"
Data.s "Q"
EndDataSection
No, read.s is not a workaround, but is not a "function" that allows assigning a var its return value. But is IS cumbersome coding because it requires a "temporary" variable.skywalk wrote:Using the existing commands: Read.s and PeekS() are NOT workarounds or slow.
I gather that you are requesting a function that modifies the data pointer and returns a type of data read from the data pointer. I agree that that would be a useful thing.Tenaja wrote:No, read.s is not a workaround, but is not a "function" that allows assigning a var its return value. But is IS cumbersome coding because it requires a "temporary" variable.
Code: Select all
;here are two stand-in macros representing the functionality desired
Macro IPeekB(ptr)
PeekB(ptr): ptr + SizeOf(Byte)
EndMacro
;a version that handles the specification of length or flags is desired but is not shown here
Macro IPeekS(ptr)
PeekS(ptr): ptr + (MemoryStringLength(ptr) + 1) * SizeOf(Character)
EndMacro
DataSection
stuff:
Data.b 5
Data.s "first", "second", "third", "fourth", "fifth"
EndDataSection
*dataPtr = ?stuff
count = IPeekB(*dataPtr) ;pointer will be incremented by 1 for the size of a byte
For i = 1 To count
Debug IPeekS(*dataPtr) ;pointer will be incremented by the memory length of the string + Null
Next
This does NOT work as a function parameter for calling another function. Like I said, it requires a temporary variable.Demivec wrote:Contrary to your comment you currently can use 'Read' to place data directly in a variable without the need for a temporary variable, you just can use it in an any kind of expression or as a literal (without being placed in a variable). You would just use: Read.s MyString.
Conversely, if Read were implemented with full access, why would one need Peek/Poke??? Peek is more of an antiquated command that was implemented due to lack of pointers etc. No other language uses it, other than languages trying to workaround their lack of string and or data handling.Demivec wrote:If implemented it would also would beg the question, "Neglecting the origins of BASIC, why would you need 'Read' for anything anymore?"
I agree, and I corrected the typo in the previous message.Tenaja wrote:This does NOT work as a function parameter for calling another function. Like I said, it requires a temporary variable.Demivec wrote:Contrary to your comment you currently can use 'Read' to place data directly in a variable without the need for a temporary variable, you just can use it in an any kind of expression or as a literal (without being placed in a variable). You would just use: Read.s MyString.