mirror of
https://onedev.site.tesses.net/crosslang
synced 2026-02-09 01:25:45 +00:00
Add helper for tytd and fix arguments
This commit is contained in:
@@ -2,6 +2,50 @@
|
|||||||
|
|
||||||
namespace Tesses::CrossLang
|
namespace Tesses::CrossLang
|
||||||
{
|
{
|
||||||
|
TObject Dictionary_FindByKey(GCList& ls, std::vector<TObject> args)
|
||||||
|
{
|
||||||
|
TList* dest = TList::Create(ls);
|
||||||
|
ls.GetGC()->BarrierBegin();
|
||||||
|
std::string key;
|
||||||
|
if(GetArgument(args,1,key))
|
||||||
|
{
|
||||||
|
|
||||||
|
std::function<void(TObject)> crawl;
|
||||||
|
crawl = [&](TObject o) -> void {
|
||||||
|
TDictionary* dict;
|
||||||
|
TList* list;
|
||||||
|
TAssociativeArray* aa;
|
||||||
|
if(GetObjectHeap(o,aa))
|
||||||
|
{
|
||||||
|
std::string k0;
|
||||||
|
for(auto& item : aa->items)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(GetObject(item.first,k0) && k0 == key) dest->Add(item.second);
|
||||||
|
crawl(item.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(GetObjectHeap(o,dict))
|
||||||
|
{
|
||||||
|
for(auto& item : dict->items)
|
||||||
|
{
|
||||||
|
if(item.first == key) dest->Add(item.second);
|
||||||
|
crawl(item.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(GetObjectHeap(o,list))
|
||||||
|
{
|
||||||
|
for(auto& item : list->items)
|
||||||
|
{
|
||||||
|
crawl(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
crawl(args[0]);
|
||||||
|
}
|
||||||
|
ls.GetGC()->BarrierEnd();
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
TObject Dictionary_Items(GCList& ls, std::vector<TObject> args)
|
TObject Dictionary_Items(GCList& ls, std::vector<TObject> args)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -94,7 +138,7 @@ namespace Tesses::CrossLang
|
|||||||
|
|
||||||
|
|
||||||
gc->BarrierBegin();
|
gc->BarrierBegin();
|
||||||
|
dict->DeclareFunction(gc, "FindByKey","Scan object recursively, return list of items with key",{"obj","key"}, Dictionary_FindByKey);
|
||||||
dict->DeclareFunction(gc, "Items","Get Dictionary Item Enumerable, for the each(item : Dictionary.Items(myDict)){item.Key; item.Value;}",{"dictionary"},Dictionary_Items);
|
dict->DeclareFunction(gc, "Items","Get Dictionary Item Enumerable, for the each(item : Dictionary.Items(myDict)){item.Key; item.Value;}",{"dictionary"},Dictionary_Items);
|
||||||
dict->DeclareFunction(gc, "SetField","Set a field in dictionary",{"dict","key","value"},Dictionary_SetField);
|
dict->DeclareFunction(gc, "SetField","Set a field in dictionary",{"dict","key","value"},Dictionary_SetField);
|
||||||
dict->DeclareFunction(gc, "GetField","Get a field in dictionary",{"dict","key"},Dictionary_GetField);
|
dict->DeclareFunction(gc, "GetField","Get a field in dictionary",{"dict","key"},Dictionary_GetField);
|
||||||
|
|||||||
@@ -7273,7 +7273,8 @@ namespace Tesses::CrossLang {
|
|||||||
{
|
{
|
||||||
cse->env->DeclareVariable(trimStart(closure->closure->args[i]), args[i]);
|
cse->env->DeclareVariable(trimStart(closure->closure->args[i]), args[i]);
|
||||||
}
|
}
|
||||||
if(i == closure->closure->args.size()-1)
|
std::string back = closure->closure->args.empty() ? std::string() : closure->closure->args.back();
|
||||||
|
if(i == closure->closure->args.size()-1 && back.size() > 2 && back[0] == '$' && back[1] == '$')
|
||||||
{
|
{
|
||||||
auto argName = closure->closure->args[i];
|
auto argName = closure->closure->args[i];
|
||||||
auto lsArgs = TList::Create(ls);
|
auto lsArgs = TList::Create(ls);
|
||||||
|
|||||||
Reference in New Issue
Block a user