Functions

  • The following line is defined in YOUScript.h
#define YS_FUNCTION(fn) Variable* fn(Instance* ysi, ArgumentData* args)
  • Argumentdata class, here you can retrieve all the arguments in a function call. One thing that is important to remember is: When you’re handeling tables, or userdata types. args->ThisObject is the table/userdata so when writing userdata wrappers, you can retrieve your userdata with args->GetThisObjectData() be sure to typecheck it with args->CheckThisObject! when making wrappers, always typecheck!
YS_FUNCTION(SomeCppFunction){
  • Lets check if its a number the user is inputting, by using the following:
if (!args->CheckType(0, Variable::VariableType::Number, true)) return null;
  • You can return a new variable here, you can also return null.
return Converter::ToVariable(args->GetNumber(0) * 10);
  • And register it
ysi.RegisterFunction("somename", SomeCppFunction);
  • in YS:
print(somename(5)) should output 50