summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <quaker66@gmail.com>2014-02-18 16:39:47 +0000
committerDaniel Kolesa <quaker66@gmail.com>2014-02-18 16:39:47 +0000
commitac3180ef34a91af2e3c075299f7efdf83f588810 (patch)
treea53eb2855adf9beb3187f6467842522228ce3c75
parentf54c86669e06aaf26359204d9985d9af4e43fb9e (diff)
string lib is no longer required
-rw-r--r--luaxpedite.c1
-rw-r--r--require.lua16
-rw-r--r--ui.lua51
-rw-r--r--util.lua12
4 files changed, 53 insertions, 27 deletions
diff --git a/luaxpedite.c b/luaxpedite.c
index e0abe8a..0bce238 100644
--- a/luaxpedite.c
+++ b/luaxpedite.c
@@ -13,7 +13,6 @@ int main(int argc, char **argv) {
13 lua_call(L, 1, 0); 13 lua_call(L, 1, 0);
14 14
15 LUAOPEN(base) 15 LUAOPEN(base)
16 LUAOPEN(string)
17 LUAOPEN(bit) 16 LUAOPEN(bit)
18 LUAOPEN(jit) 17 LUAOPEN(jit)
19 18
diff --git a/require.lua b/require.lua
index 3e3f460..4b4accf 100644
--- a/require.lua
+++ b/require.lua
@@ -9,13 +9,22 @@ ffi.cdef [[
9 size_t fread(void *ptr, size_t size, size_t count, void *f); 9 size_t fread(void *ptr, size_t size, size_t count, void *f);
10 char *strerror(int errnum); 10 char *strerror(int errnum);
11 extern int errno; 11 extern int errno;
12 char *strchr (char *str, int ch);
13 char *strrchr(char *str, int ch);
14 void *memcpy(void *dest, const void *src, size_t n);
12]] 15]]
13 16
14local C = ffi.C 17local C = ffi.C
15 18
16local loaded = { ["ffi"] = ffi, ["bit"] = bit } 19local loaded = { ["ffi"] = ffi, ["bit"] = bit }
17local loader = function(modname) 20local loader = function(modname)
18 local fname = modname:gsub("%.", "/") .. ".lua" 21 local fname = ffi.new("char[?]", #modname + 5, modname)
22 local p = C.strchr(fname, 46)
23 while p ~= nil do
24 p[0] = 47
25 p = C.strchr(p, 46)
26 end
27 C.memcpy(fname + #modname, ".lua", 5)
19 local f = C.fopen(fname, "rb") 28 local f = C.fopen(fname, "rb")
20 if f == nil then return ffi.string(C.strerror(C.errno)) end 29 if f == nil then return ffi.string(C.strerror(C.errno)) end
21 C.fseek(f, 0, 2) -- end 30 C.fseek(f, 0, 2) -- end
@@ -25,8 +34,9 @@ local loader = function(modname)
25 C.fread(buf, 1, l, f) 34 C.fread(buf, 1, l, f)
26 local cont = ffi.string(buf, l) 35 local cont = ffi.string(buf, l)
27 C.fclose(f) 36 C.fclose(f)
28 local _, dot = fname:find(".*%.") 37 local slash = C.strrchr(fname, 47)
29 if dot then fname = fname:sub(dot + 1) end 38 if slash ~= nil then fname = slash + 1 end
39 fname = ffi.string(fname)
30 f, err = load(cont, "@" .. fname) 40 f, err = load(cont, "@" .. fname)
31 if not f then error("error loading module '" .. modname 41 if not f then error("error loading module '" .. modname
32 .. "' from file '" .. fname .. "':\n" .. err, 2) 42 .. "' from file '" .. fname .. "':\n" .. err, 2)
diff --git a/ui.lua b/ui.lua
index 7313bc9..5a1c887 100644
--- a/ui.lua
+++ b/ui.lua
@@ -9,6 +9,7 @@ local require = require
9local util = require("util") 9local util = require("util")
10local get_time = util.get_time 10local get_time = util.get_time
11local write_out = util.write_out 11local write_out = util.write_out
12local printf = util.printf
12 13
13local p_fps = 0 14local p_fps = 0
14local key_func, loop_func 15local key_func, loop_func
@@ -54,10 +55,9 @@ local M = {}
54 55
55local ui_func_set, ui_menu, ui_loop 56local ui_func_set, ui_menu, ui_loop
56 57
57local fpsbuf
58local ui_fps = function(fps) 58local ui_fps = function(fps)
59 --fpsbuf = ("ESCAPE - exit, FPS: %4.3f"):format(fps) 59 --levas.evas_object_text_text_set(o_byline, util.sprintf(32,
60 --levas.evas_object_text_text_set(o_byline, fpsbuf) 60 -- "ESCAPE - exit, FPS: %4.3f", fps))
61 p_fps = fps 61 p_fps = fps
62end 62end
63 63
@@ -67,8 +67,8 @@ local ui_fps_std = function(name, t, f)
67 if f >= loops and not test_done then 67 if f >= loops and not test_done then
68 local fps = f / t 68 local fps = f / t
69 ui_fps(fps) 69 ui_fps(fps)
70 write_out(("%4.2f , %s\n"):format(fps, name)) 70 printf("%4.2f , %s\n", fps, name)
71 --write_out(("Memory usage: %d\n"):format(collectgarbage("count"))) 71 --printf("Memory usage: %d\n", ffi_new("int", collectgarbage("count")))
72 test_done = true 72 test_done = true
73 end 73 end
74end 74end
@@ -144,9 +144,9 @@ local ui_all; ui_all = function()
144 local tim = C.localtime(now) 144 local tim = C.localtime(now)
145 if tim ~= nil then C.strftime(datestr, 1024, "%Y-%m-%d %H:%M:%S", tim) 145 if tim ~= nil then C.strftime(datestr, 1024, "%Y-%m-%d %H:%M:%S", tim)
146 else C.snprintf(datestr, 1024, "unknown") end 146 else C.snprintf(datestr, 1024, "unknown") end
147 --print(("%5.2f , EVAS SPEED"):format(fps / t_count)) 147 --printf("%5.2f , EVAS SPEED", fps / t_count)
148 if cmp_report then 148 if cmp_report then
149 write_out(("%5.2f , EVAS SPEED (WEIGHTED), " 149 printf("%5.2f , EVAS SPEED (WEIGHTED), "
150 .. "tn, %i , " 150 .. "tn, %i , "
151 .. "t, %s , " 151 .. "t, %s , "
152 .. "ev , %i.%i.%i.%i , " 152 .. "ev , %i.%i.%i.%i , "
@@ -154,14 +154,18 @@ local ui_all; ui_all = function()
154 .. "sz , %i , %i , " 154 .. "sz , %i , %i , "
155 .. "c , %i , " 155 .. "c , %i , "
156 .. "e , %s , " 156 .. "e , %s , "
157 .. "fs , %i\n"):format(wfps / (t_count * avgw), 157 .. "fs , %i\n", wfps / (t_count * avgw),
158 --fps / t_count, 158 --fps / t_count,
159 t_count, ffi_str(datestr), levas.evas_version.major, 159 ffi_new("int", t_count), ffi_str(datestr),
160 levas.evas_version.minor, levas.evas_version.micro, 160 ffi_new("int", levas.evas_version.major),
161 levas.evas_version.revision, profile.name, win_w, win_h, 161 ffi_new("int", levas.evas_version.minor),
162 loops, engine[1], fullscreen and 1 or 0)) 162 ffi_new("int", levas.evas_version.micro),
163 ffi_new("int", levas.evas_version.revision),
164 profile.name, ffi_new("int", win_w), ffi_new("int", win_h),
165 ffi_new("int", loops), engine[1],
166 ffi_new("int", fullscreen and 1 or 0))
163 else 167 else
164 write_out(("\n#####Test Result#####\n" 168 printf("\n#####Test Result#####\n"
165 .. "evas fps speed: %5.2f\n" 169 .. "evas fps speed: %5.2f\n"
166 .. "evas fps speed(weighted): %5.2f\n" 170 .. "evas fps speed(weighted): %5.2f\n"
167 .. "testcase count: %i\n" 171 .. "testcase count: %i\n"
@@ -171,12 +175,16 @@ local ui_all; ui_all = function()
171 .. "window size: %i, %i\n" 175 .. "window size: %i, %i\n"
172 .. "loop count: %i\n" 176 .. "loop count: %i\n"
173 .. "engine: %s\n" 177 .. "engine: %s\n"
174 .. "full screen: %i\n"):format(fps / t_count, 178 .. "full screen: %i\n", fps / t_count,
175 (wfps / avgw) / t_count, 179 (wfps / avgw) / t_count,
176 t_count, ffi_str(datestr), levas.evas_version.major, 180 ffi_new("int", t_count), ffi_str(datestr),
177 levas.evas_version.minor, levas.evas_version.micro, 181 ffi_new("int", levas.evas_version.major),
178 levas.evas_version.revision, profile.name, win_w, win_h, 182 ffi_new("int", levas.evas_version.minor),
179 loops, engine[1], fullscreen and 1 or 0)) 183 ffi_new("int", levas.evas_version.micro),
184 ffi_new("int", levas.evas_version.revision),
185 profile.name, ffi_new("int", win_w), ffi_new("int", win_h),
186 ffi_new("int", loops), engine[1],
187 ffi_new("int", fullscreen and 1 or 0))
180 end 188 end
181 end 189 end
182end 190end
@@ -230,8 +238,7 @@ local ui_num = function(n)
230 end 238 end
231 avgw = avgw / wn 239 avgw = avgw / wn
232 if t_count > 0 then 240 if t_count > 0 then
233 write_out(("%5.2f , EVAS SPEED (WEIGHTED)\n") 241 printf("%5.2f , EVAS SPEED (WEIGHTED)\n", wfps / (t_count * avgw))
234 :format(wfps / (t_count * avgw)))
235 end 242 end
236end 243end
237 244
@@ -513,8 +520,8 @@ M.setup = function(conf)
513 local j = 1 520 local j = 1
514 for i = 1, #menu do 521 for i = 1, #menu do
515 if menu[i].weight then 522 if menu[i].weight then
516 write_out(("%3i - %s (Weight %0.2f)\n"):format(j, 523 printf("%3i - %s (Weight %0.2f)\n", ffi_new("int", j),
517 menu[i].text, menu[i].weight)) 524 menu[i].text, menu[i].weight)
518 j = j + 1 525 j = j + 1
519 end 526 end
520 end 527 end
diff --git a/util.lua b/util.lua
index 162a58f..bae2e44 100644
--- a/util.lua
+++ b/util.lua
@@ -1054,6 +1054,7 @@ ffi.cdef [[
1054 1054
1055local C = ffi.C 1055local C = ffi.C
1056local ffi_str = ffi.string 1056local ffi_str = ffi.string
1057local ffi_new = ffi.new
1057 1058
1058M.getenv = function(name) 1059M.getenv = function(name)
1059 local v = C.getenv(name) 1060 local v = C.getenv(name)
@@ -1080,6 +1081,16 @@ end
1080 1081
1081M.printf = C.printf 1082M.printf = C.printf
1082 1083
1084ffi.cdef [[
1085 int sprintf(char *str, const char *fmt, ...);
1086]]
1087
1088M.sprintf = function(size, fmt, ...)
1089 local buf = ffi_new("char[?]", size)
1090 C.sprintf(buf, fmt, ...)
1091 return buf
1092end
1093
1083local resolutions = { 1094local resolutions = {
1084 { "qvga", 320 , 240 }, 1095 { "qvga", 320 , 240 },
1085 { "qvga-p", 240 , 320 }, 1096 { "qvga-p", 240 , 320 },
@@ -1240,7 +1251,6 @@ end
1240 1251
1241M.help = help 1252M.help = help
1242 1253
1243local ffi_new = ffi.new
1244local ffi_load = ffi.load 1254local ffi_load = ffi.load
1245local pcall = pcall 1255local pcall = pcall
1246 1256