[squeak-dev] Problem storing Lua code in dynamically created class side method.

gettimothy gettimothy at zoho.com
Wed Aug 21 20:49:31 UTC 2019


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.





scrapeModulesToNewClass

|rows |

      rows := ((WikitextParserConnectionPool default executeQuery: 'select page_id, page_title, old_text from modules limit 2') at:1) rows.



rows do: [:each | |pageid pagetitle oldtext lua  methodTemplatePageId methodTemplatePageTitle methodTemplateLua methodSourcePageId methodSourcePageTitle methodSourceLua newclassname|



pageid := each at:1.

pagetitle := each at:2.

oldtext := each at:3.

lua := oldtext .    "I have been attempting String shenanigans here in attempts to get this to work"

lua inspect.

methodTemplatePageId := 'pageId ^', $', '{1}' ,$'. 

methodTemplatePageTitle := 'pageTitle ^', $', '{1}' ,$'. 

methodTemplateLua := 'lua ^', $', '{1}' ,$'. 

methodSourcePageId := methodTemplatePageId format:{pageid}.

methodSourcePageTitle := methodTemplatePageTitle format:{pagetitle}.

methodSourceLua := methodTemplateLua format:{lua}.



newclassname := ('WikitextModule', pageid asString) asSymbol.

WikitextParserModule subclass: newclassname

          instanceVariableNames: ''

          classVariableNames: ''

          poolDictionaries: ''

          category: 'WikitextParser-Modules'.



       (Smalltalk at: newclassname) compile: methodSourcePageId.

       (Smalltalk at: newclassname) compile: methodSourcePageTitle.

       (Smalltalk at: newclassname) compile: methodSourceLua.



       "Transcript show: newclassname; cr."

]




Works fine until 


(Smalltalk at: newclassname) compile: methodSourceLua.





Here's why:



lua ^'-- This module provides easy processing of arguments passed to Scribunto from

-- #invoke. It is intended for use by other Lua modules, and should not be

-- called from #invoke directly.



local libraryUtil = require('libraryUtil    End of block expected ->')

local checkType = libraryUtil.checkType



..........



end



return arguments'





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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190821/366e4715/attachment-0001.html>


More information about the Squeak-dev mailing list