ryobg / JContainers

JSON-based data structures for Papyrus - the TESV Skyrim SE scripting language
MIT License
107 stars 23 forks source link

New API functions? #36

Closed ryobg closed 6 years ago

ryobg commented 6 years ago

I will drop here some notes for functions which may be of use for JC users.

  1. [x] int JArray.erase[Integers|Floats|Strings|Forms|Objects] (object, value, start = 0, end = -1) - basically run over the whole range and delete all items which equal the passed value. Optionally, specify sub-range. Return the number of erased items.
  2. [x] JArray.reverse (object, strart = 0, end = -1) - reverse the order of elements within an array. May be used in conjunction with JArray.sort to get the opposite order.
  3. [x] int JArray.count[Integers|Floats|Strings|Forms|Objects] (object, value, start = 0, end = -1) - go over a range within an array and count how many times a given value occurs.
  4. [ ] Extend/add new version of JArray.sort with some generic utility to enable like reverse sorting, attribute sorting and etc. Probably with some kind of Lua/Papyrus(?) predicate.
RealAntithesis commented 6 years ago

I assume you are looking for c/c++ functions to go into the dll for direct access in papyrus? I've done similar functions in lua (being much faster than papyrus) but the lua interface is a bit indirect (but still more than useful once I got it into my workflow).

Something which would be useful in the long term is to expose more of the api to lua.

ryobg commented 6 years ago

@RealAntithesis yes, it is about the DLL API, which can be easily translated to Papyrus and Lua.

P.S. Basically, I want to gather feedback. Some stuff is no easily done, but some can be added easily. There is quite good foundation of well known algorithms for working with containers, but JC application domain do not need all of them. Maybe some only. Of course, the rest is in the hands of the user, but I have seen things like min & max needs, a bit superflous hasKey/getObj pairs and etc.

P.S. 2: Sure about more API into Lua. I think your recent requests were all served. If you see something else - let me know.

ryobg commented 6 years ago

Apart from some indexing arguments and the 'flexible' predicate for sorting. Rest were added. Then may consider to extend or revise these in the future again.