You can include yours into (n)mosh like these:
0) implement your C++ function in main.cpp or another place
1) wrap your function in mosh CProcedure interface
For example, see src/FFIProcedures.cpp internalFfiFreeEx which wraps
stdc free() function:
Object scheme::internalFfiFreeEx(VM* theVM, int argc, const Object*
argv)
{
DeclareProcedureName("free");
checkArgumentLength(1);
argumentAsPointer(0, p); // check if first argument is FFI pointer
and bind it to variable p
free((void*)p->pointer()); // actual function call.
return Object::Undef;
}
You can use argument checking macro declared in src/ProcedureMacro.h .
2) Get CProcedure object from your function and register it to mosh VM
Pass your function to Object::makeCProcedure() and register it
using setValueString(). You should do that in main.cpp, just before
activateR6RSMode()
see src/main.cpp :
theVM->setValueString(UC("%get-stack-trace-
obj"),Object::makeCProcedure(internalGetStackTraceObj));
this registers C++function internalGetStackTraceObj as scheme
procedure %get-stack-trace-obj.
3) Call it from scheme
Use symbol-value procedure from (mosh) library.
(import (mosh)) ;; import symbol-value from (mosh)
(define %get-stack-trace-obj (symbol-value '%get-stack-trace-obj))
(%get-stack-trace-obj)
Note that larceny-like (import (primitives %get-stack-trace-obj)) form
is not available on
psyntax based mosh.
These are totally undocumented...