Jump to content

Proposed new functions: llOrd, llChar and llHash


Mollymews
 Share

You are about to reply to a thread that has been inactive for 1120 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

read the summary SUG report over on Inara Pey's blog: https://modemworld.me/2021/04/06/2021-sug-meeting-week-14-summary/

Rider Linden:

I’m proposing the following three LSL functions llOrd, llChar and llHash.

llOrd() will return the ordinal of the first character in a string,

llChar() given an integer will return a single character string, and

llHash() is a non-cryptographic 32 bit hash. I was looking for a way to just
have an integer that had a reasonable change of being unique for an arbitrary string.
Use case I can see: Given an owner of two objects I want to select a chat channel
with a low probability of colliding with other agents in the area. This approach
wouldn’t be cryptographically secure, but would be convenient.

 

these will be good

while Rider Linden is contemplating doing this then I would like to see some other basic API functions added to the list as well. Like

llInt2Hex(integer value, integer leading_zeros)  // leading zeros being in [0..7].   // output 0x1, 0x00, 0x0012, 0x00010001, etc

llHex2Int(string value)

Hex (hexadecimal) functions from my pov, are useful when packing keys for transport

llInt2Bin(integer value, integer leading_zeros) // leading zeros being in [0..31].  // output 0b0, 0b0100, 0b0000000011111011, etc

llBin2Int(string value)

Bin (binary) functions for textual (visual) interrogation of bit flags

 

 

 

 

  • Like 1
Link to comment
Share on other sites

llOrd seems a bit superfluous, as it's not that hard to write as a user function i I'm understanding its intended use correctly:

string uInt2Ordinal(integer n)
{
    if(n==1)
        return "1st ";
    if(n==2)
        return "2nd ";
    if(n==3)
        return "3rd ";
    if(n<10)
        return (string)n+"th ";
    if(n<20)
        return (string)n+"th";
    string ret=(string)n;
    string last=llGetSubString(ret,-1,-1);
    if(last=="1")
        return ret+"st";
    if(last=="2")
        return ret+"nd";
    if(last=="3")
        return ret+"rd";
    return ret+"th";
}

Actually looking back at that there might be some problems numbers 111 thru 120 and such. could use a bit of improvement, but it's not a hard function to write.

Edited by Quistessa
Link to comment
Share on other sites

ord(" ") returns 32.  chr(32) returns " "

is a number of ways to code these up in LSL. Examples:

Pedro Oval's Ord and Chr here: http://wiki.secondlife.com/wiki/Chr

Combined Library Int2UTF here: http://wiki.secondlife.com/wiki/Combined_Library#Unicode_Integer_to_UTF8

neither of these example codes are complete

Linden API functions should be complete, able to handle extended 3 byte UTF-16 codes

  • Like 1
Link to comment
Share on other sites

Calling it llOrd seems a little weird. Why that term? I've never heard it being used in ASCII/Unicode context besides here. I would prefer llInteger2Char and llChar2Integer to be more descriptive and in line with other conversion functions.

4 hours ago, Quistessa said:

Actually looking back at that there might be some problems numbers 111 thru 120 and such. could use a bit of improvement, but it's not a hard function to write.

You inspired me:

string llOrdinal(integer n)
{
    string number = (string)n;
    string last = llGetSubString(number, -1, -1);
    n = n % 100;
    if (10 < n && n < 20) // Exception: Teens end in -th.
        return (number + "th");
    else if (last == "1")
        return (number + "st");
    else if (last == "2")
        return (number + "nd");
    else if (last == "3")
        return (number + "rd");
    else
        return (number + "th");
}

 

Regarding llHash -- while I don't dislike it, I don't really understand how it would be practically different from just choosing a random number (instead of a random string), or using already-existing data like the owner's key, the object's own key, group key, etc. It might at least benefit from being slightly clearer to read.

integer channel = (integer)((string)llGetKey());
integer channel = llHash(llGetObjectName());
integer channel = (integer)((string)llGetOwner());
integer channel = llHash(llGetUsername(llGetOwner()));

Edited by Wulfie Reanimator
  • Like 2
Link to comment
Share on other sites

llOrd and llChr follow the naming convention in languages like Python, Pascal and Basic. Ord means the ordinal (index) value of a character in the character set

i agree that the functions should be named more consistently with the LSL naming conventions. llChar2Integer() and llInteger2Char() work for me 

 

is not said but I think the idea with llHash is integer h = llHash("some string"). 

a lightweight version of producing a random looking integer from a known string

example might be: integer channel = llHash(mySecret + (string)llGetOwner())

and if we want a negative channel then: integer channel = -llHash(mySecret + (string)llGetOwner())

am assuming that llHash will never return 0 or DEBUG_CHANNEL

 

 

 

  • Thanks 1
Link to comment
Share on other sites

LSL uses, I think, UTF-16. That reflects when it was designed, back in the day when Java and Windows also used UTF-16. So a character's numeric value is between 0 and 65535. This includes most living languages and the common symbols, but does not include emoji.

Link to comment
Share on other sites

7 hours ago, animats said:

LSL uses, I think, UTF-16. That reflects when it was designed, back in the day when Java and Windows also used UTF-16. So a character's numeric value is between 0 and 65535. This includes most living languages and the common symbols, but does not include emoji.

i read a while ago that Linden were looking at enabling emojis in the viewer. If so then it should mean that UTF-16 4 byte chars (emojis, etc) would also be enabled in notecards, script editor, strings and PRIM_TEXT functions

would be good if this was to happen

also, in addition to Chr and Ord I wouldn't mind Unicode2Integer and Integer2Unicode

this way we could use the Unicode number for the character rather than the UTF-16 binary value. Like:

string catface = llInteger2Unicode(0x1F431);

integer unicode = llUnicode2Integer(catface);

0x1F431 is Unicode U+1F431

if we have to use the UTF-16 ordinal value then is 0xD83DDC31. Which means we have to think in UTF-16 rather than just thinking in Unicode

llOwnerSay(llInteger2Hex(unicode, 0) + " " + catface);

shows in chat as:  0x1F431 🐱

 

 

Edited by Mollymews
2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1120 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...