Commit 8f6f36f6 authored by dearblue's avatar dearblue

Add mruby binary loader functions from buffer memory

Add new functions (with `MRB_API`):
- `mrb_read_irep_buf()`
- `mrb_load_irep_buf()`
- `mrb_load_irep_buf_cxt()`
parent 58d525c9
......@@ -31,6 +31,7 @@ MRB_API mrb_value mrb_load_irep_file(mrb_state*,FILE*);
MRB_API mrb_value mrb_load_irep_file_cxt(mrb_state*, FILE*, mrbc_context*);
#endif
MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*);
MRB_API mrb_irep *mrb_read_irep_buf(mrb_state*, const void*, size_t);
/* dump/load error code
*
......
......@@ -52,9 +52,21 @@ MRB_API mrb_irep *mrb_add_irep(mrb_state *mrb);
/* @param [const uint8_t*] irep code, expected as a literal */
MRB_API mrb_value mrb_load_irep(mrb_state*, const uint8_t*);
/*
* @param [const void*] irep code
* @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted.
*/
MRB_API mrb_value mrb_load_irep_buf(mrb_state*, const void*, size_t);
/* @param [const uint8_t*] irep code, expected as a literal */
MRB_API mrb_value mrb_load_irep_cxt(mrb_state*, const uint8_t*, mrbc_context*);
/*
* @param [const void*] irep code
* @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted.
*/
MRB_API mrb_value mrb_load_irep_buf_cxt(mrb_state*, const void*, size_t, mrbc_context*);
void mrb_irep_free(mrb_state*, struct mrb_irep*);
void mrb_irep_incref(mrb_state*, struct mrb_irep*);
void mrb_irep_decref(mrb_state*, struct mrb_irep*);
......
......@@ -629,6 +629,12 @@ mrb_read_irep(mrb_state *mrb, const uint8_t *bin)
return read_irep(mrb, bin, (size_t)-1, flags);
}
MRB_API mrb_irep*
mrb_read_irep_buf(mrb_state *mrb, const void *buf, size_t bufsize)
{
return read_irep(mrb, (const uint8_t *)buf, bufsize, FLAG_SRC_MALLOC);
}
void mrb_exc_set(mrb_state *mrb, mrb_value exc);
static void
......@@ -662,12 +668,24 @@ mrb_load_irep_cxt(mrb_state *mrb, const uint8_t *bin, mrbc_context *c)
return load_irep(mrb, mrb_read_irep(mrb, bin), c);
}
MRB_API mrb_value
mrb_load_irep_buf_cxt(mrb_state *mrb, const void *buf, size_t bufsize, mrbc_context *c)
{
return load_irep(mrb, mrb_read_irep_buf(mrb, buf, bufsize), c);
}
MRB_API mrb_value
mrb_load_irep(mrb_state *mrb, const uint8_t *bin)
{
return mrb_load_irep_cxt(mrb, bin, NULL);
}
MRB_API mrb_value
mrb_load_irep_buf(mrb_state *mrb, const void *buf, size_t bufsize)
{
return mrb_load_irep_buf_cxt(mrb, buf, bufsize, NULL);
}
#ifndef MRB_DISABLE_STDIO
mrb_irep*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment