如何使用LuaBridge从文件加载表? [来自C ++的Lua]

时间:2016-03-31 05:57:52

标签: c++ lua

我正在阅读LuaBridge reference manual并且我无法理解如何实际加载/读取.lua文件以便我可以访问其中的表。

这是lua文件(从tiled导出):

return {
  version = "1.1",
  luaversion = "5.1",
  tiledversion = "0.16.0",
  orientation = "orthogonal",
  renderorder = "right-down",
  width = 16,
  height = 16,
  tilewidth = 32,
  tileheight = 32,
  nextobjectid = 3,
  properties = {},
  tilesets = {
    {
      name = "terrain_atlas",
      firstgid = 1,
      tilewidth = 32,
      tileheight = 32,
      spacing = 0,
      margin = 0,
      image = "../../../../Resources/Tilesets/Atlas/terrain_atlas.png",
      imagewidth = 1024,
      imageheight = 1024,
      tileoffset = {
        x = 0,
        y = 0
      },
      properties = {},
      terrains = {},
      tilecount = 1024,
      tiles = {}
    }
  },
  layers = {
    {
      type = "tilelayer",
      name = "Ground",
      x = 0,
      y = 0,
      width = 16,
      height = 16,
      visible = true,
      opacity = 1,
      offsetx = 0,
      offsety = 0,
      properties = {},
      encoding = "lua",
      data = {
        839, 840, 840, 840, 840, 840, 840, 840, 840, 840, 840, 840, 840, 840, 840, 841,
        871, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 873,
        871, 872, 872, 872, 872, 936, 872, 872, 872, 872, 872, 872, 872, 872, 872, 873,
        871, 872, 937, 872, 872, 872, 872, 872, 872, 872, 872, 872, 937, 872, 872, 873,
        871, 872, 872, 872, 872, 872, 872, 872, 872, 935, 872, 872, 872, 872, 872, 873,
        871, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 873,
        871, 872, 872, 872, 936, 872, 872, 937, 872, 872, 872, 872, 872, 872, 872, 873,
        871, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 873,
        871, 872, 872, 872, 872, 872, 872, 872, 872, 872, 935, 872, 872, 872, 872, 873,
        871, 872, 872, 872, 935, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 873,
        871, 936, 872, 872, 872, 872, 872, 872, 936, 872, 872, 872, 872, 872, 872, 873,
        871, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 873,
        871, 872, 872, 872, 937, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 873,
        871, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 935, 872, 872, 872, 873,
        871, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 873,
        903, 904, 904, 904, 904, 904, 904, 904, 904, 904, 904, 904, 904, 904, 904, 905
      }
    },
    {
      type = "tilelayer",
      name = "Above",
      x = 0,
      y = 0,
      width = 16,
      height = 16,
      visible = true,
      opacity = 1,
      offsetx = 0,
      offsety = 0,
      properties = {},
      encoding = "lua",
      data = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 938, 0, 0, 0,
        0, 0, 0, 0, 907, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 876, 0, 0, 0, 0,
        0, 0, 939, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 874, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 939, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

您正在搜索:

{
  data: [
    ... collection of resource objects
  ]
}

manualreference manual中所述。它会读取您的文件并在import DS from 'ember-data'; export default DS.JSONAPISerializer.extend({ primaryKey: 'id', normalizeFindAllResponse(store, type, payload) { return { data: payload.map((el) => { return { id: el.id, type: type.modelName, attributes: { /* the attributes you need from el */ } } }) }; } }); 变量中返回您的对象。