JeViCo Posted March 17, 2019 Share Posted March 17, 2019 (edited) Hi there! I have custom module for lua language (dll) which use require function to work example: local modul = require("my-module"); local variable = modul.func(some_args, another_stuff) Of course i added this module to mtaserver.conf to avoid require but i don't know how can i use that function from example (module.func) now. Edited March 17, 2019 by JeViCo Link to comment
Sorata_Kanda Posted March 19, 2019 Share Posted March 19, 2019 I'm quite not sure, but shouldn't you be able to just use your methods? Also, I think you can add 'require' permissions to your resource via ACL. Link to comment
JeViCo Posted March 19, 2019 Author Share Posted March 19, 2019 7 hours ago, Sorata_Kanda said: Also, I think you can add 'require' permissions to your resource via ACL Thanks for reply! I tried that and got nothing. I think i can't use this function at all 7 hours ago, Sorata_Kanda said: I'm quite not sure, but shouldn't you be able to just use your methods? What do you mean? Custom functions? I don't understand modules much but i'm gonna do whatever it takes I tried to use discord RPC library (Lua) ( functions such as discordRPC.initialise where discordRPC = require("discord-rpc") ) Link to comment
Moderators IIYAMA Posted March 19, 2019 Moderators Share Posted March 19, 2019 (edited) No your can't use that function as it blocked. This is more or less how a require_once module works. So you can also make your own. (NOTE: it is not exactly the same as require, just the logic of it) Untested, if it works or not is irrelevant for now. modules = {["module1"] = {loaded = false}} function requireThis (name) local thisModule = modules[name] if thisModule then if thisModule.loaded then return thisModule.container else local fileName = name .. ".lua" if fileExists ( fileName ) then local theFile = fileOpen(fileName, true) if theFile then local count = fileGetSize(theFile) local data = fileRead(theFile, count) thisModule.container = loadstring(data)() thisModule.loaded = true end fileClose(theFile) return true end end end return false end requireThis("module1") File: module1.lua local thisModule = { collection = {} } function thisModule:add (...) local data = {...} if data[1] then local collection = self.collection collection[#collection + 1] = data return true end return false end return thisModule Edited March 19, 2019 by IIYAMA Link to comment
XaskeL Posted March 20, 2019 Share Posted March 20, 2019 Так для работы с всякими Discord ботами нужны сокеты. И? Естественно в модуле самом нужно регистрировать Lua функции (пример не приведу, под рукой не осталось ни одного модуля что я писал) но можешь изучать чужие. require в mta заблокирована, как и многие обычные функции Lua. Link to comment
JeViCo Posted March 20, 2019 Author Share Posted March 20, 2019 3 hours ago, XaskeL said: Так для работы с всякими Discord ботами нужны сокеты В том то и проблема, что это не бот для канала, а standalone приложение, которым я могу воспользоваться только при помощи модулей, а не http запросов :с 3 hours ago, XaskeL said: Естественно в модуле самом нужно регистрировать Lua функции Вот как это осуществить я не совсем понимаю. Там используются функции вида модуль.функция, а на уме пока что такая картина (своего рода переход): function функция (...) return модуль.функция(...) end @IIYAMA thank you for your help but i have .dll module. I guess i should make my own methods as @Sorata_Kanda and @XaskeL have already mentioned I think i should do some kind of function transition but i don't know where to start Link to comment
Sorata_Kanda Posted March 22, 2019 Share Posted March 22, 2019 (edited) On 20/03/2019 at 08:56, JeViCo said: В том то и проблема, что это не бот для канала, а standalone приложение, которым я могу воспользоваться только при помощи модулей, а не http запросов :с Вот как это осуществить я не совсем понимаю. Там используются функции вида модуль.функция, а на уме пока что такая картина (своего рода переход): function функция (...) return модуль.функция(...) end @IIYAMA thank you for your help but i have .dll module. I guess i should make my own methods as @Sorata_Kanda and @XaskeL have already mentioned I think i should do some kind of function transition but i don't know where to start @JeViCo Take this wiki page as a reference. You can just include/loadup it into your server and just use the functions like any other function in mta. E.g. if you defined foo_bar() in your module, then you can simply use foo_bar(). However, do remember that .dll can be only used by Windows binaries. For Linux, you have to use .so files Edited March 22, 2019 by Sorata_Kanda Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now