Closed CrosRoad95 closed 10 months ago
Would library inclusion solve this problem for you?
This is basically a request to not have to type exports.resourceName: so what if there was an MTA function like addExportAsFunction(function) which would be called inside the script that creates the export, then each resource would have that function added as a function that can be called without need for exports.resourceName or even addFunctionAsGlobalFunction(function) that would clone any function (doesn't need to be exported) into each resource's function register (that _gc thing?)
@ArranTuna no, already exists getDistanceBetweenPoints2/3D
why not other useful math functions? this function implementation is shorter then name of this function, but getDistanceBetweenPointAndSegment3D is i think ~30 lines of code
i also want require
addFunctionAsGlobalFunction
and other simillar things
What I mean is servers can add those functions (plus we could have a default resource with all the useful functions included) and all you have to do is start that resource, then it will make all the useful functions accessible in any resource.
now, we need wait for someone who say security
"you can overwrite other resource", "you can do X" "you can do Y"
but you don't need this functions to destroy server, just destroyElement(root)
#security
Quickest, easiest and most lightweight solution ( for the solution being discussed here is a new function getResourceExports
.
Then someone can just write code to automate those exports being introduced into the global scope with an exports wrapper.
@CrosRoad95, you mentioned that library inclusion with require
would not solve your problem. Why not?
require
can solve almost every problem in mta.
Why some math functions ( easing functions, tocolor, getDistanceBetweenPoints2/3D ) are build in mta and others wouldn't be in mta?
getDistanceBetweenPoints2D math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
^ look at length of both, why mta implementing formula that is 20% longer then function name????
I think exports are too slow for such a function (as they serialize and deserialize input and output data).
Library inclusion in form of require
or something similar is probably the better solution. It might even make sense (without having further thought about it) to introduce a new library resource type that works similarly to exports, but actually loads the code into the importing resource rather than the traditional exports approach.
require
from original lua would be enough, i don't wanna make 10 resources, in each i have other type of functions
you should check lua-package branch
I would really prefer enabling the regular require
from Lua (i.e the lua-package
branch)
Well, let's say that require gets enabled: a server owner could now access your system with os., io. which means that require should be filtered - and even when filtered properly - it wont prevent scripters from using them (renaming etc) which might be a security flaw
Maybe there should be a library folder (1 mta resource / server path) containing all libraries which can be imported in meta.xml using <library name="Math utility" src=":libraries/maths.lua" />
OR we simply add another feature called <import type="server/client/shared" src="*.lua" />
which loads them directly into environment which might be the best solution.
just add a little + feature to Githubissues.
Is your feature request related to a problem? Please describe. Low amount of math function that are used often
Describe the solution you'd like Add more math functions
Describe alternatives you've considered Copy and paste one piece of code to every resource
Additional context few math functions that could be added, all of them you can find on wiki and in google getDistanceBetweenPointAndSegment2D getDistanceBetweenPointAndSegment3D, findRotation2D, findRotation3D, getPointFromDistanceRotation, getOffsetFromXYZ except that, should be added function for bazier curve and splines in 2d and 3d