<div dir="ltr">Hi,<div><br></div><div>Without having thought it through that much or having understood the whole context:</div><div><br></div><div>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.</div><div>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.</div><div>3. If you need Smalltalk classes, you could as well declare a class instance variable and store the unmodified Lua code string there.</div><div><br></div><div>    YourClass class</div><div>       instanceVariableNames: 'lua'.</div><div>    </div><div>    lua: aString "class side"</div><div>       lua := aString.</div><div>    </div><div>    lua</div><div>       ^ lua</div><div>    </div><div>    lua "instance side"</div><div>       ^ self class lua</div><div>    </div><div>    YourClass lua: (row at: 3).</div><div><br></div><div>Kind regards,</div><div>Jakob</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Mi., 21. Aug. 2019 um 22:49 Uhr schrieb gettimothy via Squeak-dev <<a href="mailto:squeak-dev@lists.squeakfoundation.org">squeak-dev@lists.squeakfoundation.org</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u><div><div style="font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10pt"><div>Hi all.<br></div><div><br></div><div>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.<br></div><div><br></div><div>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.<br></div><div>The code is a modified version of what I used to scrape the Squeak Wiki.<br></div><div><br></div><div><br></div><div><blockquote style="border:1px solid rgb(204,204,204);padding:7px;background-color:rgb(245,245,245)"><div>scrapeModulesToNewClass<br></div><div>|rows |<br></div><div>      rows := ((WikitextParserConnectionPool default executeQuery: 'select page_id, page_title, old_text from modules limit 2') at:1) rows.<br></div><div><br></div><div>rows do: [:each | |pageid pagetitle oldtext lua  methodTemplatePageId methodTemplatePageTitle methodTemplateLua methodSourcePageId methodSourcePageTitle methodSourceLua newclassname|<br></div><div><br></div><div>pageid := each at:1.<br></div><div>pagetitle := each at:2.<br></div><div>oldtext := each at:3.<br></div><div>lua := oldtext .    "I have been attempting String shenanigans here in attempts to get this to work"<br></div><div>lua inspect.<br></div><div>methodTemplatePageId := 'pageId ^', $', '{1}' ,$'. <br></div><div>methodTemplatePageTitle := 'pageTitle ^', $', '{1}' ,$'. <br></div><div>methodTemplateLua := 'lua ^', $', '{1}' ,$'. <br></div><div>methodSourcePageId := methodTemplatePageId format:{pageid}.<br></div><div>methodSourcePageTitle := methodTemplatePageTitle format:{pagetitle}.<br></div><div>methodSourceLua := methodTemplateLua format:{lua}.<br></div><div><br></div><div>newclassname := ('WikitextModule', pageid asString) asSymbol.<br></div><div>WikitextParserModule subclass: newclassname<br></div><div>          instanceVariableNames: ''<br></div><div>          classVariableNames: ''<br></div><div>          poolDictionaries: ''<br></div><div>          category: 'WikitextParser-Modules'.<br></div><div><br></div><div>       (Smalltalk at: newclassname) compile: methodSourcePageId.<br></div><div>       (Smalltalk at: newclassname) compile: methodSourcePageTitle.<br></div><div>       (Smalltalk at: newclassname) compile: methodSourceLua.<br></div><div><br></div><div>       "Transcript show: newclassname; cr."<br></div><div>]<br></div></blockquote><div><br></div><div>Works fine until <br></div></div><blockquote style="border:1px solid rgb(204,204,204);padding:7px;background-color:rgb(245,245,245)"><div>(Smalltalk at: newclassname) compile: methodSourceLua.<br></div></blockquote><div><br></div><div>Here's why:<br></div><div><br></div><div><blockquote style="border:1px solid rgb(204,204,204);padding:7px;background-color:rgb(245,245,245)"><div>lua ^'-- This module provides easy processing of arguments passed to Scribunto from<br></div><div>-- #invoke. It is intended for use by other Lua modules, and should not be<br></div><div>-- called from #invoke directly.<br></div><div><br></div><div>local libraryUtil = require('libraryUtil    <b>End of block expected -</b>><b>'</b>)<br></div><div>local checkType = libraryUtil.checkType<br></div><div><br></div><div>..........<br></div><div><br></div><div>end<br></div><div><br></div><div>return arguments'<br></div></blockquote><div><br></div></div><div>The Method compilation fails.</div><div><br></div><div>Should I even attempt to escape this thing? <br></div><div><br></div><div>Remember, I am going to have to do an OSProcess lua call to run this stuff.<br></div><div><br></div><div>I suppose I could just store the PGRow in the class, but that feels weird.<br></div><div><br></div><div>Thanks in advance.</div><div><br></div></div><br></div><br>
</blockquote></div>