A Tcl like command language made for the Clinl kernel testing
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 

47 Zeilen
1.1 KiB

/*#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
*/
#include "crank.h"
#include <iostream>
#include <string>
kstd::string_view put(kstd::string_view args, crank_context& ctx)
{
args = skip_whitespace(args);
auto key = extract_token(args);
auto value = skip_linearspace(kstd::string_view(args.begin()+key.size(),args.end()));
for(auto c : args)
std::cout<<c;
return ctx.store(key,value);
}
int main()
{
const char* putstext = "puts";
std::string get="";
crank_context ctx;
ctx.add_native(kstd::string_view((char*)putstext,4), put);
std::cout<<"> ";
while((std::getline(std::cin,get)).good())
{
auto ret = ctx.eval(kstd::string_view(get.data(), get.size()));
std::cout<<"&> ";
for(auto c : ret)
std::cout<<c;
std::cout<<std::endl<<"> ";
}
}
/*
TEST_CASE("crank")
{
crank_context ctx;
static const char* setter_code = "set sample \"Hello world\"";
kstd::string_view setter_c{(char*)setter_code, 24};
ctx.eval_no_copy(setter_c);
static const char* getter_code = "$sample";
kstd::string_view getter_c{(char*)getter_code, 7};
ctx.eval_no_copy(getter_c);
}*/