Create Oneshot::crc32 Ruby function
Due to issues in loading Zlib directly within Ruby, I decided to create a C++ binding. Boost also has a much faster and smarter CRC32 implementation, so I decided to just use it instead of working with Zlib. This also means that translations are fixed!
This commit is contained in:
parent
cd6b77ac8f
commit
332fc3d9e0
|
|
@ -6,6 +6,7 @@
|
||||||
#include "eventthread.h"
|
#include "eventthread.h"
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <boost/crc.hpp>
|
||||||
|
|
||||||
RB_METHOD(oneshotSetYesNo)
|
RB_METHOD(oneshotSetYesNo)
|
||||||
{
|
{
|
||||||
|
|
@ -88,6 +89,17 @@ RB_METHOD(oneshotShake)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RB_METHOD(oneshotCRC32)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
VALUE string;
|
||||||
|
boost::crc_32_type result;
|
||||||
|
rb_get_args(argc, argv, "S", &string RB_ARG_END);
|
||||||
|
std::string str = std::string(RSTRING_PTR(string), RSTRING_LEN(string));
|
||||||
|
result.process_bytes(str.data(), str.length());
|
||||||
|
return UINT2NUM(result.checksum());
|
||||||
|
}
|
||||||
|
|
||||||
void oneshotBindingInit()
|
void oneshotBindingInit()
|
||||||
{
|
{
|
||||||
VALUE module = rb_define_module("Oneshot");
|
VALUE module = rb_define_module("Oneshot");
|
||||||
|
|
@ -114,4 +126,5 @@ void oneshotBindingInit()
|
||||||
_rb_define_module_function(module, "allow_exit", oneshotAllowExit);
|
_rb_define_module_function(module, "allow_exit", oneshotAllowExit);
|
||||||
_rb_define_module_function(module, "exiting", oneshotExiting);
|
_rb_define_module_function(module, "exiting", oneshotExiting);
|
||||||
_rb_define_module_function(module, "shake", oneshotShake);
|
_rb_define_module_function(module, "shake", oneshotShake);
|
||||||
|
_rb_define_module_function(module, "crc32", oneshotCRC32);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class Language
|
||||||
def tr(string)
|
def tr(string)
|
||||||
#dbg_print(caller_locations(1, 1).first.tap{|loc| puts "#{loc.path}:#{loc.lineno}"})
|
#dbg_print(caller_locations(1, 1).first.tap{|loc| puts "#{loc.path}:#{loc.lineno}"})
|
||||||
if @data
|
if @data
|
||||||
rv = @data[Zlib::crc32(string)] || string
|
rv = @data[Oneshot::crc32(string)] || string
|
||||||
else
|
else
|
||||||
rv = string
|
rv = string
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue