module_wcwidth.c
1 #include <kuroko/vm.h>
2 #include <kuroko/util.h>
3 
4 #include <wchar.h>
5 #include <locale.h>
6 
7 #ifndef _WIN32
8 extern int wcwidth(wchar_t c);
9 #else
10 static
11 #include "../wcwidth._h"
12 #endif
13 
14 KRK_Function(wcwidth) {
15  FUNCTION_TAKES_EXACTLY(1);
16  CHECK_ARG(0,int,krk_integer_type,codepoint);
17  return INTEGER_VAL(wcwidth(codepoint));
18 }
19 
20 KrkValue krk_module_onload_wcwidth(void) {
21  KrkInstance * module = krk_newInstance(vm.baseClasses->moduleClass);
22  krk_push(OBJECT_VAL(module));
23  KRK_DOC(module, "Character widths.");
24  BIND_FUNC(module, wcwidth);
25 
26 #ifndef _WIN32
27  setlocale(LC_ALL, "");
28 #endif
29 
30  return krk_pop();
31 }
32 
An object of a class.
Definition: object.h:255
KrkInstance * krk_newInstance(KrkClass *_class)
Create a new instance of the given class.
Definition: object.c:339
Stack reference or primative value.
Utilities for creating native bindings.
#define KRK_DOC(thing, text)
Attach documentation to a thing of various types.
Definition: util.h:292
Core API for the bytecode virtual machine.
#define vm
Convenience macro for namespacing.
Definition: vm.h:267
KrkValue krk_pop(void)
Pop the top of the stack.
Definition: vm.c:170
void krk_push(KrkValue value)
Push a stack value.
Definition: vm.c:157