NumToChar in LCB?

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
trevix
Posts: 958
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

NumToChar in LCB?

Post by trevix » Fri Mar 29, 2019 5:30 pm

Trying to work on images...
I understand that "the cod of tChar" give me the numeric code of the character.
What is the reverse of it? (on LCS would be NumToChar()

Trevix
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: NumToChar in LCB?

Post by bn » Fri Mar 29, 2019 6:10 pm

Does this help?

ByteWithCode

Type operator

Syntax
the byte with code Value

Summary
Create a 1-byte data value from a number

Edition
Community

Associations
com.livecode.byte

Parameters
Name: Value
Description:
The value for the new data value


Description
Returns a byte of binary data, created using the given value. The
Value must be between 0 and 255 (inclusive).

Kind regards
Bernd

trevix
Posts: 958
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: NumToChar in LCB?

Post by trevix » Sat Mar 30, 2019 9:47 pm

Mmmmh...
this compile OK but returns me and error at line 12, given AdditionTest("abcd"), while should return "abc":

Code: Select all

library community.livecode.trevix.testmathuno
metadata version is "1.0.0"
metadata author is "trevix"
metadata title is "TestMathUno Library"
public handler AdditionTest(in pText as String) returns String
   variable tNumText as String
   variable tResult as String
   variable tNum as Number
   variable tCounter as Number
   repeat with tCounter from 1 up to 3
      put the code of (char tCounter of pText) into tNum --IS A Number 0-255
      put the byte with code tNum into tNumText
      put tNumText  after tResult
   end repeat
   log[tResult]
   return tResult
end handler
end library
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

trevix
Posts: 958
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: NumToChar in LCB?

Post by trevix » Sat Mar 30, 2019 9:56 pm

Also, since you seem to be knowledgable, what speed gain can I expect form LCB?
In LCS, a inverse conversion of an image area (make it negative) takes me roughly 7 seconds.
What do you think could be the time for the same routine in LCB?
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: NumToChar in LCB?

Post by bn » Sun Mar 31, 2019 12:49 pm

Hi Trevix,

this works for me

Code: Select all

library community.livecode.trevix.testmathuno
metadata version is "1.0.0"
metadata author is "trevix"
metadata title is "TestMathUno Library"

public handler AdditionTest(in pText as String) returns String
   variable tNumData as Data
   variable tResult as String
   variable tNum as Number
   variable tCounter as Number
   variable tDataToNum as Number
   repeat with tCounter from 1 up to 3
      put the code of (char tCounter of pText) into tNum --IS A Number 0-255
      put tNum formatted as string & newline  after tResult
      put the byte with code tNum into tNumData -- tNumData is binary
      put the code of tNumData into tDataToNum -- convert to Number
      put tDataToNum formatted as string & newline after tResult
   end repeat
   --log[tResult]
   return tResult
end handler
end library
You were trying to put binary data into a string-type variable. That did not work.
put the byte with code tNum into tNumText
As far as speed is concerned it all depends. But don't expect LCB to be considerably faster than LCS.

Look at the extensive and excellent examples from Hermann regarding LCB and imageData. Good stuff to learn from.

Kind regards
Bernd

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: NumToChar in LCB?

Post by [-hh] » Sun Mar 31, 2019 2:32 pm

trevix wrote:What speed gain can I expect from LCB?
In LCS, a inverse conversion of an image area (make it negative) takes me roughly 7 seconds.
What do you think could be the time for the same routine in LCB?
The best way to know this is to walk through the bytes of imageData (= the pixels in LCB), without doing anything with them: It is muuuuch slower. Even using Java via FFI is not faster than LCS.

But LCB is very fast with canvas methods you don't have available in LCS, like transforms (I use these with widget imagewidget).

By far the fastest (directly available) way to handle raw imageData is JavaScript via a browser widget (because JS uses your GPU).
shiftLock happens

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: NumToChar in LCB?

Post by bwmilby » Sun Mar 31, 2019 6:47 pm

A while back I did some speed comparisons for finding primes and LCS was much faster than LCB. The speed gains in LCB will currently come when it is leveraging compiled code (like the transforms that were mentioned).
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

Post Reply

Return to “LiveCode Builder”