diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-05 12:07:46 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2013-02-16 23:19:15 (GMT) |
commit | ddc650c96c24e5899d46244a18ce2b106f835ceb (patch) | |
tree | c24fc36ed56220760096fdf8c007263e0920ebab /src | |
parent | 4df6d5d83a3d4eb1fc0efb1dd3a68326e52cf912 (diff) | |
download | fluxbox_pavel-ddc650c96c24e5899d46244a18ce2b106f835ceb.zip fluxbox_pavel-ddc650c96c24e5899d46244a18ce2b106f835ceb.tar.bz2 |
luamm: add a version of loadstring which also takes the string length as a parameter
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/Luamm.cc | 21 | ||||
-rw-r--r-- | src/FbTk/Luamm.hh | 4 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/FbTk/Luamm.cc b/src/FbTk/Luamm.cc index 3de86db..c4ea2e0 100644 --- a/src/FbTk/Luamm.cc +++ b/src/FbTk/Luamm.cc | |||
@@ -145,6 +145,19 @@ namespace lua { | |||
145 | return r ? 3 : 1; | 145 | return r ? 3 : 1; |
146 | } | 146 | } |
147 | 147 | ||
148 | struct reader_data { | ||
149 | const void *s; | ||
150 | size_t len; | ||
151 | }; | ||
152 | |||
153 | const char *string_reader(lua_State *, void *data, size_t *size) | ||
154 | { | ||
155 | reader_data *d = static_cast<reader_data *>(data); | ||
156 | *size = d->len; | ||
157 | d->len = 0; | ||
158 | return static_cast<const char *>(d->s); | ||
159 | } | ||
160 | |||
148 | } | 161 | } |
149 | 162 | ||
150 | std::string exception::get_error_msg(state *L) | 163 | std::string exception::get_error_msg(state *L) |
@@ -336,9 +349,13 @@ namespace lua { | |||
336 | } | 349 | } |
337 | } | 350 | } |
338 | 351 | ||
339 | void state::loadstring(const char *s) throw(lua::syntax_error, std::bad_alloc) | 352 | void |
353 | state::loadstring(const char *s, size_t len, const char *chunkname) | ||
354 | throw(lua::syntax_error, std::bad_alloc) | ||
340 | { | 355 | { |
341 | switch(luaL_loadstring(cobj, s)) { | 356 | reader_data data = { s, len }; |
357 | |||
358 | switch(lua_load(cobj, string_reader, &data, chunkname)) { | ||
342 | case 0: | 359 | case 0: |
343 | return; | 360 | return; |
344 | case LUA_ERRSYNTAX: | 361 | case LUA_ERRSYNTAX: |
diff --git a/src/FbTk/Luamm.hh b/src/FbTk/Luamm.hh index 218eea9..0ebe6ef 100644 --- a/src/FbTk/Luamm.hh +++ b/src/FbTk/Luamm.hh | |||
@@ -23,6 +23,7 @@ | |||
23 | #define FBTK_LUAMM_HH | 23 | #define FBTK_LUAMM_HH |
24 | 24 | ||
25 | #include <assert.h> | 25 | #include <assert.h> |
26 | #include <cstring> | ||
26 | #include <memory> | 27 | #include <memory> |
27 | #include <stdexcept> | 28 | #include <stdexcept> |
28 | 29 | ||
@@ -255,7 +256,8 @@ namespace lua { | |||
255 | void getglobal(const char *name) { getfield(GLOBALSINDEX, name); } | 256 | void getglobal(const char *name) { getfield(GLOBALSINDEX, name); } |
256 | bool lessthan(int index1, int index2); | 257 | bool lessthan(int index1, int index2); |
257 | void loadfile(const char *filename) throw(lua::syntax_error, lua::file_error, std::bad_alloc); | 258 | void loadfile(const char *filename) throw(lua::syntax_error, lua::file_error, std::bad_alloc); |
258 | void loadstring(const char *s) throw(lua::syntax_error, std::bad_alloc); | 259 | void loadstring(const char *s, const char *chunkname = NULL) throw(lua::syntax_error, std::bad_alloc) { loadstring(s, strlen(s), chunkname); } |
260 | void loadstring(const char *s, size_t len, const char *chunkname = NULL) throw(lua::syntax_error, std::bad_alloc); | ||
259 | bool next(int index); | 261 | bool next(int index); |
260 | // register is a reserved word :/ | 262 | // register is a reserved word :/ |
261 | template<typename Functor> | 263 | template<typename Functor> |