diff options
author | chai <chaifix@163.com> | 2018-09-08 14:52:17 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-09-08 14:52:17 +0800 |
commit | 7c3609b04eabc79db0c0b245a155fc3c5e875053 (patch) | |
tree | 9333f727863c8fed738bd16eaf6d9e2f0d4f53b5 /src/lua/modules | |
parent | 1ccc798ca383fc941d624751293ed88e012900d1 (diff) |
*update
Diffstat (limited to 'src/lua/modules')
-rw-r--r-- | src/lua/modules/filesystem/filesystem.cpp | 7 | ||||
-rw-r--r-- | src/lua/modules/graphics/graphics.cpp | 4 | ||||
-rw-r--r-- | src/lua/modules/net/Buffer.cpp | 10 | ||||
-rw-r--r-- | src/lua/modules/net/Buffer.h | 3 |
4 files changed, 14 insertions, 10 deletions
diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/filesystem.cpp index f377f0c..1fc0d7c 100644 --- a/src/lua/modules/filesystem/filesystem.cpp +++ b/src/lua/modules/filesystem/filesystem.cpp @@ -112,9 +112,10 @@ namespace lua Filesystem* fs = context.fs; const char* file = luax_checkstring(L, 1); unsigned int len; - char* data = (char*)fs->read(file, &len); - luax_pushstring(L, data); - luax_pushinteger(L, len); + Buffer buffer; + buffer.data = (char*)fs->read(file, &buffer.size); + luax_pushstring(L, (char*)buffer.data); + luax_pushinteger(L, buffer.size); return 2; } diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index ada4754..4d597ae 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -110,7 +110,7 @@ namespace lua error(L, "No such image file %s", f); goto fail; } - Buffer b; + Buffer b = {}; if (!fs->read(f, &b)) { error(L, "Failed to read image %s", f); @@ -459,13 +459,13 @@ namespace lua { const char* path = luax_checkstring(L, 1); Filesystem* fs = Filesystem::get(); - Buffer b = {}; if (!fs->exists(path)) { error(L, "No such font %s\n", path); luax_pushnil(L); return 1; } + Buffer b = {}; fs->read(path, &b); font->loadMemory((const unsigned char*)b.data); } diff --git a/src/lua/modules/net/Buffer.cpp b/src/lua/modules/net/Buffer.cpp index cc9f2b4..1a62c9a 100644 --- a/src/lua/modules/net/Buffer.cpp +++ b/src/lua/modules/net/Buffer.cpp @@ -68,10 +68,12 @@ namespace net { BufferRef ref = checkNetBuffer(L); int offset = luax_checkinteger(L, 2); - int len; - const char* str = ref->grabString(&len, offset); - luax_pushstring(L, str); - luax_pushinteger(L, len); + unsigned int len; + char* data = ref->grabString(&len, offset); + Array<char> str; + str.bind(data, len); + luax_pushstring(L, &str); + luax_pushinteger(L, str.count()); return 2; } diff --git a/src/lua/modules/net/Buffer.h b/src/lua/modules/net/Buffer.h index 31e6df8..172682d 100644 --- a/src/lua/modules/net/Buffer.h +++ b/src/lua/modules/net/Buffer.h @@ -52,7 +52,8 @@ namespace net return; } - const char* grabString(int* length, int offset = 0) + /* grab and create a string */ + char* grabString(unsigned int* length, int offset = 0) { int l = offset; for (; l < size; ++l) |