Skip to content
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

More math functions for mta #654

Closed
CrosRoad95 opened this issue Oct 15, 2018 · 12 comments
Closed

More math functions for mta #654

CrosRoad95 opened this issue Oct 15, 2018 · 12 comments
Labels
enhancement New feature or request
Milestone

Comments

@CrosRoad95
Copy link
Contributor

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

@qaisjp
Copy link
Contributor

qaisjp commented Oct 16, 2018

Would library inclusion solve this problem for you?

@qaisjp qaisjp added the enhancement New feature or request label Oct 16, 2018
@ArranTuna
Copy link
Collaborator

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?)

@CrosRoad95
Copy link
Contributor Author

@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

@ArranTuna
Copy link
Collaborator

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.

@CrosRoad95
Copy link
Contributor Author

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

@qaisjp
Copy link
Contributor

qaisjp commented Oct 16, 2018

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?

@CrosRoad95
Copy link
Contributor Author

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????

@jushar
Copy link
Contributor

jushar commented Oct 16, 2018

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.

@CrosRoad95
Copy link
Contributor Author

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

@qaisjp
Copy link
Contributor

qaisjp commented Oct 16, 2018

I would really prefer enabling the regular require from Lua (i.e the lua-package branch)

@ghost
Copy link

ghost commented Oct 17, 2018

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.

  • Luxy.c

@Pirulax
Copy link
Contributor

Pirulax commented Oct 18, 2018

just add a little + feature to <script> tag, namely the to be able to set 'src' to a script from another resource.
Or, as others said, just add a '/libs' folder or something like that.

@botder botder added this to the Backlog milestone Mar 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants