Hi, TL;DR Check out how runresult does it: https://github.com/NetLogo/NetLogo/blob/hexy/netlogo-gui/src/main/prim/etc/_runresult.scala#L18-L23 (Scala code, but translating to Java shouldn’t be too bad).
You’ll need to get an org.nlogo.nvm.Context from your org.nlogo.api.Context. You can do that with something like: ((org.nlogo.nvm.ExtensionContext) context).nvmContext. Long version: I want it to be able to parse a String and interpret it as a NetLogo object. For parsing simple NetLogo literals, you can use workspace.readFromString. This will cover string, number, and list literals (that is they use square brackets rather than the list reporter), as well as nobody. This will be much faster than actually evaluating it as NetLogo code, since it doesn’t have to invoke the full NetLogo compiler or engine. However, it won’t give you anonymous procedures. For that, you will need something like workspace.report (which is preferable to App.app.report). Unfortunately, as you found: every time I use App.app().report, NetLogo freezes, and the same happens with App.app().command. Is there something I’m doing wrong, is it a bug in NetLogo, or do I need to write my own parser? These procedures are part of the NetLogo Controlling API, which is for other Java programs to be able to use NetLogo like a library. The upshot of this is that those methods are designed to be called from somewhere besides NetLogo’s JobThread (which is where all NetLogo compiled code gets executed). The downside is that these then don’t work from the JobThread (which is where your extension code is running): they submit a new job to the JobThread and then sit there waiting for it to finish, but the job never ends up even starting, since the caller is using the JobThread. Honestly, these methods should probably detect whether you’re on the JobThread or not. Anyway, to actually do it, you need to compile the code to a Procedure, create an Activation for that Procedure, and then submit it to the current Context to be run. See the above link to _runresult‘s code. However, this only works for reporters. For commands, it’s a little trickier because you have to actually mess around with the instruction pointer and, honestly, I don’t know how to get the instruction pointer for the next command from an extension (that’s what the next is in the _run code: https://github.com/NetLogo/NetLogo/blob/hexy/netlogo-gui/src/main/prim/etc/_run.scala#L21). You might look at AnonymousCommand for how to run a compiled Procedure without caring about instructions pointers: https://github.com/NetLogo/NetLogo/blob/hexy/netlogo-core/src/main/nvm/AnonymousProcedure.scala#L163-L175. Whenever I’ve needed to do stuff like this, it’s always been pretty context dependent, so not sure of a good generalized method. Anyway, hope that helps! Bryan On Wed, Jan 1, 2020 at 4:57 AM TechnoRazor <therealtechnora...@gmail.com> wrote: > I'm making an extension for NetLogo, and for part of it I want it to be > able to parse a String and interpret it as a NetLogo object. For example, > the string "true" gets parsed as the boolean true, "15" gets parsed as the > double 15, "[1 2 3]" gets parsed as the LogoList [1 2 3], "[-> print 5 + > 5]" gets parsed as an anonymous command, etc. > I thought I could simply do App.app().report(myInputString) in order to > parse it, but every time I use App.app().report, NetLogo freezes, and the > same happens with App.app().command. Is there something I'm doing wrong, is > it a bug in NetLogo, or do I need to write my own parser? Thanks in advance. > > TL;DR What is the Java equivalent of "runresult"? > > -- > You received this message because you are subscribed to the Google Groups > "netlogo-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to netlogo-devel+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/netlogo-devel/0469b708-7fd3-4bfc-a308-66dbf0537d87%40googlegroups.com > <https://groups.google.com/d/msgid/netlogo-devel/0469b708-7fd3-4bfc-a308-66dbf0537d87%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Bryan Head PhD Candidate, Computer Science Center for Connected Learning and Computer-Based Modeling Department of Electrical Engineering and Computer Science Northwestern University -- You received this message because you are subscribed to the Google Groups "netlogo-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-devel/CAFM%3DnTdyy%2BbDExjSZVygwADCL%2ByeQJyS96LFzP8KpY7fHOLmJA%40mail.gmail.com.