1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00

Ruby: Add method KernAux.cmdline

This commit is contained in:
Alex Kotov 2022-01-22 02:23:40 +05:00
parent 3eaa30d0a8
commit 32c19c14ce
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 32 additions and 0 deletions

View file

@ -16,4 +16,6 @@ have_func 'kernaux_itoa10'
have_func 'kernaux_snprintf'
have_func 'kernaux_cmdline'
raise 'can\'t create Makefile' unless create_makefile 'kernaux/default'

View file

@ -5,6 +5,8 @@
#include <ruby.h>
static VALUE rb_KernAux = Qnil;
static VALUE rb_KernAux_Error = Qnil;
static VALUE rb_KernAux_CmdlineError = Qnil;
static void assert_cb(const char *file, int line, const char *str);
@ -24,9 +26,17 @@ static VALUE rb_KernAux_itoa10(VALUE self, VALUE number);
static VALUE rb_KernAux_snprintf1(int argc, VALUE *argv, VALUE self);
#endif
#ifdef HAVE_KERNAUX_CMDLINE
static VALUE rb_KernAux_cmdline(VALUE self, VALUE cmdline);
#endif
void Init_default()
{
rb_KernAux = rb_define_module("KernAux");
rb_KernAux_Error =
rb_define_class_under(rb_KernAux, "Error", rb_eRuntimeError);
rb_KernAux_CmdlineError =
rb_define_class_under(rb_KernAux, "CmdlineError", rb_KernAux_Error);
kernaux_assert_cb = assert_cb;
@ -48,6 +58,10 @@ void Init_default()
rb_define_singleton_method(rb_KernAux, "snprintf1",
rb_KernAux_snprintf1, -1);
#endif
#ifdef HAVE_KERNAUX_CMDLINE
rb_define_singleton_method(rb_KernAux, "cmdline", rb_KernAux_cmdline, 1);
#endif
}
void assert_cb(const char *const file, const int line, const char *const str)
@ -216,3 +230,12 @@ VALUE rb_KernAux_snprintf1(
return rb_funcall(result_rb, rb_intern("freeze"), 0);
}
#endif
#ifdef HAVE_KERNAUX_CMDLINE
VALUE rb_KernAux_cmdline(VALUE self_rb, VALUE cmdline_rb)
{
Check_Type(cmdline_rb, T_STRING);
rb_raise(rb_KernAux_CmdlineError, "test");
return Qnil;
}
#endif

View file

@ -49,6 +49,13 @@ module KernAux
# @see .panic
#
class AssertError < Error; end
##
# Raised when command line parsing goes wrong.
#
# @see .cmdline
#
class CmdlineError < Error; end
end
# Native extension