forked from PuqiAR/Fig-TreeWalker
[Feat] 为List增加push函数
This commit is contained in:
@@ -81,7 +81,8 @@ namespace Fig
|
|||||||
{ValueType::Function, {}},
|
{ValueType::Function, {}},
|
||||||
{ValueType::StructType, {}},
|
{ValueType::StructType, {}},
|
||||||
{ValueType::StructInstance, {}},
|
{ValueType::StructInstance, {}},
|
||||||
{ValueType::List, {{u8"length", [this](std::vector<ObjectPtr> args) -> ObjectPtr {
|
{ValueType::List, {
|
||||||
|
{u8"length", [this](std::vector<ObjectPtr> args) -> ObjectPtr {
|
||||||
if (args.size() != 0)
|
if (args.size() != 0)
|
||||||
throw RuntimeError(FString(
|
throw RuntimeError(FString(
|
||||||
std::format("`length` expects 0 arguments, {} got", args.size())));
|
std::format("`length` expects 0 arguments, {} got", args.size())));
|
||||||
@@ -101,7 +102,17 @@ namespace Fig
|
|||||||
if (i >= list.size())
|
if (i >= list.size())
|
||||||
return Object::getNullInstance();
|
return Object::getNullInstance();
|
||||||
return list[i];
|
return list[i];
|
||||||
}}}},
|
}},
|
||||||
|
{u8"push", [this](std::vector<ObjectPtr> args) -> ObjectPtr {
|
||||||
|
if (args.size() != 1)
|
||||||
|
throw RuntimeError(FString(
|
||||||
|
std::format("`push` expects 1 arguments, {} got", args.size())));
|
||||||
|
ObjectPtr arg = args[0];
|
||||||
|
List &list = as<List>();
|
||||||
|
list.push_back(arg);
|
||||||
|
return Object::getNullInstance();
|
||||||
|
}},
|
||||||
|
}},
|
||||||
{ValueType::Map, {
|
{ValueType::Map, {
|
||||||
{u8"get", [this](std::vector<ObjectPtr> args) -> ObjectPtr {
|
{u8"get", [this](std::vector<ObjectPtr> args) -> ObjectPtr {
|
||||||
if (args.size() != 1)
|
if (args.size() != 1)
|
||||||
@@ -135,7 +146,7 @@ namespace Fig
|
|||||||
{ValueType::Function, {}},
|
{ValueType::Function, {}},
|
||||||
{ValueType::StructType, {}},
|
{ValueType::StructType, {}},
|
||||||
{ValueType::StructInstance, {}},
|
{ValueType::StructInstance, {}},
|
||||||
{ValueType::List, {{u8"length", 0}, {u8"get", 1}}},
|
{ValueType::List, {{u8"length", 0}, {u8"get", 1}, {u8"push", 1}}},
|
||||||
{ValueType::Map, {
|
{ValueType::Map, {
|
||||||
{u8"get", 1},
|
{u8"get", 1},
|
||||||
{u8"contains", 1},
|
{u8"contains", 1},
|
||||||
|
|||||||
Reference in New Issue
Block a user