Static data load

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

static_data_load(path, callback)

static_data_load is used to get load static data from a XML, JSON or CSV file.

Return value

This function won't return any value.

Arguments

# Argument Type Description
1 path String The location of the static file inside the resource folder (*.xml or *.json).
2 callback Function Function is called when data has been loaded. Data argument contains the data, is nil on error.

Example (JSON)

Example JSON file:

{
  "firstName": "John",
  "lastName": "Smith",
  "age": 27,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    "212 555-1234",
    "646 555-4567",
    "123 456-7890"
  ]
}
static_data_load("my_file.xml", function(data)
  if data ~= nil then
    -- Do something with your data
  else
    print("Failed to load static data")
  end
end)