Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Berry add global function format as a simpler syntax to string.format #18925

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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