With an idea from WolfGang Senizen, I have a nice ‘ll’ extension scheme working.
The ll table / library / whatever you want to call it, does not support all the LL functions in the version that runs on your local computer. For example, ll.Rot2Euler is not provided. In my work, I need that function and its “inverse”, so I wrote them.
I’ve been working slowly toward a convenient way both to provide those functions for my local testing, and to use the provided ones in world. Yesterday’s article was a progress report on that. Today’s article combines a scheme that I already had in mind for the require format, plus an idea from WolfGang that lets us avoid a bunch of table copying and such.
Here is the test file that shows that it works:
local __ = require('../inc/expectations')
local ll = require('../inc/ll_extensions')
__:describe('Test ll Extensions', function()
__:test('pre-existing functions work', function()
__:expect(ll.ToLower('ABC'), 'still works').is('abc')
end)
__:test('extended function Euler2Rot', function()
__:expect(ll.Euler2Rot(vector.zero)).is(rotation.identity)
end)
end)
__:execute()
Both tests pass. As an extra check, if you comment out the local ll at the top, the Euler2Rot test fails, because the original ll does not include it. So it’s working.
How does it work, you may be wondering. The required file, ‘ll_extensions’ goes like this:
local function _euler_to_rot(euler: vector): rotation
-- details removed
end
local function _rot_to_euler(rot: rotation): vector
-- details removed
end
local _extensions = {
Rot2Euler = _rot_to_euler,
Euler2Rot = _euler_to_rot,
}
setmetatable(_extensions, {__index=ll})
return _extensions
That’s all there is to it:
ll.Seems to be all just fine. I’ll convert my existing code to use this scheme, and if it holds water, which I expect it will, it’ll become my overall approach.
In-world, if our ‘ll_extensions.lua’ file were just return ll, I think we wouldn’t have to change anything else.
What the world needs now is a curated repository of extensions. I don’t feel up to that just now but am certainly willing to share my stuff if such a repo were to exist.
(Curious readers may wonder why I don’t make my repo public. One good reason is that it includes a lot of proprietary code for the Valkyrie Transport products. But there’s plenty that I can share, and when I can, I try to publish it here.)
Safe paths!