User:Necktrox: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
| m (Added installation notes and link to socket module page) | m (Added personal code snippets) | ||
| Line 63: | Line 63: | ||
| *[https://github.com/Necktrox GitHub Profile] | *[https://github.com/Necktrox GitHub Profile] | ||
| *[https://forum.mtasa.com/memberlist.php?mode=viewprofile&u=74045 Forum Profile] | *[https://forum.mtasa.com/memberlist.php?mode=viewprofile&u=74045 Forum Profile] | ||
| == Code Snippets == | |||
| === string.address === | |||
| <syntaxhighlight lang="lua">function string:address() | |||
|     return self:match("0+(.+)") | |||
| end</syntaxhighlight> | |||
| <pre> | |||
| local e = createElement("example") | |||
| outputDebugString(tostring(e):address()) | |||
| </pre> | |||
| === utf8.split === | |||
| <syntaxhighlight lang="lua">function utf8:split(separator) | |||
|     assert(type(separator) == "string", "expected string at argument 1, got ".. type(separator)) | |||
|     local rows = {} | |||
|     local position, startpoint = false, 1 | |||
|     local sepLength = utf8.len(separator) | |||
|     repeat | |||
|         position = self:find(separator, startpoint, true) | |||
|         local part = self:sub(startpoint, position and (position - 1) or nil) | |||
|         startpoint = position and (position + sepLength) or 0 | |||
|         if part:len() > 1 then | |||
|             rows[#rows + 1] = part | |||
|         end | |||
|     until not position | |||
|     return rows | |||
| end | |||
| </syntaxhighlight> | |||
| <pre> | |||
| for index, column in ipairs(utf8.split("A--B--C", "--")) do | |||
|     -- ... | |||
| end | |||
| </pre> | |||
Revision as of 20:31, 19 April 2016
Download and install socket module
Download
These binaries are freshly baked for the commit a23bf532477f03f70be6432b3b4b4d51f2949a11.
- Windows x32 ml_sockets.dll
- MD5: 1C5CF970F6D02CE8A8C92024DF195ED6
- SHA1: 3195ED77145EC09A53582105F9EFD5ABD429C28B
 
- Windows x64 ml_sockets.dll
- MD5: BE9F4AE98162839487783E87E212D25F
- SHA1: E713B004C729651E40B51E1A46C069C462933B68
 
- Linux x32 ml_sockets.so
- MD5: 3585F06C00EE344FA480C6E21C21BDBE
- SHA1: F92A420F614603C83272AA4FC0CC595FAAE6ADA3
 
- Linux x64 ml_sockets.so
- MD5: DE1A161743F5E079F8A838C3E2027223
- SHA1: 59CE19EC63FEB1EA0DE41C5FEEF1C289AC77BCF8
 
Installation
You can read more about the sockets module here: Modules/Sockets
Windows
x32: server/mods/deathmatch/modules/ml_sockets.dll x64: server/x64/modules/ml_sockets.dll
Linux
x32: server/mods/deathmatch/modules/ml_sockets.so x64: server/x64/modules/ml_sockets.so
Compile socket module on Ubuntu 15.10 (or on any Debian distro?)
Install the necessary build tools, headers and libraries
$ sudo apt-get install git build-essential automake libtool lib32z1-dev g++-multilib
Clone the multitheftauto/multitheftauto-modules repository to your disk
$ git clone https://github.com/multitheftauto/multitheftauto-modules.git mta-modules
Change your directory to mta-modules/sockets
$ cd mta-modules/sockets
Make the shell scripts executable, so they can be ran from terminal
$ chmod a+x build-32.sh $ chmod a+x build-64.sh
Build the x32/x64 libraries
$ ./build-32.sh $ ./build-64.sh
Contact
Code Snippets
string.address
function string:address()
    return self:match("0+(.+)")
end
local e = createElement("example")
outputDebugString(tostring(e):address())
utf8.split
function utf8:split(separator)
    assert(type(separator) == "string", "expected string at argument 1, got ".. type(separator))
    local rows = {}
    local position, startpoint = false, 1
    local sepLength = utf8.len(separator)
    repeat
        position = self:find(separator, startpoint, true)
        local part = self:sub(startpoint, position and (position - 1) or nil)
        startpoint = position and (position + sepLength) or 0
        if part:len() > 1 then
            rows[#rows + 1] = part
        end
    until not position
    return rows
end
for index, column in ipairs(utf8.split("A--B--C", "--")) do
    -- ...
end