Custom DDLs

  • Dlls can be created simply too, and in YS you can then use the function includeDll to load it. The following line is defined in YOUScript.h
#define YS_MODULE(fn) void fn(Instance* ysi)
#include <YOUScript.h>
  • using namespace YOUScript;
#define DLL_EXPORT extern "C" __declspec(dllexport)
DLL_EXPORT YS_MODULE(YOUScriptStart){
Variable* msg = Converter::ToVariable("The dll got loaded");
  • Vars get registered in the garbage collector when they enter the YOUScript empire so we don’t need to do that ourselfs
List<Variable*> args;
args.Add(msg);
ysi->GetVar("print")->GetFunction()->Run(&args);
}
DLL_EXPORT YS_MODULE(YOUScriptShutdown){
  • Ysi gets unloaded in the following order
1> calls shutdown on all dlls, because this is the first step, you can still call functions and do other stuff

    2> removes scopes (every time you use DoString/DoFile/DoCode you create a local scope)

    3> removes globals

    4> calls the GC to clean everything up

    5> deletes and removes all remaining pointers
Variable* msg = Converter::ToVariable("The ysi instance is being destroyed");
ysi->GC.RegisterVariable(msg);
List<Variable*> args;
args.Add(msg);
ysi->GetVar("print")->GetFunction()->Run(&args);
}