Hi all. I am attempting to store the Wikimedia Lua Modules as Classes in my image. The idea being that when the Parser encounters a Module #invoke I can hand it off to the appropriate class and have it invoke Lua and return content to me. I have extracted the Wikimedia Modules to a postgres table named 'modules' and I am hitting that table and iterating over it to dynamically create the classes I need. The code is a modified version of what I used to scrape the Squeak Wiki.
Works fine until
Here's why:
The Method compilation fails. Should I even attempt to escape this thing? Remember, I am going to have to do an OSProcess lua call to run this stuff. I suppose I could just store the PGRow in the class, but that feels weird. Thanks in advance. |
Hi, Without having thought it through that much or having understood the whole context: 1. Can't you just replace each ' in your Lua text by '' (two single quotes) before compiling the Smalltalk method string? It escapes the single quotes in the string. 2. Do you really need to create a new Smalltalk class for each row? (That feels weird to me.) Why not create an instance of something for each row and store the collection of all the instances in a well-known place? These instances could have an instance variable to hold the plain Lua code string. 3. If you need Smalltalk classes, you could as well declare a class instance variable and store the unmodified Lua code string there. YourClass class instanceVariableNames: 'lua'. lua: aString "class side" lua := aString. lua ^ lua lua "instance side" ^ self class lua YourClass lua: (row at: 3). Kind regards, Jakob Am Mi., 21. Aug. 2019 um 22:49 Uhr schrieb gettimothy via Squeak-dev <[hidden email]>:
|
(including the list in addresses again) Am Mi., 21. Aug. 2019 um 23:53 Uhr schrieb gettimothy <[hidden email]>:
methodTemplateLua := 'lua ^ ''{1}'''. methodSourceLua := methodTemplateLua format: {lua copyReplaceTokens: '''' "four single quotes" with: '''''' "six single quotes"}. Or for more comfortable reading: lua copyReplaceTokens: (String with: $') with: (String with: $' with: $') Still, I would avoid tinkering with the code and go with the (class) instance variable approach if possible. |
Hi, there. #printString on String does the trick: methodTemplateLua := 'lua ^ {1}'. methodSourceLua := methodTemplateLua format: { lua printString }. Best, Marcel
|
Free forum by Nabble | Edit this page |