Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
No edit summary
KethoBot (talk | contribs)
m (apitype template)
Tag: WoW API docs
 
(33 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{wowapitype}}__NOEDITSECTION__
+
{{wowapitype}} {{ood}}
  +
<!--The [[World of Warcraft API]] is constructed in lua, with an accompanying XML definition, in which everything is either a basic type, function or table. Tables are flexible objects that the API uses to define rather distinct WoW-specific "complex" types.
   
  +
==Basic Types==
The [[World of Warcraft API]] uses rather complex values for some arguments and return values. Rather than re-explain them every time they're used, we document them as distinct data types (though in reality they're numbers and strings).
 
  +
===Lua===
  +
Lua variables are not formally assigned a type, but rather dynamically become a type when a value is assigned.<ref>{{ref book|author=R. Ierusalimschy, L. H. de Figueiredo, W. Celes|url=https://www.lua.org/manual/5.1/manual.html|date=20060801|isbn=85-903798-3-3|title=Lua 5.1 Reference Manual|chapter=2.2 – Values and Types}}</ref> World of Warcraft uses seven basic types from Lua.
  +
{| class="darktable zebra"
  +
|-
  +
! Type !! Description !! Implicit casting !! Explicit casting !! Special Functions
  +
|-
  +
| <center>{{apitype|nil}}</center> || absence of any value || || ||
  +
|-
  +
| <center>{{apitype|boolean}}</center> || true or false, historically represented as 1 or nil<sup style="color:yellow">†</sup> || nil → false; any other value → true || <code>x = not not x</code> ||
  +
|-
  +
| <center>{{apitype|number}}</center> || integer or floating-point || "1" → 1; "1.23" → 1.23 || {{api|tonumber(x)}} returns a number or nil || [[Lua functions#Math Functions|Math]], [[Lua functions#Bit Functions|Bitlib]]
  +
|-
  +
| <center>{{apitype|string}}</center> || array of UTF-8 characters || 1.23 → "1.23"; true → "true" || {{api|tostring(x)}} returns "nil", "function: x", etc. || [[Lua functions#String Functions|String]]
  +
|-
  +
| <center>{{apitype|function}}</center> || reference to executable code || || ||
  +
|-
  +
| <center>{{apitype|table}}</center> || reference to an association of key/value pairs || || || [[Lua functions#Table Functions|Table]]
  +
|-
  +
| <center>{{apitype|userdata}}</center> || reference to an object implemented in ''C''<sup style="color:yellow">‡</sup> || || ||
  +
|-
  +
| colspan="5" |
  +
:::<span style="color:yellow">†</span> <span style="font-size:smaller">The original WoW API was written in [https://www.lua.org/manual/4.0/manual.html Lua v4] that had no boolean type; the formal definition being introduced in Lua 5.0</span>
  +
:::<span style="color:yellow">‡</span> <span style="font-size:smaller">The Lua-based WoW API rides over a game engine written in ''C''</span>
  +
|}
   
  +
===XML===
== Complex World of Warcraft API Data Types ==
 
  +
Although XML has 19 primitive data types,<ref>{{Ref web|url=https://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes|title=XML Schema Part 2: Datatypes Second Edition|publisher=World Wide Web Consortium|date=20141028|author=XML Schema Working Group}}</ref> FrameXML only uses five corresponding to Lua types:
{{API types}}
 
  +
{| class="darktable zebra"
  +
|-
  +
! Type !! Description !! Runtime (Lua)
  +
|-
  +
| xs:nil || missing or empty attribute || varies by the default value of each attribute
  +
|-
  +
| xs:boolean || "true" or "false" || usually becomes {{apitype|boolean}}
  +
|-
  +
| xs:int || "1" || usually becomes {{apitype|number}}
  +
|-
  +
| xs:float || "1.23" || usually becomes {{apitype|number}}
  +
|-
  +
| xs:string || "abc" || usually becomes a {{apitype|string}} or a {{api|getglobal|globally accessible}} reference (''ie.'' _G["name"])
  +
|}
   
  +
==API Types==
  +
{{for|the complete list of complex types|:Category:API types}}
  +
The API encodes several complex information using tables and strings. Although these objects are merely instances of the basic types, their utility comes from how the information is encoded. Wowpedia's API documentation treates these as '''complex types''' even though there is no such official term. These may be further categorized as below:
   
  +
{| class="darktable zebra"
[[:Category:API types]] has the full list. (Though if something there is not available here: please list it!)
 
  +
|-
  +
! Category !! Basic Type !! Description
  +
|-
  +
! Numeric ID
  +
| <center>{{apitype|number}}</center> || Whole number enumerating each kind of something, usually ascending from 1 as each expansion adds to the list. <br />(Differs from the enumeration type which is a table with string/number pairs)
  +
: ''Example:'' [[Northrend Dungeonmaster]] has [[achievementID]] <code>1288</code>
  +
|-
  +
! Encoded String
  +
| <center>{{apitype|string}}</center> || Colon-delimited description of an in-game object, usually beginning with its category and ID.
  +
: ''Example:'' [[Hearthstone]] has [[itemString]] <code>"item:6948::::::::80:105::::::"</code>
  +
|-
  +
! Hyperlink
  +
| <center>{{apitype|string}}</center> || An object string surrounded by <code>|H</code> and <code>|h</code> [[UI escape sequences]], interpretted by chat windows as a clickable hyperlink.
  +
: ''Example:'' [[Arugal's Folly]] has [[questLink]] in <code>|cff808080|Hquest:99:15|h[Arugal's Folly]|h|r</code>
  +
|-
  +
! Globally Unique Identifier ([[GUID]])
  +
| <center>{{apitype|string}}</center> || Hyphen-delimited string for every distinguishable object, possibly containing a numeric ID or encoded string in one of the fields.
  +
: ''Example:'' One single [[Kobold Vermin]] in Elwynn Forest might have [[GUID]] <code>Creature-0-6-0-11-31146-000136DF91</code>
  +
|-
  +
! Constant
  +
| <center>''varies''</center> || Global variable (commonly uppercase and underscores) intended to be written in code for legibility and compatibility. <br />The value is fixed (''constant'') during runtime but could differ between classic/retail or languages.
  +
: ''Translation Example:'' [https://www.townlong-yak.com/framexml/live/GlobalStrings.lua FrameXML/GlobalStrings.lua] defines <code>ABSORB = "Absorb"</code> in enUS or <code>ABSORB = "Поглот"</code> in ruRU
  +
: ''Fixed-Value Example:'' [https://www.townlong-yak.com/framexml/live/Constants.lua FrameXML/Constants.lua] defines <code>LOOT_ROLL_TYPE_NEED = 1</code> and <code>LOOT_ROLL_TYPE_GREED = 2</code>
  +
|-
  +
! Enumeration
  +
| <center>{{apitype|table}}</center> || Keys are strings and values are integers used for quick identification. This approach has increasing usage to replace constants. They can be accessed with e.g. <code>/dump Enum.ClubType</code>
  +
: ''Example:'' {{api|Enum Club.ClubType|t=t}} has four keys "BattleNet", "Character", "Guild" and "Other" with values 0 to 3.
  +
|-
  +
! Struct
  +
| <center>{{apitype|table}}</center> || Return values as a consolidated table with several key/value pairs. This approach has increasing usage in the modern API.<ref>For example, compare [https://wow.gamepedia.com/index.php?title=API_C_Map.GetMapInfo&oldid=5328377 GetMapInfo()] until Legion with {{api|C_Map.GetMapInfo||uiMapID}} after [[Patch 8.0.1]]</ref>
  +
: ''Example:'' {{api|C_Map.GetMapInfo||uiMapID}} returns a single table decribed by [[Struct Map.UiMapDetails]]
  +
|-
  +
! Mixin
  +
| <center>{{apitype|table}}</center> || FrameXML tables whose members are copied into another table using {{api|CreateFromMixins(mixin)}} and often (not always) incorporated into XML virtual templates.
  +
: ''Example:'' [[SpellMixin]] provides standard methods on any Spell object inheriting from it.
  +
|}
   
  +
==References==
  +
{{Reflist|2}}
  +
-->
  +
 
{{API types}}
 
[[Category:API types| 0]]
 
[[Category:API types| 0]]

Latest revision as of 22:06, 21 July 2022