Dateien

> > CS2D > Lua Scripts > [EngiN33R] UTF-8 Wrapper Library
DateiübersichtCS2D-ÜbersichtLua Scripts-Übersicht

Englisch [EngiN33R] UTF-8 Wrapper Library >

22 Kommentare2 kb, 582 Downloads

alt [EngiN33R] UTF-8 Wrapper Library

EngiN33R
Moderator Off Offline

This is an official tiny wrapper library that helps you forget about UTF-8 conversions in the new CS2D versions. The library replaces the msg, msg2, print and parse functions to always use UTF-8. The library has a safeguard against being loaded multiple times, so it should be safe to include in your mod or script without additional considerations.

When using this library for UTF-8 strings in your code, make sure to save your .lua files as UTF-8 without BOM!

In case you need raw access to UTF-8 helper functions, the library provides the following:

• utf8.codepoint(char) [number] - get the Unicode codepoint of the given character.
• utf8.encode(char) [string] - get the UTF-8 representation of a single character.
• utf8.convert(str) [string] - get a CS2D-ready UTF-8 representation of the given string.

After loading this library, UTF-8 conversion works as follows:

• utf8.convert("欢迎来到CS2D") gives
UTF-8:xE6xACxA2xE8xBFx8ExE6x9DxA5xE5x88xB0x43x53x32x44

• utf8.convert("Привет CS2D!") gives
UTF-8:xD0x9FxD1x80xD0xB8xD0xB2xD0xB5xD1x82x20x43x53x32x44x21
1× editiert, zuletzt 05.12.17 21:17:54
Zugelassen von SQ

Download Download

2 kb, 582 Downloads

Kommentare

22 Kommentare
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

Logge dich ein!

Du musst dich einloggen, um selber Kommentare verfassen zu können!Einloggen

alt

TobyInChina
User Off Offline

Hello
And I find another Bug,
If you want say something by using addhook('say','_say')
it's like dont work.
IMG:https://s2.ax1x.com/2019/04/01/AySwxU.png

IMG:https://s2.ax1x.com/2019/04/01/AySaGV.png

IMG:https://s2.ax1x.com/2019/04/01/AySd2T.png
Ich mag es!
1× editiert, zuletzt 01.04.19 13:30:04

alt

Vehk
User Off Offline

user Gaios Here's a patch for that.

1
2
3
4
5
6
7
8
9
10
11
12
--- utf8-original.lua
+++ utf8.lua
@@ -26,6 +26,9 @@
                -- UTF8-1
                return 1

+       elseif c == 0xA9 then           -- ASCII Copyright/CS2D color code
+               return 1
+
        elseif c >= 194 and c <= 223 then
                -- UTF8-2
                local c2 = string.byte(s, i + 1)

To anyone using this script I'd recommend using an alias for utf8.convert

1
2
3
4
U = utf8.convert

-- simplifies usage
U"欢迎来到CS2D"
Ich mag es!
1× editiert, zuletzt 29.12.18 02:06:26

alt

Gaios
Reviewer Off Offline

You may add exception for
\169
Ich mag es!

alt

Gaios
Reviewer Off Offline

@user TobyInChina: Autorun folder is executed after all scripts. You do it wrong.
Ich mag es!

alt

TobyInChina
User Off Offline

@user SQ:
I've run UTF in the AutoRun folder
Ich mag es!

alt

Vehk
User Off Offline

Good script! Fixes another design flaw in the cs2d Lua API.

Why are utf8len and utf8sub private?

Note to scripters
If you use code similar to this
1
2
3
local colorcode=string.char(0xA9)
...
msg(colorcode.."255000000hello")
Using this script will break it. You can add a fix by doing this
1
2
3
4
local colorcode=string.char(0xA9)
if utf8 then
	colorcode=string.char(0xC2)..string.char(0xA9)
end

This will cause problems with existing scripts, especially if this file becomes included by default.

Any script using code similar to the above snippet or using the © symbol and saving as ASCII will be broken.

One fix is for scripters to always use code like the second snippet above. Another would be for this library to return invalid utf-8 as byte(s) or to provide new functions instead of overwriting existing ones.

This should be considered before possibly including this with CS2D and for anyone wanting to use this script on their servers (you might need to make changes to existing scripts).
Ich mag es!
4× editiert, zuletzt 10.12.17 04:59:16

alt

SQ
Moderator Off Offline

@user TobyInChina:
Zitat
When using this library for UTF-8 strings in your code, make sure to save your .lua files as UTF-8 without BOM!

Also you have loaded UTF after printing your line.
Ich mag es!

alt

TobyInChina
User Off Offline

I use you lua.but It maybe dont work!
Help!!!
IMG:https://ww4.sinaimg.cn/large/0060lm7Tly1fm96hg3pj2j307202nglr.jpg

IMG:https://ww2.sinaimg.cn/large/0060lm7Tly1fm96hg1jc4j30ei021mx2.jpg

IMG:https://ww1.sinaimg.cn/large/0060lm7Tly1fm96hg1hyuj308m02xt9f.jpg
Ich mag es!

alt

Nekomata
User Off Offline

Thank God.
Ich mag es!

alt colored text working

2Gen
User Off Offline

@user SQ:
Yea, it working, thanks. I just made a mistake in my code and wrote
1
parse("sv_msg2 "..id.."©255000000 Привет CS2D@C")
instead
1
parse("sv_msg2 "..id.." ©255000000 Привет CS2D@C")

well, now everything is alright
Ich mag es!

alt

Devil-Thanh
GAME BANNED Off Offline

Great work here
Ich mag es!

alt

Gaios
Reviewer Off Offline

@user SQ: I didn't even download it
Ich mag es!

alt

SQ
Moderator Off Offline

@user 2Gen: @user Gaios:
There is nothing you need to additionally do. It's a wrapper.
1
msg("©255100100Привет CS2D!!")

Gaiyos code won't even work because it's double converting.
Ich mag es!

alt otlichnaya rabota

2Gen
User Off Offline

Oh, this is exactly what I was looking for, thanks. But can you explain how to get the colored text using this script, since I always have it yellow.
Ich mag es!

alt

Gaios
Reviewer Off Offline

Thank you
Ich mag es!

alt

VADemon
User Off Offline

Must be included by default...
but then nobody uses wrapper.lua because of unclear up-to-date state.
Ich mag es!

alt

Yates
Reviewer Off Offline

                                                                             
Ich mag es!

alt

EngiN33R
Moderator Off Offline

@user Infinite Rain: The intricacies of editing
package.path
to be able to painlessly include files, as well as the question of the library being potentially redistributed with mods and required multiple times, means that an old-fashioned safeguard is easier to do. If you want to use the require toolchain, just use
require "utf8"
, provided your
package.path
is modified accordingly.
Zum Anfang Vorherige 1 2 Nächste Zum Anfang