first commit
CI / Build (clang, clang++, ubuntu-22.04, linux, 3.10, master, x86,x86_64) (push) Canceled after 0s
CI / Build (clang, clang++, windows-2022, windows, 3.10, master, x86,x86_64) (push) Canceled after 0s
CI / Release (push) Canceled after 0s

This commit is contained in:
2026-09-13 22:18:11 +01:00
commit 08c03ac533
6701 changed files with 1577314 additions and 0 deletions
@@ -0,0 +1,5 @@
MRuby::Gem::Specification.new('mruby-print') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'standard print/puts/p'
end
@@ -0,0 +1,55 @@
##
# Kernel
#
# ISO 15.3.1
module Kernel
##
# Invoke method +print+ on STDOUT and passing +*args+
#
# ISO 15.3.1.2.10
def print(*args)
i = 0
len = args.size
while i < len
__printstr__ args[i].to_s
i += 1
end
end
##
# Invoke method +puts+ on STDOUT and passing +*args*+
#
# ISO 15.3.1.2.11
def puts(*args)
i = 0
len = args.size
while i < len
s = args[i].to_s
__printstr__ s
__printstr__ "\n" if (s[-1] != "\n")
i += 1
end
__printstr__ "\n" if len == 0
nil
end
##
# Print human readable object description
#
# ISO 15.3.1.3.34
def p(*args)
i = 0
len = args.size
while i < len
__printstr__ args[i].inspect
__printstr__ "\n"
i += 1
end
args.__svalue
end
def printf(*args)
__printstr__(sprintf(*args))
nil
end
end
@@ -0,0 +1,66 @@
#include <mruby.h>
#ifdef MRB_DISABLE_STDIO
# error print conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb'
#endif
#include <mruby/string.h>
#include <string.h>
#include <stdlib.h>
#if defined(_WIN32)
# include <windows.h>
# include <io.h>
#ifdef _MSC_VER
# define isatty(x) _isatty(x)
# define fileno(x) _fileno(x)
#endif
#endif
static void
printstr(mrb_state *mrb, mrb_value obj)
{
if (mrb_string_p(obj)) {
#if defined(_WIN32)
if (isatty(fileno(stdout))) {
DWORD written;
int mlen = (int)RSTRING_LEN(obj);
char* utf8 = RSTRING_PTR(obj);
int wlen = MultiByteToWideChar(CP_UTF8, 0, utf8, mlen, NULL, 0);
wchar_t* utf16 = (wchar_t*)mrb_malloc(mrb, (wlen+1) * sizeof(wchar_t));
if (MultiByteToWideChar(CP_UTF8, 0, utf8, mlen, utf16, wlen) > 0) {
utf16[wlen] = 0;
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE),
utf16, wlen, &written, NULL);
}
mrb_free(mrb, utf16);
} else
#endif
fwrite(RSTRING_PTR(obj), RSTRING_LEN(obj), 1, stdout);
fflush(stdout);
}
}
/* 15.3.1.2.9 */
/* 15.3.1.3.34 */
mrb_value
mrb_printstr(mrb_state *mrb, mrb_value self)
{
mrb_value argv = mrb_get_arg1(mrb);
printstr(mrb, argv);
return argv;
}
void
mrb_mruby_print_gem_init(mrb_state* mrb)
{
struct RClass *krn;
krn = mrb->kernel_module;
mrb_define_method(mrb, krn, "__printstr__", mrb_printstr, MRB_ARGS_REQ(1));
}
void
mrb_mruby_print_gem_final(mrb_state* mrb)
{
}