-
-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Lua packages #680
Conversation
Similar design to before, but in C++: use require, and package.loaded is enabled. Pure Lua modules must be placed correctly in either: <resource>/?.lua <resource>/?/init.lua Lua C Modules must be placed in: /server/mods/deathmatch/modules/?.dll To easily test or use modules for Windows: Download and install Lua for Windows. Copy contents of C:\Program Files (x86)\Lua\5.1\clibs into /server/mods/deathmatch/modules. Use e.g. require"lfs" To-do: * Port over to clientside (without C module support) * More detailed error messages for Pure lua packages * ACL support for C modules. * Extensive testing
Fixed if someone naughty sets package as nil.
For each resource that wants to use a C module, a right needs to be added in the following format: <right name="module.<name>" access="true"></right> For example, <right name="module.lfs" access="true"></right> A * wildcard works to grant a resource access to all modules.
8d32e08
to
8d74aa2
Compare
I think this should work with LuaRocks |
make hostings can control mtaserver.conf file and keep this path always in place, don't let user to change it |
I made some tests, serverside ( shared code, i don't think there are difference between client and server ). Checks for incorrect behaviour
longText = string.rep("a",2^24)
require(longText) -- just spam in console, and a bit lag require("../../../../../asdf") i was suprised when i discovered this require("ŕşôíŠ%v=Ü6ÇŘ˙˙śeDL×�`���ëGF–±Öş|5ľxuóľ�") -- https://pastebin.com/eA1xHZQr when you trying require this monster, windows produce this sound: setTimer(function()
for k=1,100 do
randomString = {}
for i=1,40 do
randomString[#randomString + 1] = string.char ( math.random(255) )
end
randomString = table.concat(randomString)
require(randomString)
end
end,50,0) nothing special, just make server logs spam
a = createElement("test")
return a rrr = require "test"
iprint(rrr, getElementsByType("test")) Tests in practice usagerrr = require "test"
iprint(rrr, rrr.func(2,2)) where randomModule = {}
randomModule.int = 1
randomModule.float = math.pi
randomModule.string = "hi"
randomModule.table = {a = 3, [1] = 9, asdf = "asdf"}
randomModule.func = function(a,b) return a+b end
return randomModule
function traceback ()
local level = 1
while true do
local info = debug.getinfo(level, "Sl")
if not info then break end
if info.what == "C" then -- is a C function?
print(level, "C function")
else -- a Lua function
print(string.format("[%s]:%d",
info.short_src, info.currentline))
end
level = level + 1
end
end
return traceback
rrr = require "test"
iprint(rrr()) Bugs, issues
print ("blabla")
rrr = require "test" -- contain infinity loop
print("bla bla")
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of what needs fixing and/or double-checking:
- Infinite loop error should output some more useful trace
- Error out
require()
if trying to require the same script file
Other than that seems fine with #683 merged into this.
I will test LuaRocks with this soon and add any further notes on this review.
* Improved warnings Previous looks like shit * fix conflicts * fix conflicts * Fix indentation * Tweak location text * fix path * fixed `nil` return in require * Fix code formatting
any plans to marge? |
@patrikjuvonen — I have investigated requiring the same file. Test code:
I think we should just do the latter. Here is the commit in Lua that removes this error message. The Lua specification also does not define what should happen if |
Also, this is how 5.3.5 behaves for infinite loops: ➜ cat test.lua
require "test"
print "hello"
➜ lua test.lua
lua: C stack overflow
stack traceback:
[C]: in function 'require'
./test.lua:1: in main chunk
[C]: in function 'require'
./test.lua:1: in main chunk
[C]: in function 'require'
./test.lua:1: in main chunk
[C]: in function 'require'
./test.lua:1: in main chunk
[C]: in function 'require'
./test.lua:1: in main chunk
...
[C]: in function 'require'
./test.lua:1: in main chunk
[C]: in function 'require'
./test.lua:1: in main chunk
[C]: in function 'require'
./test.lua:1: in main chunk
[C]: in function 'require'
./test.lua:1: in main chunk
[C]: in function 'require'
test.lua:1: in main chunk
[C]: in ? |
Right now requiring the same file crashes the server. |
Since the development of this PR has halted (has it?), I think it helps if there is an up-to-date todolist of what has to be done in order to complete this PR.
|
A new PR should be created by someone who wants to author this enhancement to the end. Remember to link to this, gather necessary information from here and elsewhere to the new PR. |
Work done by @darkdreamingdan.
This pull request is to record any remaining hurdles that need to be jumped before merging.
Personally, I am only happy with merging this if it's forward compatible with an expansion of this feature to support LuaRocks. Discussion about LuaRocks should be done in a separate issue.
Fixes #654