From ESOUI Wiki

Jump to: navigation, search

Work-in-progress docs can be founds at: /Docs


Scattered observations

Notes that I should turn into an article at some point

Built-in format strings

Used for raw unit names, i.e. LocalizeString(SI_UNIT_NAME, GetRawUnitName("player")).


Defined here.

It's a class which handles autocomplete for EditBoxes; the constructor accepts:

The "flags" are actually handlers defined here and registered via ZO_AutoComplete.AddFlag. When your EditBox's input changes, a function loops over all of your "include" flags and calls them, passing these arguments:

If you look at the vanilla flag definitions, you can see how they use a function called ZO_AutoComplete.IncludeOrExcludeResult to include or exclude results as appropriate. If you wish to add your own set of auto-complete options, then, you do so by defining your own flag. A word of warning, however: if a ZO_AutoComplete field uses AUTO_COMPLETE_FLAG_ALL, then your custom flags will be included in that field! You should probably have your flags return immediately whenever they're not meant to be used (this may be complicated somewhat by the fact that your handler won't receive the ZO_AutoComplete instance or the attached EditBox as an argument).

If you look at the source code for ZO_AutoComplete, you'll notice that it doesn't create any controls or use any templates. Rather, it uses the following API functions:

These APIs are responsible for showing or hiding the list of autocomplete options as a drop-down menu; the ZO_AutoComplete class relies entirely on a hardcoded menu design. There are other Zenimax widgets that use XML-/Lua-defined controls as a menu instead. As these functions aren't documented yet, the precise operational definition of "a menu" remains unknown. Is it a widget that appears overtop everything else, without being tethered to a specific TopLevelControl? Is it a widget with specific behaviors, or tied to a specific event system? Something else?

Useful formatting

Xbox A button in text

Performance experiments

These are the results of performance tests that I've run on basic operations. In many cases, the performance difference won't be significant — a single operation may complete in less than a millisecond no matter how you do it — but it's still worth knowing what code is the fastest, especially if you're working with relatively large data sets.

Array length

What's the fastest way to get the length of an array? If you're just starting out with add-on development, and learning from existing code, then you might be surprised by the answer!

Before we begin, though, let's define our terms. Lua doesn't have "arrays as first-class members," which is to say: there is no built-in array type. A single type, "table," provides the foundation for sets, maps, and arrays. For this discussion, then, an "array" is a table that meets the following definitions:

The four approaches we're going to test for getting the length are:

If we run each method 10,000,000 times in a row, we come up with the following times:

Benchmark for getting the length of an array 10,000,000 times
Method Result for a 15-length array Result for a 1500-length array
table.getn 0.460 seconds 0.512 seconds
# (normal) 0.099 seconds 0.213 seconds
# (sealed) 0.133 seconds 0.203 seconds
sealed length 0.138 seconds 0.128 seconds

The performance variation isn't significant for one single attempt at getting an array's length. If you were to use the slowest method, table.getn, to get the length of one array that has fifteen elements, then it would take just 0.000000046 seconds. Still, # is built-in, faster to type, and faster to execute.

A few other stats:

Array insertions

What's the fastest way to insert 15 elements into an empty array?

table.insert(myTable, ...)

   for i = 1, 15 do  
      table.insert(dummy, i)

It takes 0.164 seconds to execute this 50,000 times in a row.

myTable[#myTable + 1] = ...

   for i = 1, 15 do  
      dummy[#dummy + 1] = i

It takes 0.143 seconds to execute this 50,000 times in a row.

Note, however, that there are situations where # may be slower: extremely long arrays and things that only recently became arrays (e.g. inserting with keys in reverse order) come to mind.

myTable[i] = ...

   for i = 1, 15 do  
      dummy[i] = i

It takes 0.132 seconds to execute this 50,000 times in a row.

Personal tools