E2Table Class in API #2817
Denneisk
started this conversation in
Suggestions
Replies: 1 comment 2 replies
-
I like the idea, tables should've been like this in the first place for sure. E2 exposes too many internal behaviors that lock us into these backwards compatibility situations. API might need to be a bit different, I alongside others would definitely appreciate arbitrary key types, although maybe that could be done with a separate type since adjusting this might be too annoying while balancing backwards compatibility. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Make E2Tables a class. This would be pretty useful as parts of the implementation and functionality of E2 tables could be offloaded into E2Lib (or wherever the class is defined), thus making them easier to operate with.
Provisional API:
class E2Table
integer size
table<integer, any> n
table<integer, string> ntypes
table<string, any> s
table<string, string> stypes
string? IsHomogeneous
- ? Optimization flag. Set to the homogeneous typeidboolean? IsSequential
- ? Optimization flagnewE2Table(table? args, table? types): E2Table
- Initializes anE2Table
. If first argument and second argument are specified, initialize the outputE2Table
with the key-values inargs
and the types intypes
. The second argument may be optional if type guessing is included.E2Table:Get(string|integer key): any? value, string? type
- Returns the value and type of an element at the index or nil if it doesn't exist.E2Table:Set(string|integer key, any value, string type)
- Sets the key in theE2Table
to the value with the provided type. The third argument may be optional if type guessing is included.E2Table:Clone(): E2Table
- Shallow copy (subtables are references) (Provisional name)E2Table:Duplicate(): E2Table
- ? Deep copy (subtables are new tables) (Provisional name)Just spitballing with these last ones, but kind of a must if you want to abstract E2 tables' implementations from their usage.
Could also include a type guessing step here and there but that demands a better type implementation.
Beta Was this translation helpful? Give feedback.
All reactions