I got it partially working but there are some problemsLizard - Script language for symbolic calculations, arbitrary large and precise numbers and more
1: no matter what I tried, I get a warning of passing a different pointer on 2nd argument to Kernel_BindCallback, however at least the error function seems to work
2: why do I get a crash if at the end I deallocate the wstrings?
3: if I at the input prompt I enter "Calculate(Pi)" I get an error but if I set the input string to "Calculate(Pi)" in the code and then compile/run then no problem, also no problem if in the code I concatenate "Calculate("+input_+")"
here's my test code
Code: Select all
#inclib "Lizard"
Enum Event
Event_Print = 1
Event_Message
Event_Error
End Enum
extern "Windows"
declare function Kernel_BindCallback(byval as integer, byval CallbackAddress as sub ptr) as integer
' Kernel_DuplicateExpression
declare function Kernel_EvaluateExpression(byval p as any ptr) as any ptr
' Kernel_FreeExpression
' Kernel_GetValue
declare function Kernel_Initialize(byval p as wstring ptr) as integer
declare function Kernel_InputExpression(byval p as wstring ptr) as any ptr
declare function Kernel_OutputExpression(byval p as any ptr) as wstring ptr
' Kernel_Reset
' Kernel_SetValue
declare function Kernel_Terminate() as integer
declare function Kernel_Version() as wstring ptr
sub Callback_Print(byval Text as wstring ptr)
Print *Text
End sub
sub Callback_Message(byval Text as wstring ptr, byval SymbolName as wstring ptr, byval ErrorName as wstring ptr)
Print " ";*SymbolName;".";*ErrorName;" ";
Print *Text
End sub
sub Callback_Error(byval Text as wstring ptr)
Print " Syntax error: \";*Text
End sub
end extern
dim as double tm
dim as wstring ptr input_=callocate(1024), output_=callocate(1024*1024)
dim as any ptr pin, pout 'pin=allocate(1024*1024), pout=allocate(1024*1024)
if Kernel_Initialize(0) then
Kernel_BindCallback(Event_Error, @Callback_Error())
Kernel_BindCallback(Event_Message, @Callback_Message())
Kernel_BindCallback(Event_Print, @Callback_Print())
else
print "unable to initialize"
sleep
end
end if
*input_=" "
while *input_<>""
input "-> ",*input_
if *input_="" then exit while
'*input_="Calculate("+(*input_)+", 50)"
tm=timer
pin=Kernel_InputExpression(input_)
pout=Kernel_EvaluateExpression(pin)
output_=Kernel_OutputExpression(pout)
print *output_
tm=timer-tm
print tm
wend
'w=Kernel_Version() 'crash
'print *w
Kernel_Terminate()
'deallocate(w) 'crash
'deallocate(pin)
'deallocate(pout)