mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
...
This commit is contained in:
parent
41ef71a580
commit
be273f55c9
@ -442,7 +442,8 @@ __NEXT_STEP:;
|
||||
auto it = _lazy_modules.find(name);
|
||||
if(it == _lazy_modules.end()){
|
||||
bool ok = false;
|
||||
source = _read_file_cwd(fmt(name, ".py"), &ok);
|
||||
Bytes b = _read_file_cwd(fmt(name, ".py"), &ok);
|
||||
source = Str(b._data);
|
||||
if(!ok) _error("ImportError", fmt("module ", name.escape(), " not found"));
|
||||
}else{
|
||||
source = it->second;
|
||||
|
10
src/io.h
10
src/io.h
@ -11,18 +11,18 @@
|
||||
|
||||
namespace pkpy{
|
||||
|
||||
inline Str _read_file_cwd(const Str& name, bool* ok){
|
||||
inline Bytes _read_file_cwd(const Str& name, bool* ok){
|
||||
std::filesystem::path path(name.sv());
|
||||
bool exists = std::filesystem::exists(path);
|
||||
if(!exists){
|
||||
*ok = false;
|
||||
return Str();
|
||||
return Bytes();
|
||||
}
|
||||
std::ifstream ifs(path);
|
||||
std::string buffer((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
|
||||
ifs.close();
|
||||
*ok = true;
|
||||
return Str(std::move(buffer));
|
||||
return Bytes({std::move(buffer)});
|
||||
}
|
||||
|
||||
struct FileIO {
|
||||
@ -175,9 +175,9 @@ namespace pkpy{
|
||||
inline void add_module_io(VM* vm){}
|
||||
inline void add_module_os(VM* vm){}
|
||||
|
||||
inline Str _read_file_cwd(const Str& name, bool* ok){
|
||||
inline Bytes _read_file_cwd(const Str& name, bool* ok){
|
||||
*ok = false;
|
||||
return Str();
|
||||
return Bytes();
|
||||
}
|
||||
|
||||
} // namespace pkpy
|
||||
|
2
src/vm.h
2
src/vm.h
@ -24,7 +24,7 @@ namespace pkpy{
|
||||
#define POPX() (s_data.popx())
|
||||
#define STACK_VIEW(n) (s_data.view(n))
|
||||
|
||||
Str _read_file_cwd(const Str& name, bool* ok);
|
||||
Bytes _read_file_cwd(const Str& name, bool* ok);
|
||||
|
||||
#define DEF_NATIVE_2(ctype, ptype) \
|
||||
template<> inline ctype py_cast<ctype>(VM* vm, PyObject* obj) { \
|
||||
|
Loading…
x
Reference in New Issue
Block a user