读取.csv文件为.erl文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kkx12138/article/details/79438339

1. 功能描述

erlang游戏服务器经常会用到的一个功能模块就是将策划配置的.csv文件改写成 .erl 文件。所以我把这个功能单独写成了一个服务。

2. 服务git地址为

https://github.com/hongweikkx/csv2erl.git

3. 功能效果:

.csv 文件
cat hero.csv

hero_id,hero_name
英雄id,英雄名字
int,string
1001,貂蝉
1002,甄姬

=> .erl 文件
cat hero.erl

-module(hero).
-export([get/1, get_all/0]).
-include("table_to_data_record.hrl").
get(1001) ->
    #data_hero{
        hero_id = 1001,
        hero_name = [232,178,130,232,157,137]
};
get(1002) ->
    #data_hero{
        hero_id = 1002,
        hero_name = [231,148,132,229,167,172]
};
get(_) -> not_find.

get_all() ->
    [1001,1002].

猜你喜欢

转载自blog.csdn.net/kkx12138/article/details/79438339