Is there a way to run arbitrary swift code from inside a compiled swift program? Similar to JSCore?
Other than shelling out to swift
or swiftc
, no, not really. You could try looking into how lldb's expression evaluation works, but I wouldn't count on it being suitable for your purposes.
1 Like
As David pointed out, you can only do this through swift
or swiftc
.
I implemented this in an open source CLI tool I built recently. Here's a snippet of the Swift file runner.
I learned all about this method through this detailed post.