Skip to content

Commit fbcd000

Browse files
committed
remove file.loader because lua support external string now
1 parent b6df887 commit fbcd000

File tree

7 files changed

+6
-74
lines changed

7 files changed

+6
-74
lines changed

src/file.c

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -50,77 +50,12 @@ lfile_load(lua_State *L) {
5050
return 1;
5151
}
5252

53-
struct file_buffer {
54-
void *ptr;
55-
};
56-
57-
static int
58-
close_buffer(lua_State *L) {
59-
struct file_buffer *buf = lua_touserdata(L, 1);
60-
free(buf->ptr);
61-
buf->ptr = NULL;
62-
lua_pushnil(L);
63-
lua_setmetatable(L, 1);
64-
return 0;
65-
}
66-
67-
static int
68-
loader(lua_State *L) {
69-
const char *filename = lua_tostring(L, lua_upvalueindex(1));
70-
const char *mode = luaL_optstring(L, 2, "rb");
71-
FILE *f = fopen_utf8(filename, mode);
72-
if (f == NULL)
73-
return luaL_error(L, "Can't open %s", filename);
74-
75-
struct file_buffer * buf = (struct file_buffer *)lua_newuserdatauv(L, sizeof(*buf), 0);
76-
buf->ptr = NULL;
77-
if (luaL_newmetatable(L, "SOLUNA_LOADER")) {
78-
luaL_Reg l[] = {
79-
{ "__close", close_buffer },
80-
{ "__gc", close_buffer },
81-
{ NULL, NULL },
82-
};
83-
luaL_setfuncs(L, l, 0);
84-
}
85-
lua_setmetatable(L, -2);
86-
87-
fseek(f, 0, SEEK_END);
88-
size_t sz = ftell(f);
89-
fseek(f, 0, SEEK_SET);
90-
91-
buf->ptr = malloc(sz);
92-
if (buf->ptr == NULL) {
93-
fclose(f);
94-
return luaL_error(L, "loader : Out of memory");
95-
}
96-
size_t rd = fread(buf->ptr, 1, sz, f);
97-
fclose(f);
98-
if (rd != sz) {
99-
free(buf->ptr);
100-
buf->ptr = NULL;
101-
return luaL_error(L, "Read %s failed", filename);
102-
}
103-
lua_pushlightuserdata(L, buf->ptr);
104-
lua_pushinteger(L, sz);
105-
lua_pushvalue(L, -3);
106-
return 3;
107-
}
108-
109-
static int
110-
lfile_loader(lua_State *L) {
111-
lua_settop(L, 1);
112-
luaL_checkstring(L, 1);
113-
lua_pushcclosure(L, loader, 1);
114-
return 1;
115-
}
116-
11753
int
11854
luaopen_soluna_file(lua_State *L) {
11955
luaL_checkversion(L);
12056
luaL_Reg l[] = {
12157
{ "exist", lfile_exist },
12258
{ "load", lfile_load },
123-
{ "loader", lfile_loader },
12459
{ NULL, NULL },
12560
};
12661
luaL_newlib(L, l);

src/lualib/icon.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local icon = {}
99

1010
function icon.bundle(filename)
1111
local path = filename:match "(.*[/\\])[^/\\]+$"
12-
local b = datalist.parse(file.loader(filename))
12+
local b = datalist.parse(file.load(filename))
1313
local names = {}
1414
local icons = {}
1515
local n = #b

src/lualib/initsetting.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ function S.init(args)
5959
local default_settings = datalist.parse(source.data.settingdefault)
6060
local realname = settings_filename(args[1])
6161
if realname then
62-
local loader = file.loader(realname)
63-
local game_settings = datalist.parse(loader)
62+
local game_settings = datalist.parse(file.load(realname))
6463
for k,v in pairs(game_settings) do
6564
patch(default_settings, k,v)
6665
end

src/lualib/layout.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ do
128128
function layout.load(filename_or_list, scripts)
129129
local list
130130
if type(filename_or_list) == "string" then
131-
list = datalist.parse_list(file.loader(filename_or_list))
131+
list = datalist.parse_list(file.load(filename_or_list))
132132
else
133133
list = filename_or_list
134134
end

src/lualib/spritebundle.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ global type, tonumber, error, assert, ipairs, print
77
local M = {}
88

99
local function load_bundle(filename)
10-
local b = datalist.parse(file.loader(filename))
10+
local b = datalist.parse(file.load(filename))
1111
return b
1212
end
1313

test/file.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ local file = require "soluna.file"
22
local image = require "soluna.image"
33
local lfs = require "soluna.lfs"
44

5-
local loader = file.loader "asset/avatar.png"
6-
7-
print_r(image.info(loader))
5+
print_r(image.info(file.load "asset/avatar.png"))
86
print(lfs.realpath ".")
97

108
for name in lfs.dir "." do

test/image.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local image = require "soluna.image"
22
local file = require "soluna.file"
33

4-
local c = file.loader "asset/avatar.png"
4+
local c = file.load "asset/avatar.png"
55
print(image.info(c))
66
local content, w, h = image.load(c)
77
local x, y, cw, ch = image.crop(content, w, h)

0 commit comments

Comments
 (0)