-
Posts
14 -
Joined
-
Last visited
Details
-
Gang
Microvolnovka
-
Location
Russia
-
Occupation
Developer
-
Interests
Programming
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
uriid1's Achievements

Square (6/54)
2
Reputation
-
Well, I understand where I went wrong and why it's not working as I expected. But now I'd like to learn a bit more about how asynchronous functions are executed in MTA and in which thread. Is this thread similar to an event loop, like in Node.js, or does it use a different model? And can you influence this thread, for example, by adding your own asynchronous functions? On an interesting note, there's a project called luvit that also uses an asynchronous model, but they've figured out how to wrap asynchronous functions in coroutines. For example, you can see this in action here: https://github.com/luvit/lit/blob/master/deps/coro-net.lua. This is something I would also like to achieve in MTA. However, for now, it seems impossible.
-
Works if written like this: local function callback(responseData, errorCode) coroutine.yield(responseData, errorCode) end But MTA doesn't support this notation. I don't understand why this works: local function test() return 'Hello' end local testCo = coroutine.create(test) local result, data = coroutine.resume(testCo) outputDebugString('Data: '..tostring(data)) -- 'Data: Hello' And this doesn't work... local function testFetchAndOutput() local responseData, errorCode = fetchRemoteAsync(url, opts) return responseData, errorCode end local testCo = coroutine.create(testFetchAndOutput) local result, responseData, errorCode = coroutine.resume(testCo) outputDebugString('responseData: '..tostring(responseData)) -- nil I find this very strange.
-
I tried to implement this logic in plain Lua(5.1), but I didn't get any results. local function fetchRemote(url, opts, callback) callback("data: Yes, it's data", 200) end local function fetchRemoteAsync(url, opts) local co = coroutine.running() local function callback(responseData, errorCode) -- print(responseData) -- data: Yes, it's data coroutine.resume(co, responseData, errorCode) end fetchRemote(url, opts, callback) return coroutine.yield() end local function testFetchAndOutput() local responseData, errorCode = fetchRemoteAsync('http://site.com/foo/bar', { method = 'POST' }) print('responseData:', responseData) -- nil return responseData, errorCode end local testCo = coroutine.create(testFetchAndOutput) print(coroutine.status(testCo)) -- suspended coroutine.resume(testCo) print(coroutine.status(testCo)) -- suspended coroutine.resume(testCo) print(coroutine.status(testCo)) -- dead
-
Thank you for your response. Unfortunately, the example you provided will only work synchronously for the testFetchAndOutput function. The behavior I would like to achieve: -- Create a coroutine that will execute testFetchAndOutput local co = coroutine.create( function() local responseData, errorCode = fetchRemoteAsync(url, opts) return responseData, errorCode end ) -- Execute the coroutine local coRes, responseData, errorCode = coroutine.resume(co) outputDebugString('coRes: '..tostring(coRes)) -- true outputDebugString('responseData: '..tostring(responseData)) -- '{data: foo}' outputDebugString('errorCode: '..tostring(errorCode)) -- nil I want to avoid callbacks. Your example provides some insight into working with coroutines in MTA. Is there somewhere I can read more about this? I haven't been able to find any information on this. Thanks again.
-
I want to achieve synchronous behavior for the fetchRemote function. However, instead, I'm getting an infinite loop with the while statement. Could it be because MTA uses different addressing? local expectedResponse = {} function fetchRemoteCallback(responseData) table.insert(expectedResponse, responseData) end function fetchRemoteAsync(url, opts) expectedResponse = {} fetchRemote(url, opts, fetchRemoteCallback) end function waitForResponse() while not expectedResponse[1] do -- Wait... end end fetchRemoteAsync('http://site.com/foo/bar', { method = 'POST', headers = ... }) waitForResponse() if expectedResponse[1] then return expectedResponse[1] end
-
Big Update! The library is literally rewritten. Added support for CallbackButton, Button. Added send ImageData to send image data. Also: editMessageText answerCallbackQuery keyboardInit inlineKeyboardInit inlineButton inlineKeyboardMarkup replyKeyboardMarkup The example from GitHub has been updated. Link: https://github.com/uriid1/MTA-Telegram-bot Demonstration:
-
wine-6.15 works good I am grateful to you for your detailed answer and thank you for helping
-
I know how the function works, of course, in the end I rewrote the resource for its use. But I still find it inconvenient :F (terrible fonts are due to the launch of MTA in wine)
-
Since the dxCreateRenderTarget draws in the upper-left corner, this creates problems for me. If the function had the form dxCreateRenderTarget (x, y, w, h, [ ... ]), I wouldn't ask this question :_)
-
Hello. I'm doing something like a GUI, and I need to draw text inside a square or rectangle. I tried to implement this using dxCreateRenderTarget, but it allows you to create a render target element not in the specified coordinates, as I reported in the issue on github. Maybe there are ideas on how it could be implemented yet? Maybe there is some shader...
-
Well, I mean, if the server script will tell the client that some file has changed (via triggerServerEvent/triggerClientEvent). Just checking if the size of this file has changed. In this case, Clint could download it again. And if we talk about scripts,it was possible to implement LiveCode/HotReload using loadstring. But this is of course stupid
-
Thanks. Interestingly, it turns out that you can implement something like love code by changing the resource code on the server, it would change on the client.
-
Hello. The FileOpen function works for me without problems in the server script. But it does not work on the client side. meta.xml <meta> <!-- Information --> <info name="nine" author="uriid1" version="0" type="script" /> <!-- Scripts --> <script src="main.lua" type="client" /> <!-- MTA Version--> <min_mta_version server="1.5.8" /> </meta> main.lua local hFile = fileOpen("test.txt", true) -- attempt to open the file (read only) if hFile then -- check if it was successfully opened local buffer while not fileIsEOF(hFile) do -- as long as we're not at the end of the file... buffer = fileRead(hFile, 500) -- ... read the next 500 bytes... outputConsole(buffer) -- ... and output them to the console end fileClose(hFile) -- close the file once we're done with it else outputConsole("Unable to open test.txt") end test.txt it is located in the root of the resource and contains the text " Hello World!" I just realized that I didn't specify in meta.xml file test.txt. now I wonder if it is possible to somehow load a dynamically modified file
-
I made a small library for working with telegram bot. So far, there are few functions, but if there is interest, I will continue developing in my free time. With the help of my library, you can more effectively monitor the server and its users. GitHub -> https://github.com/uriid1/MTA-Telegram-bot Put a star if you liked it