aboutsummaryrefslogtreecommitdiff
path: root/io/param.c
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-05-25 17:04:33 +0800
committerDeterminant <[email protected]>2015-05-25 17:04:33 +0800
commitc1e714052f0c2654ebe2a92d6961382146450b9e (patch)
tree24e82deeac88f48cecf173d12adcd85ccd38fca1 /io/param.c
parentbc1e2c57b1f234d153254845d62994bcd1a6e42f (diff)
clear redundant code in `param.c`
Diffstat (limited to 'io/param.c')
-rw-r--r--io/param.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/io/param.c b/io/param.c
index 7e776a8..e10944f 100644
--- a/io/param.c
+++ b/io/param.c
@@ -161,12 +161,9 @@ int nerv_param_file_open_read(lua_State *L, const char *fn) {
return 1;
}
-int nerv_param_file___init(lua_State *L) {
- const char *fn = luaL_checkstring(L, 2);
- const char *mode = luaL_checkstring(L, 3);
+int nerv_param_file_new_(lua_State *L, const char *fn, const char *mode) {
int rd = 1, bin = 0;
size_t i, len = strlen(mode);
- lua_pushvalue(L, 1);
for (i = 0; i < len; i++)
switch (mode[i])
{
@@ -178,21 +175,16 @@ int nerv_param_file___init(lua_State *L) {
nerv_param_file_open_write(L, fn);
}
+int nerv_param_file___init(lua_State *L) {
+ lua_pushvalue(L, 1);
+ return nerv_param_file_new_(L, luaL_checkstring(L, 2),
+ luaL_checkstring(L, 3));
+}
+
int nerv_param_file_new(lua_State *L) {
- const char *fn = luaL_checkstring(L, 1);
- const char *mode = luaL_checkstring(L, 2);
- int rd = 1, bin = 0;
- size_t i, len = strlen(mode);
- for (i = 0; i < len; i++)
- switch (mode[i])
- {
- case 'r': rd = 1; break;
- case 'w': rd = 0; break;
- case 'b': bin = 1; break;
- }
lua_newtable(L);
- return rd ? nerv_param_file_open_read(L, fn) : \
- nerv_param_file_open_write(L, fn);
+ return nerv_param_file_new_(L, luaL_checkstring(L, 1),
+ luaL_checkstring(L, 2));
}
int nerv_param_file_write_chunkdata(lua_State *L) {