summaryrefslogtreecommitdiff
path: root/htk_io/src/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'htk_io/src/init.c')
-rw-r--r--htk_io/src/init.c63
1 files changed, 53 insertions, 10 deletions
diff --git a/htk_io/src/init.c b/htk_io/src/init.c
index 8a1ec3b..04046e9 100644
--- a/htk_io/src/init.c
+++ b/htk_io/src/init.c
@@ -7,13 +7,37 @@ const char *nerv_tnet_label_repo_tname = "nerv.TNetLabelRepo";
const char *nerv_matrix_host_float_tname = "nerv.MMatrixFloat";
static int feat_repo_new(lua_State *L) {
- const char *scp_file = luaL_checkstring(L, 1);
- const char *conf = luaL_checkstring(L, 2);
- int frm_ext = luaL_checkinteger(L, 3);
- TNetFeatureRepo *repo = tnet_feature_repo_new(scp_file, conf, frm_ext);
+ TNetFeatureRepo *repo = NULL;
+ if(lua_gettop(L) == 1)
+ {
+ long id = luaL_checkinteger(L, 1);
+ repo = tnet_feature_repo_newWithId(id);
+ }
+ else
+ {
+ const char *scp_file = luaL_checkstring(L, 1);
+ const char *conf = luaL_checkstring(L, 2);
+ int frm_ext = luaL_checkinteger(L, 3);
+ repo = tnet_feature_repo_new(scp_file, conf, frm_ext);
+ }
+
luaT_pushudata(L, repo, nerv_tnet_feat_repo_tname);
return 1;
}
+static int feat_repo_id(lua_State *L) {
+ TNetFeatureRepo *repo = luaT_checkudata(L, 1, nerv_tnet_feat_repo_tname);
+ lua_pushinteger(L, tnet_feature_repo_id(repo));
+ return 1;
+}
+
+static int feat_repo_tostring(lua_State *L)
+{
+ char str[128];
+ TNetFeatureRepo *repo = luaT_checkudata(L, 1, nerv_tnet_feat_repo_tname);
+ snprintf(str, 128, "%s <%lx>", nerv_tnet_feat_repo_tname, tnet_feature_repo_id(repo));
+ lua_pushstring(L, str);
+ return 1;
+}
static int feat_repo_destroy(lua_State *L) {
TNetFeatureRepo *repo = luaT_checkudata(L, 1, nerv_tnet_feat_repo_tname);
@@ -55,22 +79,40 @@ static const luaL_Reg feat_repo_methods[] = {
{"cur_tag", feat_repo_current_tag},
{"next", feat_repo_next},
{"is_end", feat_repo_is_end},
+ {"__tostring", feat_repo_tostring},
+ {"id", feat_repo_id},
{NULL, NULL}
};
static int label_repo_new(lua_State *L) {
- const char *mlf_file = luaL_checkstring(L, 1);
- const char *fmt = luaL_checkstring(L, 2);
- const char *arg = luaL_checkstring(L, 3);
- const char *dir = luaL_checkstring(L, 4);
- const char *ext = luaL_checkstring(L, 5);
- TNetLabelRepo *repo = tnet_label_repo_new(
+ TNetLabelRepo *repo = NULL;
+ if(lua_gettop(L) == 1)
+ {
+ long id = luaL_checkinteger(L, 1);
+ repo = tnet_label_repo_newWithId(id);
+ }
+ else
+ {
+ const char *mlf_file = luaL_checkstring(L, 1);
+ const char *fmt = luaL_checkstring(L, 2);
+ const char *arg = luaL_checkstring(L, 3);
+ const char *dir = luaL_checkstring(L, 4);
+ const char *ext = luaL_checkstring(L, 5);
+ repo = tnet_label_repo_new(
mlf_file, fmt, arg,
dir, ext);
+ }
luaT_pushudata(L, repo, nerv_tnet_label_repo_tname);
return 1;
}
+static int label_repo_id(lua_State *L) {
+ TNetLabelRepo *repo = luaT_checkudata(L, 1, nerv_tnet_label_repo_tname);
+ lua_pushinteger(L, tnet_label_repo_id(repo));
+ return 1;
+}
+
+
static int label_repo_read_utterance(lua_State *L) {
TNetLabelRepo *repo = luaT_checkudata(L, 1, nerv_tnet_label_repo_tname);
TNetFeatureRepo *feat_repo = luaT_checkudata(L, 2, nerv_tnet_feat_repo_tname);
@@ -95,6 +137,7 @@ static int label_repo_destroy(lua_State *L) {
static const luaL_Reg label_repo_methods[] = {
{"get_utter", label_repo_read_utterance},
+ {"id", label_repo_id},
{NULL, NULL}
};