mirror of
https://onedev.site.tesses.net/crosslang/crosslang-website
synced 2026-02-08 17:15:46 +00:00
Add types
This commit is contained in:
100
content/runtime/getargument.md
Normal file
100
content/runtime/getargument.md
Normal file
@@ -0,0 +1,100 @@
|
||||
+++
|
||||
title = 'Get Argument Helpers'
|
||||
date = 2025-10-22T20:31:08-05:00
|
||||
+++
|
||||
|
||||
## GetArgument
|
||||
```c++
|
||||
/*
|
||||
Gets a non heap object from arguments
|
||||
Returns true if argument is of type T and index < args.size()
|
||||
obj is set to the args[index] if it returns true
|
||||
*/
|
||||
template<typename T>
|
||||
bool GetArgument(std::vector<TObject>& args, size_t index, T& obj);
|
||||
```
|
||||
|
||||
```c++
|
||||
//Heres it in code
|
||||
static TObject My_Custom(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
int64_t n;
|
||||
if(GetArgument(args,0,n))
|
||||
{
|
||||
return n + 5;
|
||||
}
|
||||
return (int64_t)5;
|
||||
}
|
||||
```
|
||||
## GetArgumentHeap
|
||||
|
||||
```c++
|
||||
/*
|
||||
Gets a heap object from arguments
|
||||
Returns true if argument is of type T and index < args.size()
|
||||
obj is set to the args[index] if it returns true
|
||||
*/
|
||||
template<typename T>
|
||||
bool GetArgumentHeap(std::vector<TObject>& args, size_t index, T& obj);
|
||||
```
|
||||
|
||||
```c++
|
||||
//Heres it in code
|
||||
static TObject My_Custom(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
TList* list;
|
||||
if(GetArgumentHeap(args,0,list))
|
||||
{
|
||||
list->Add((std::string)"Hello, world");
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
```c++
|
||||
|
||||
/*
|
||||
Gets a non heap object from src
|
||||
Returns true if argument is of type T
|
||||
obj is set to src if it returns true
|
||||
*/
|
||||
template<typename T>
|
||||
bool GetObject(TObject& src, T& obj);
|
||||
```
|
||||
|
||||
```c++
|
||||
//Heres it in code
|
||||
static TObject My_Custom(GCList& ls, std::vector<TObject> args)
|
||||
{
|
||||
int64_t n;
|
||||
TDictionary* dict;
|
||||
if(GetArgumentHeap(args,0,dict))
|
||||
{
|
||||
auto item = dict->GetValue("MyItem");
|
||||
if(GetObject(item, n))
|
||||
return n + 5;
|
||||
}
|
||||
return (int64_t)5;
|
||||
}
|
||||
```
|
||||
## GetArgumentHeap
|
||||
|
||||
```c++
|
||||
/*
|
||||
Gets a heap object from src
|
||||
Returns true if argument is of type T
|
||||
obj is set to src if it returns true
|
||||
*/
|
||||
template<typename T>
|
||||
bool GetObjectHeap(TObject& src, T& obj);
|
||||
```
|
||||
|
||||
```c++
|
||||
//Heres it in code
|
||||
static void My_Custom(TObject something)
|
||||
{
|
||||
TList* ls;
|
||||
if(GetObjectHeap(something, ls))
|
||||
{
|
||||
ls->Add((int64_t)42);
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user