Make your Garry's Mod I/O asynchronous!
Garry's Mod still doesn't have file.AsyncWrite
function,.
Also file.AsyncRead
also doesn't work properly in menu state,
and Rubat doesn't want to elaborate in any way.
Also gm_async_write exists, but it doesn't provide binaries for client-side and doesn't have binaries for MacOS.
- Go to Releases page
- Download binary that matches your OS and Garry's Mod branch
- Select
gmsv_asyncio
binary if you need binary for your server orgmcl_asyncio
if you need for clientside - Choose
asyncio_win
,asyncio_linux
orasyncio_osx
respectively to your OS - If you installed chromium or x86-64 Garry's Mod beta, then choose binary that ends with
win64.dll
/linux64.dll
/osx64.dll
, otherwisewin32.dll
/linux.dll
/osx.dll
- Select
- Place freshly downloaded binary to
<Garry's Mod>/garrysmod/lua/bin/
folder - Enjoy your smooth ride!
-- Asynchronously writes given content to fileName in DATA folder
-- Have same limitations as https://wiki.facepunch.com/gmod/file.Write
-- Arguments:
-- fileName: path to a file
-- content: data to be written to a file
-- callback: function that will be called when async operation finishes
-- Arguments are:
-- * fileName: string path to a file
-- * gamePath: always "DATA"
-- * status: see https://wiki.facepunch.com/gmod/Enums/FSASYNC
-- Returns:
-- status: FSASYNC_OK if successful, otherwise FSASYNC_ERR_
-- see https://wiki.facepunch.com/gmod/Enums/FSASYNC
number asyncio.AsyncWrite( string fileName, string content, function callback )
-- Same as asyncio.AsyncWrite, but instead of rewriting content of the file, just appends content to file
number asyncio.AsyncAppend( string fileName, string content, function callback )
-- Asynchronously reads content from a specified file
-- Have same limitations as https://wiki.facepunch.com/gmod/file.Read
-- Arguments:
-- fileName: path to a file
-- gamePath: see https://wiki.facepunch.com/gmod/File_Search_Paths
-- callback: function that will be called when async operation finishes
-- Arguments are:
-- * fileName: string path to a file
-- * gamePath: gamePath specified earlier
-- * status: see https://wiki.facepunch.com/gmod/Enums/FSASYNC
-- * data: contents of a file
-- Returns:
-- status: FSASYNC_OK if successful, otherwise FSASYNC_ERR_
-- see https://wiki.facepunch.com/gmod/Enums/FSASYNC
number asyncio.AsyncRead( string fileName, string gamePath, function callback )
-- Good luck with coding!
local data = "Hello World!"
local ok = asyncio.AsyncWrite("example.txt", data, function(fileName, gamePath, status)
local ok = asyncio.AsyncRead(filename, gamePath, function(fileName, gamePath, status, fileContent)
print(status, status == FSASYNC_OK) -- 0 true
print(fileContent) -- Hello World!
print(data == fileContent) -- true
end)
end)
print("Write successful:", ok == FSASYNC_OK) -- Write successful: true
Feel free to create issues and pull request ❤️