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