commit
e1ee1d8a31
@ -26,6 +26,38 @@ function __vc_Canvas_set_data(self, data)
|
|||||||
self:_set_data(tostring(_ffi.cast("uintptr_t", canvas_ffi_buffer)))
|
self:_set_data(tostring(_ffi.cast("uintptr_t", canvas_ffi_buffer)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_ffi.cdef([[
|
||||||
|
unsigned long crc32(unsigned long crc, const char *buf, unsigned len);
|
||||||
|
]])
|
||||||
|
|
||||||
|
local zlib
|
||||||
|
if _ffi.os == "Windows" then
|
||||||
|
zlib = _ffi.load("zlib1")
|
||||||
|
elseif _ffi.os == "OSX" then
|
||||||
|
zlib = _ffi.load("z")
|
||||||
|
elseif _ffi.os == "Linux" then
|
||||||
|
zlib = _ffi.load("libz.so.1")
|
||||||
|
else
|
||||||
|
error("platform does not support zlib " .. _ffi.os)
|
||||||
|
end
|
||||||
|
|
||||||
|
function crc32(bytes, chksum)
|
||||||
|
local chksum = chksum or 0
|
||||||
|
|
||||||
|
local length = #bytes
|
||||||
|
if type(bytes) == "string" then
|
||||||
|
return zlib.crc32(chksum, bytes, length)
|
||||||
|
elseif type(bytes) == "table" then
|
||||||
|
local buffer = _ffi.new(
|
||||||
|
string.format("char[%s]", length)
|
||||||
|
)
|
||||||
|
for i=1, length do
|
||||||
|
buffer[i - 1] = bytes[i]
|
||||||
|
end
|
||||||
|
return zlib.crc32(chksum, buffer, length)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Check if given table is an array
|
-- Check if given table is an array
|
||||||
function is_array(x)
|
function is_array(x)
|
||||||
if #x > 0 then
|
if #x > 0 then
|
||||||
|
|||||||
@ -30,7 +30,7 @@ static int l_resolve(lua::State* L) {
|
|||||||
static int l_read(lua::State* L) {
|
static int l_read(lua::State* L) {
|
||||||
io::path path = lua::require_string(L, 1);
|
io::path path = lua::require_string(L, 1);
|
||||||
if (io::is_regular_file(path)) {
|
if (io::is_regular_file(path)) {
|
||||||
return lua::pushstring(L, io::read_string(path));
|
return lua::pushlstring(L, io::read_string(path));
|
||||||
}
|
}
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"file does not exists " + util::quote(path.string())
|
"file does not exists " + util::quote(path.string())
|
||||||
|
|||||||
@ -184,6 +184,11 @@ namespace lua {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int pushlstring(lua::State* L, std::string_view view) {
|
||||||
|
lua_pushlstring(L, reinterpret_cast<const char*>(view.data()), view.size());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
inline int pushfstring(lua_State* L, const char* fmt, Args... args) {
|
inline int pushfstring(lua_State* L, const char* fmt, Args... args) {
|
||||||
lua_pushfstring(L, fmt, args...);
|
lua_pushfstring(L, fmt, args...);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user