/xls2lua

Convert xls to lua script for game res

Primary LanguagePython

xls2lua

Convert xls to lua script for game res
use python xlrd

example

building.xls

id name use_money use_food is_init defense
int string int int boolean int
唯一ID 名字 使用金币数 使用食物数 是否初始化 防御力
1 house 1000 123 TRUE 100
123 120
456 130
2 farm 100 234 FALSE 200
200
200
./xls2lua.py building.xls

NOTICE:

The first row must be title.
The second row must be type(int, string, boolean) The third row must be interpretation.
The first column must be ID.
The second column must be Name.

LUA SCRIPT

-- this file is generated by program!
-- don't change it manaully.
-- source file: building.xls
-- created at: Tue May 20 12:08:14 2014


local building = {}


building.type_map = {}
local type_map = building.type_map
type_map[2] = "farms"
type_map["farms"] = 2
type_map[1] = "houses"
type_map["houses"] = 1


building.farms = {}
local farms = building.farms

farms[1] = {
	id = 2,
	name = "farm",
	use_money = 100,
	use_food = 234,
	is_init = false,
	defense = 200,
}

farms[2] = {
	use_money = 200,
}

farms[3] = {
	use_money = 200,
}

building.houses = {}
local houses = building.houses

houses[1] = {
	id = 1,
	name = "house",
	use_money = 1000,
	use_food = 123,
	is_init = false,
	defense = 100,
}

houses[2] = {
	use_money = 123,
	defense = 120,
}

houses[3] = {
	use_money = 456,
	defense = 130,
}

building.type= {}
local type = building.type
type[1] = farms
type[2] = houses



for i=1, #(building.type) do
	local item = building.type[i]
	for j=1, #item do
		item[j].__index = item[j]
		if j < #item then
			setmetatable(item[j+1], item[j])
		end
	end
end


return building

HOW TO USE LUA SCRIPT

local building = require "building"

print(building.houses[2].id)

The console will print 1