mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Pluggable Struct
This commit is contained in:
@@ -45,7 +45,6 @@
|
||||
|
||||
/* -DDISABLE_XXXX to drop following features */
|
||||
//#define DISABLE_SPRINTF /* Kernel.sprintf method */
|
||||
//#define DISABLE_STRUCT /* Struct class */
|
||||
//#define DISABLE_STDIO /* use of stdio */
|
||||
|
||||
/* -DENABLE_XXXX to enable following features */
|
||||
@@ -84,9 +83,6 @@ typedef short mrb_sym;
|
||||
#ifndef DISABLE_SPRINTF
|
||||
#define ENABLE_SPRINTF
|
||||
#endif
|
||||
#ifndef DISABLE_STRUCT
|
||||
#define ENABLE_STRUCT
|
||||
#endif
|
||||
#ifndef DISABLE_STDIO
|
||||
#define ENABLE_STDIO
|
||||
#endif
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
** mruby/struct.h - Struct class
|
||||
**
|
||||
** See Copyright Notice in mruby.h
|
||||
*/
|
||||
|
||||
#ifndef MRUBY_STRUCT_H
|
||||
#define MRUBY_STRUCT_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct RStruct {
|
||||
struct RBasic basic;
|
||||
long len;
|
||||
mrb_value *ptr;
|
||||
};
|
||||
#define RSTRUCT(st) ((struct RStruct*)((st).value.p))
|
||||
#define RSTRUCT_LEN(st) ((int)(RSTRUCT(st)->len))
|
||||
#define RSTRUCT_PTR(st) (RSTRUCT(st)->ptr)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* MRUBY_STRUCT_H */
|
||||
+10
-12
@@ -29,12 +29,11 @@ enum mrb_vtype {
|
||||
MRB_TT_HASH, /* 16 */
|
||||
MRB_TT_STRING, /* 17 */
|
||||
MRB_TT_RANGE, /* 18 */
|
||||
MRB_TT_STRUCT, /* 19 */
|
||||
MRB_TT_EXCEPTION, /* 20 */
|
||||
MRB_TT_FILE, /* 21 */
|
||||
MRB_TT_ENV, /* 22 */
|
||||
MRB_TT_DATA, /* 23 */
|
||||
MRB_TT_MAXDEFINE /* 24 */
|
||||
MRB_TT_EXCEPTION, /* 19 */
|
||||
MRB_TT_FILE, /* 20 */
|
||||
MRB_TT_ENV, /* 21 */
|
||||
MRB_TT_DATA, /* 22 */
|
||||
MRB_TT_MAXDEFINE /* 23 */
|
||||
};
|
||||
|
||||
typedef struct mrb_value {
|
||||
@@ -89,12 +88,11 @@ enum mrb_vtype {
|
||||
MRB_TT_HASH, /* 17 */
|
||||
MRB_TT_STRING, /* 18 */
|
||||
MRB_TT_RANGE, /* 19 */
|
||||
MRB_TT_STRUCT, /* 20 */
|
||||
MRB_TT_EXCEPTION, /* 21 */
|
||||
MRB_TT_FILE, /* 22 */
|
||||
MRB_TT_ENV, /* 23 */
|
||||
MRB_TT_DATA, /* 24 */
|
||||
MRB_TT_MAXDEFINE /* 25 */
|
||||
MRB_TT_EXCEPTION, /* 20 */
|
||||
MRB_TT_FILE, /* 21 */
|
||||
MRB_TT_ENV, /* 22 */
|
||||
MRB_TT_DATA, /* 23 */
|
||||
MRB_TT_MAXDEFINE /* 24 */
|
||||
};
|
||||
|
||||
#ifdef MRB_ENDIAN_BIG
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
MRuby::Gem::Specification.new('mruby-struct') do |spec|
|
||||
spec.license = 'MIT'
|
||||
spec.authors = 'mruby developers'
|
||||
end
|
||||
@@ -4,18 +4,23 @@
|
||||
** See Copyright Notice in mruby.h
|
||||
*/
|
||||
|
||||
#include "mruby.h"
|
||||
#ifdef ENABLE_STRUCT
|
||||
#include <string.h>
|
||||
#include "error.h"
|
||||
#include "mruby/struct.h"
|
||||
#include "mruby/array.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "mruby.h"
|
||||
#include "mruby/array.h"
|
||||
#include "mruby/string.h"
|
||||
#include "mruby/class.h"
|
||||
#include "mruby/variable.h"
|
||||
|
||||
struct RStruct {
|
||||
struct RBasic basic;
|
||||
long len;
|
||||
mrb_value *ptr;
|
||||
};
|
||||
|
||||
#define RSTRUCT(st) ((struct RStruct*)((st).value.p))
|
||||
#define RSTRUCT_LEN(st) ((int)(RSTRUCT(st)->len))
|
||||
#define RSTRUCT_PTR(st) (RSTRUCT(st)->ptr)
|
||||
|
||||
static struct RClass *
|
||||
struct_class(mrb_state *mrb)
|
||||
@@ -778,4 +783,3 @@ mrb_init_struct(mrb_state *mrb)
|
||||
mrb_define_method(mrb, st, "eql?", mrb_struct_eql, ARGS_REQ(1)); /* 15.2.18.4.12(x) */
|
||||
|
||||
}
|
||||
#endif /* ENABLE_STRUCT */
|
||||
@@ -170,7 +170,6 @@ mrb_obj_id(mrb_value obj)
|
||||
case MRB_TT_ARRAY:
|
||||
case MRB_TT_HASH:
|
||||
case MRB_TT_RANGE:
|
||||
case MRB_TT_STRUCT:
|
||||
case MRB_TT_EXCEPTION:
|
||||
case MRB_TT_FILE:
|
||||
case MRB_TT_DATA:
|
||||
|
||||
@@ -86,9 +86,6 @@ typedef struct {
|
||||
struct RArray array;
|
||||
struct RHash hash;
|
||||
struct RRange range;
|
||||
#ifdef ENABLE_STRUCT
|
||||
struct RStruct strct;
|
||||
#endif
|
||||
struct RData data;
|
||||
struct RProc proc;
|
||||
} as;
|
||||
|
||||
@@ -20,7 +20,6 @@ void mrb_init_array(mrb_state*);
|
||||
void mrb_init_hash(mrb_state*);
|
||||
void mrb_init_numeric(mrb_state*);
|
||||
void mrb_init_range(mrb_state*);
|
||||
void mrb_init_struct(mrb_state*);
|
||||
void mrb_init_gc(mrb_state*);
|
||||
void mrb_init_print(mrb_state*);
|
||||
void mrb_init_math(mrb_state*);
|
||||
@@ -48,9 +47,6 @@ mrb_init_core(mrb_state *mrb)
|
||||
mrb_init_hash(mrb); DONE;
|
||||
mrb_init_numeric(mrb); DONE;
|
||||
mrb_init_range(mrb); DONE;
|
||||
#ifdef ENABLE_STRUCT
|
||||
mrb_init_struct(mrb); DONE;
|
||||
#endif
|
||||
mrb_init_gc(mrb); DONE;
|
||||
#ifdef ENABLE_STDIO
|
||||
mrb_init_print(mrb); DONE;
|
||||
|
||||
@@ -379,7 +379,6 @@ static const struct types {
|
||||
{MRB_TT_HASH, "Hash"},
|
||||
{MRB_TT_STRING, "String"},
|
||||
{MRB_TT_RANGE, "Range"},
|
||||
{MRB_TT_STRUCT, "Struct"},
|
||||
// {MRB_TT_BIGNUM, "Bignum"},
|
||||
{MRB_TT_FILE, "File"},
|
||||
{MRB_TT_DATA, "Data"}, /* internal use: wrapped C pointers */
|
||||
|
||||
Reference in New Issue
Block a user