Accessing globals/defines from MCompile
Posted: Thu Dec 01, 2022 11:21 am
Hi,
Is there a way to compile a codeblock from a string at runtime that can access globals and defines?
I've tried MCompile and creating an instance of XSharp.Runtime.MacroCompiler but can't seem to get it to work.
Thanks,
Fergus
Is there a way to compile a codeblock from a string at runtime that can access globals and defines?
I've tried MCompile and creating an instance of XSharp.Runtime.MacroCompiler but can't seem to get it to work.
Thanks,
Fergus
Code: Select all
GLOBAL cGlobal := "Global" AS STRING
DEFINE cDefine := "Define" AS STRING
FUNCTION Start() AS VOID STRICT
LOCAL compileTimeCodeblock AS CODEBLOCK
LOCAL cbStr AS STRING
LOCAL runTimeCodeblock AS CODEBLOCK
compileTimeCodeblock := {|| cGlobal }
Console.WriteLine(Eval(compileTimeCodeblock)) //Global
cbStr := "{|| GetGlobal() }"
runTimeCodeblock := MCompile(cbStr)
Console.WriteLine(Eval(runTimeCodeblock)) //Global
cbStr := "{|| cGlobal }"
runTimeCodeblock := MCompile(cbStr)
Console.WriteLine(Eval(runTimeCodeblock)) //Error - Variable does not exist
Console.ReadKey()
FUNCTION GetGlobal() AS STRING
RETURN cGlobal