Lua-Iconv
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Lua-Iconv

Started by PPK, 09 April, 2012, 16:45:11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PPK

Version for PtokaX 0.4.2.0 build 376 and higher.

Homepage: http://luaforge.net/projects/lua-iconv/

Binary: http://www.ptokax.org/files/Libs-376/Lua-Iconv-6.7z
Binary x64: http://www.ptokax.org/files/Libs-376/Lua-Iconv-6-x64.7z
Source: http://www.ptokax.org/files/Libs-376/Lua-Iconv-6-src.7z

Initializing:
require "iconv"


This will register global iconv, more is in readme 8)

This lib is compatible with PXLua 5.1.5 and PXLua 5.2.0 ;)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PPK

#1
Example script.
When user country is Russia, Ukraine or Belarus then any his text sent to chat is tested for utf-8 encoding. When text is not in utf-8 then is converted from win-1251 encoding (default on windows) to utf-8  :P

local iconv = require "iconv"

utf8test = nil
cp1251toutf8 = nil

function OnStartup()
    utf8test = iconv.new("utf8", "utf8") -- setup utf-8 encoding checker
    cp1251toutf8 = iconv.new("utf8", "cp1251") -- setup win-1251 to utf-8 converter
end

function ChatArrival(curUser, sData)
    CountryCode = Core.GetUserValue(curUser, 26) -- get user country code

    if CountryCode == nil then -- no country code found, no conversion
        return false
    end

    if CountryCode ~= "RU" and CountryCode ~= "UA" and CountryCode ~= "BY"then -- user is not from Russia, Ukraine or Belarus. no conversion
        return false
    end

   if string.find(SetMan.GetString(29), string.sub(sData, 4+string.len(curUser.sNick), 4+string.len(curUser.sNick)), 1, true) then -- test for hub commands, no conversion
      return false
   end

    nstr, err = utf8test:iconv(sData) -- utf-8 encoding test
    if err ~= nil then
        nstr, err = cp1251toutf8:iconv(sData) -- conversion from win-1251 to utf-8
        if err == nil then
            Core.SendToAll(nstr) -- send converted chat
            UDPDbg.Send(sData) -- send original to udp debug
            return true -- don't process data by hub
        end
    end
end
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PPK

#2
Lua-iconv 7 for PtokaX 0.4.2.0 build 376 and higher.

Homepage: http://luaforge.net/projects/lua-iconv/

Binary: http://www.ptokax.org/files/Libs-376/Lua-Iconv-7.7z
Binary x64: http://www.ptokax.org/files/Libs-376/Lua-Iconv-7-x64.7z
Source: http://www.ptokax.org/files/Libs-376/Lua-Iconv-7-src.7z

Initializing:
local iconv = require "iconv"


This will create iconv metatable (version 7 no more create global iconv), more is in readme 8)

This lib is compatible with PXLua 5.1.5, 5.2.0 and 5.2.1 ;)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

SMF spam blocked by CleanTalk