aboutsummaryrefslogtreecommitdiff
path: root/io
diff options
context:
space:
mode:
Diffstat (limited to 'io')
-rw-r--r--io/init.lua3
-rw-r--r--io/param.c10
2 files changed, 8 insertions, 5 deletions
diff --git a/io/init.lua b/io/init.lua
index d96f062..dc1c6c3 100644
--- a/io/init.lua
+++ b/io/init.lua
@@ -22,7 +22,8 @@ function nerv.ParamFile:read_param(id)
if metadata == nil then
nerv_error("param with id %s does not exist", id)
end
- local param = assert(loadstring("return " .. metadata.type .. "(" .. id .. ")"))()
+ local param = assert(loadstring("return " ..
+ metadata.type .. "(\"" .. id .. "\")"))()
param:set_info(metadata.info)
param:read(self:get_chunkdata(id))
return param
diff --git a/io/param.c b/io/param.c
index 477df28..a57b183 100644
--- a/io/param.c
+++ b/io/param.c
@@ -77,7 +77,8 @@ ParamChunkData *get_param_chunk_data(FILE *fp, ParamChunkInfo *info) {
pcd->data = (char *)malloc(info->length);
pcd->fp = fmemopen(pcd->data, info->length, "r");
assert(fseeko(fp, info->offset, SEEK_SET) == 0);
- assert(fread(pcd->data, 1, info->length, fp) == (size_t)info->length);
+ if (fread(pcd->data, 1, info->length, fp) != (size_t)info->length)
+ return NULL;
return pcd;
}
@@ -239,6 +240,7 @@ int nerv_param_file_write_chunkdata(lua_State *L) {
int nerv_param_file_get_chunkdata(lua_State *L) {
ParamFileHandle *pfh;
ParamChunkInfo *pci;
+ ParamChunkData *pcd;
const char *id = luaL_checkstring(L, 2);
lua_getfield(L, 1, "handle");
@@ -252,9 +254,9 @@ int nerv_param_file_get_chunkdata(lua_State *L) {
return 0;
lua_getfield(L, -1, "chunk");
pci = luaT_checkudata(L, -1, nerv_param_chunk_info_tname);
-
- luaT_pushudata(L, get_param_chunk_data(pfh->fp, pci),
- nerv_param_chunk_data_tname);
+ if (!(pcd = get_param_chunk_data(pfh->fp, pci)))
+ nerv_error(L, "unexpected end of file");
+ luaT_pushudata(L, pcd, nerv_param_chunk_data_tname);
return 1;
}