[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

[m8n] fengari loader

Uploaded Image: UnderConstructionLine.gif


| repo ext boot image st
  l lua lauxlib
  jsString lString tojs
|
repo := 'http://u8.smalltalking.net/profile/aleReimondo/m8n/'.
ext := '.lua.txt'. "Note that we use here .lua.txt extension while our U8 service is not configured to serve .lua files. It will change soon, so you will not need the .txt extension to get the lua contents"

boot  := (repo ,#boot ,ext) fileContents.

lString	:= #{fengari} basicAt: #to_luastring.
jsString:= #{fengari} basicAt: #to_jsstring.
tojs	:= #{fengari}[#interop] basicAt: #tojs.
lua 	:= #{fengari} basicAt: #lua.
l   	:= #{fengari} basicAt: #L.	"JS@>l"
lauxlib	:= #{fengari} basicAt: #lauxlib."JS@>lauxlib"

st := lauxlib
	#luaL_loadbuffer: l
	source: (lString value: boot)
	size: nil handle
	chunkname: (lString value: #boot).
st = lua[#LUA_ERRSYNTAX] ifTrue: [
	self error: 'Syntax error - ' ,(jsString value: l value: -1)
].
lua #lua_setglobal: l name: (lString value: #smalltalk).

image := (repo ,'s8.image' ,ext) fileContents.
(#{fengari} #load: image as: #image) value.