Jump to content
  • 0

How should I covert(decode) an bytes array to UTF-16LE text(or string)?


ctbear

Question

My script has a functional requirement: I search all actor(hero) names in the game, then I want to show the user a list of names,the user selects one of them.The script performs subsequent operations based on this selection.

My question is : How to convert byte arrays to text(string)?

In Java, His effect is similar to :

    String content = new String(bytes, "UTF-16LE");

How to do this in Lua Script?

I know "string.char" can decode UTF-8, but when the code is UTF-16LE, the text is garbled.(My game language is Chinese).I see some code that can be implemented, but that requires bit operation on Lua53.

Who can give me some suggest,or some tools and methods that can run on Lua52

Thanks.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

On 1/12/2022 at 10:45 PM, ctbear said:

I see some code that can be implemented, but that requires bit operation on Lua53.

Lua implementation in GG is source-compatible with Lua 5.3 (as mentioned in the documentation), meaning that bitwise operators are supported.

For example, the following code should work correctly when executed by GG

print("2 XOR 4 = " .. (2 ~ 4)) -- should print "2 XOR 4 = 6"
Link to comment
Share on other sites

10 hours ago, CmP said:

Lua implementation in GG is source-compatible with Lua 5.3 (as mentioned in the documentation), meaning that bitwise operators are supported.

For example, the following code should work correctly when executed by GG

print("2 XOR 4 = " .. (2 ~ 4)) -- should print "2 XOR 4 = 6"

thank you for your reply.

The code you said is useful. But doing so faces another problem. My Script is can't run after Luac(5.3) compilation.  

The error message is:

Invalid binary script header.
Unknown version. Expected '52' butfound '54'.
Unknown endianness. Expected '0'or'1' but found '25'.
Unknown size of int. Expected '4' butfound '147'.
Unknown size of size t. Expected '4'but found '13'.
Unknown size of instruction.
Expected '4' but found '10'.
Unknown size of Lua number.Expected '4' or '8' but found '26'.

 Now I use the code of bitwise operators solved the problems mentioned in the topic.  My code can only run as source code now. This makes people feel helpless.

 Anyway, thank you.

Link to comment
Share on other sites

21 hours ago, CmP said:

You can use the following script to compile your source code for GG

Script compiler (#9b2xri28)

Thank you for your kind help. 

I just registered my forum account recently. I encountered some problems in using.  I think they are easy to solve, just need to add some APIs.  Where and how should I submit my proposal?

Link to comment
Share on other sites

18 hours ago, ctbear said:

I just registered my forum account recently. I encountered some problems in using.  I think they are easy to solve, just need to add some APIs.  Where and how should I submit my proposal?

You can create a new topic with description of encountered problem and suggestion(s) for GG that you have in context of the problem. It's also not unlikely that the problem can have solutions that don't require any changes to GG, so first step should be to let others know about the problem.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.