editor.CharAt

19 views
Skip to first unread message

mozers

unread,
Oct 11, 2009, 5:21:12 AM10/11/09
to scite-i...@googlegroups.com
Hello Scite-interest!

I'm tormented by curiosity.
editor.CharAt returns an unsigned integer.
And though conversion is simple (editor.CharAt[x] % 256), in lua unsigned integers are not used.
It is a defect or unfathomable wisdom?
Neil, you will accept a patch?

--
mozers
<http://scite.net.ru>

Philippe Lhoste

unread,
Oct 11, 2009, 5:37:37 AM10/11/09
to scite-i...@googlegroups.com
On 11/10/2009 11:21, mozers wrote:
> editor.CharAt returns an unsigned integer.
> And though conversion is simple (editor.CharAt[x] % 256), in lua unsigned integers are not used.
> It is a defect or unfathomable wisdom?

That's probably because it is a blind, automatic interface to the

# Returns the character byte at the position.
get int GetCharAt=2007(position pos,)

Scintilla message, like most Lua bindings/functions.

Why do you do modulus? You can get more than one byte with Unicode
characters?

--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --

Neil Hodgson

unread,
Oct 11, 2009, 7:37:03 AM10/11/09
to scite-i...@googlegroups.com
mozers:

> I'm tormented by curiosity.
> editor.CharAt returns an unsigned integer.

Don't you mean signed? The C 'char' type is signed on most commonly
used platforms.

> And though conversion is simple (editor.CharAt[x] % 256), in lua unsigned integers are not used.
> It is a defect or unfathomable wisdom?
> Neil, you will accept a patch?

No. It would break existing code.

Neil

mozers

unread,
Oct 11, 2009, 4:05:54 PM10/11/09
to Philippe Lhoste
Sunday, October 11, 2009, 1:37:37 PM, Philippe wrote:

>> And though conversion is simple (editor.CharAt[x] % 256), in lua unsigned integers are not used.

> Why do you do modulus? You can get more than one byte with Unicode characters?

For characters with code from 0 to 127 editor.CharAt returns the correct values.
For characters with code from 128 to 256 editor.CharAt returns a negative value.
e.g.
char=} asciiCode=125 editor.CharAt return 125
char=~ asciiCode=126 editor.CharAt return 126
char= asciiCode=127 editor.CharAt return 127
char=Ђ asciiCode=128 editor.CharAt return -128
char=Ѓ asciiCode=129 editor.CharAt return -127
char=‚ asciiCode=130 editor.CharAt return -126

You can check it
print(editor.CharAt[editor.CurrentPos])

Transform to real ascii code variant 1:
if char_at < 0 then char_at = 256 + char_at end

Transform to real ascii code variant 2:
char_at = char_at % 256

--
mozers
<http://scite.net.ru>

mozers

unread,
Oct 11, 2009, 4:17:48 PM10/11/09
to Neil Hodgson
Sunday, October 11, 2009, 3:37:03 PM, Neil wrote:

>> editor.CharAt returns an unsigned integer.
> Don't you mean signed? The C 'char' type is signed on most commonly used platforms.

I try to explain a detail in the prev post to Philippe.

>> in lua unsigned integers are not used.
>> It is a defect or unfathomable wisdom?
>> Neil, you will accept a patch?
> No. It would break existing code.

If you do not think this is a mistake, then I - retreat.

--
mozers
<http://scite.net.ru>

Reply all
Reply to author
Forward
0 new messages