Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Created November 16, 2020 22:50
Show Gist options
  • Save gr33n7007h/1ee53ec23cbb931e5a14c57c5fa94c14 to your computer and use it in GitHub Desktop.
Save gr33n7007h/1ee53ec23cbb931e5a14c57c5fa94c14 to your computer and use it in GitHub Desktop.
Testing variadic Fiddle version 1.0.1
require 'fiddle'
include Fiddle
# Fiddle v:1.0.1
setlocale = Function.new(
Handle['setlocale'],
[
:int,
:const_string
],
:voidp
)
setlocale.(4, '')
strfmon = Function.new(
Handle['strfmon'],
[
:voidp,
:size_t,
:const_string,
:variadic
],
:ssize_t
)
buf = Pointer.malloc(100)
strfmon.(
buf,
buf.size,
'%n :: %i',
:double,
42.1337,
:double,
42.1337
)
p buf.to_s.force_encoding('utf-8')
free buf
__END__
"£42.13 :: GBP42.13"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment