🚀 input now can choose `std::getline` to read one line.

This commit is contained in:
ValKmjolnir 2022-07-30 01:31:56 +08:00
parent c0862704f0
commit 52fcc9118c
3 changed files with 9 additions and 5 deletions

View File

@ -25,8 +25,8 @@ var system=func(str){
}
# input uses std::cin and returns what we input.
var input=func(){
return __input();
var input=func(end=nil){
return __input(end);
}
# split a string by separator for example:

View File

@ -277,8 +277,12 @@ nas_ref builtin_system(nas_ref* local,nasal_gc& gc)
}
nas_ref builtin_input(nas_ref* local,nasal_gc& gc)
{
nas_ref end=local[1];
nas_ref ret=gc.alloc(vm_str);
std::cin>>ret.str();
if(end.type!=vm_str || end.str().length()>1)
std::cin>>ret.str();
else
std::getline(std::cin,ret.str(),end.str()[0]);
return ret;
}
nas_ref builtin_fin(nas_ref* local,nasal_gc& gc)

View File

@ -25,8 +25,8 @@ var system=func(str){
}
# input uses std::cin and returns what we input.
var input=func(){
return __input();
var input=func(end=nil){
return __input(end);
}
# split a string by separator for example: