-
Notifications
You must be signed in to change notification settings - Fork 5
[Suggestion] Revisit support for LUA #33
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
Comments
Close as duplicate for #5 |
EDIT: Removed unnecessary "programming" before "API" in the OP |
I'm not sure if I get the need of most of that functions, Module Manager already provides most of the features itself. What I think we need is a way to delegated to a Lua script the resolution of values, or the filtering of nodes. The The temporal directives should really be on the patch? Why not implement it as hooks on the Instead of:
Or
where this last option would create a whole new syntax creep on MM, why not just
Where
I'm not exactly sure about the usefulness of these callbacks, since I don't think it would be a good idea to allow Lua to generate or manipulate Nodes itself (Module Manager should be the only guy in town allowed to do that). But other than that, I think this mechanism would work better. We need to keep in mind: we will need to keep the ConfigCache consistent, and the only way to guarantee that is not allowing anyone else manipulating Nodes. |
Humm... Would not you be thinking on a "GameDatabaseGenerator" where a Lua Script would create the ConfigNodes itself instead of KSP reading |
Preamble
Hi. After 4.5 years with a lot of breaks, I'm finally wanting a solid API for patches. Today I've been trying to implement ISRU patching and I've got plans to expand Ultimate Part Converter with more features. But I've hit several issues, like https://forum.kerbalspaceprogram.com/topic/50533-18x-112x-module-manager-423-july-03th-2023-fireworks-season/page/309/#comment-4440498, which makes both of my attempts at finding nodes with non-standard ID keys difficult, if not impossible. The need for arbitrarily programmable patching system is dictated by lack of constructs that allow cross-products of several lists of nodes, which is needed to implement B9 Fuel Switch compatibility for LPG converter.
The Overview
I'm suggesting addition of Lua API, like #5 that was given to me, but I've not wanted it yet, because the Ultimate Part Converter, which was a part of SSTO Project in the past was simpler and had just half of the code that I want to have now. But it was still remarkable, that it converted any LF jet, LF+Ox rocket, LF tank and LF+Ox tank to its LPG version, while supporting 2 fuel switching mods and SMURFF at the same time. And it still does that today perfectly.
Overview of the API and scripting environment
This solution combines approaches of both #5 and sarbian#157. In particular, it combines Lua API from #5 and functions from the advanced constructs issue. Here are all functions:
regexp(pattern,string)
- run regexp expression on a stringsin
,cos
,tan
,log10
,ln
,log2
,expE
,exp10
,mod
,exp
,sec
,csc
,sqrt
,curt
,root
,log
- math functionsgetKeys(node)
: finds all keys of a given nodegetKeysName(node, name)
: finds all keys with given name of a given nodegetKey(node, name)
: finds the first key with given name of a given node, or nil if not foundsetKey(key, value)
: sets a key to a valueaddKey(node, name, value)
: adds a key to a value and returns the new keyresetKey(node, name, value)
: creates or sets a key and returns the new/existing keysetNameKey(node, name, value)
: sets a key to a value only if present and returns the key or nil if not foundrenameKey(key, name)
- renames a keydelKey(key)
: deletes the keygetAllNodes(node)
: gets all sub-nodes of a nodegetTypeNodes(node, type)
: gets all sub-nodes of a node with given typegetNode(node, type)
: gets the first sub-node of a node with given type, or nil if not foundaddNode(node, name, value)
: adds a node to a value and returns the new noderesetNode(node, name, value)
: creates or sets a node and returns the new/existing nodesetNameNode(node, name, value)
: sets a node to a value only if present and returns the node or nil if not founddelNode(node)
- deletes a given noderetypeNode(node, newtype)
- changes type of the nodecloneNode(existingNode, targetParent)
- copies a node and returns the new nodecopyNode(existingNode, targetNode)
- copies all node data to a different nodeclearNode(node)
- removes all data from a noderootNode(type)
: find a primary root-node with given typerootNodeName(type, name)
: find a root-node with given type and nameFIRST(callback), BEFORE(mod, callback), FOR(mod, callback), AFTER(mod, callback), LAST(mod, callback), FINAL(callback)
: runs the callback without arguments on given stage of loading. BEFORE, FOR, AFTER and LAST also take a modname.Final Considerations
It's a long Feature Request, but it has to because the API will be finally extensive and very powerful. If it's implemented, I'll be grateful and Ultimate Part Converter will be bigger and better than ever.
The text was updated successfully, but these errors were encountered: