Skip to content

Commit

Permalink
Berry add global function format as a simpler syntax to `string.for…
Browse files Browse the repository at this point in the history
…mat` (#18925)
  • Loading branch information
s-hadinger authored Jun 21, 2023
1 parent 635e240 commit 410aadb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/libesp32/berry/src/be_baselib.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "be_vector.h"
#include "be_string.h"
#include "be_map.h"
#include "be_strlib.h"
#include <string.h>

#define READLINE_STEP 100
Expand Down Expand Up @@ -504,6 +505,7 @@ void be_load_baselib_next(bvm *vm)
{
be_regfunc(vm, "call", l_call);
be_regfunc(vm, "bool", l_bool);
be_regfunc(vm, "format", be_str_format);
}
#else
extern const bclass be_class_list;
Expand Down Expand Up @@ -537,6 +539,7 @@ vartab m_builtin (scope: local) {
bytes, class(be_class_bytes)
call, func(l_call)
bool, func(l_bool)
format, func(be_str_format)
}
@const_object_info_end */
#include "../generate/be_fixed_m_builtin.h"
Expand Down
6 changes: 3 additions & 3 deletions lib/libesp32/berry/src/be_strlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ static bbool convert_to_real(bvm *vm, int index, breal *val)
return converted;
}

static int str_format(bvm *vm)
int be_str_format(bvm *vm)
{
int top = be_top(vm);
if (top > 0 && be_isstring(vm, 1)) {
Expand Down Expand Up @@ -940,7 +940,7 @@ static int str_escape(bvm *vm)

#if !BE_USE_PRECOMPILED_OBJECT
be_native_module_attr_table(string) {
be_native_module_function("format", str_format),
be_native_module_function("format", be_str_format),
be_native_module_function("count", str_count),
be_native_module_function("split", str_split),
be_native_module_function("find", str_find),
Expand All @@ -958,7 +958,7 @@ be_define_native_module(string, NULL);
#else
/* @const_object_info_begin
module string (scope: global, depend: BE_USE_STRING_MODULE) {
format, func(str_format)
format, func(be_str_format)
count, func(str_count)
split, func(str_split)
find, func(str_find)
Expand Down
1 change: 1 addition & 0 deletions lib/libesp32/berry/src/be_strlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const char* be_splitpath(const char *path);
const char* be_splitname(const char *path);
const char* be_pushvfstr(bvm *vm, const char *format, va_list arg);
bstring* be_strindex(bvm *vm, bstring *str, bvalue *idx);
int be_str_format(bvm *vm);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 410aadb

Please sign in to comment.