Author Topic: Chipmonkey Lua 0.2  (Read 4591 times)

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Chipmonkey Lua 0.2
« on: April 14, 2013, 01:38:51 PM »
Chipmonkey is an interactive Lua interpreter in the style of the good old days of BASIC. This was actually inspired by the classic Chipmunk BASIC by David Gillespie. I played around a bit but stumbled soon upon ome problems: since it uses inline 32 bit ASM it wasn't possible to compile for 64 bit Linux systems. And because my main working OS is a 64 bit Kubuntu that was a no go. So one day I thought, why not taking Lua for he task? The only thing which was a bit tricky to implement is the interactive mode because I have to check the input before executing if there's a for, while or repeat loop or an if statement. But, well, here it is: Chipmonkey 0.2 (see attached screenshots).

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: Chipmonkey Lua 0.2
« Reply #1 on: April 14, 2013, 08:32:32 PM »
Okay, I attached the Windows version so you can test it. Bear in mind that the edit mode is very rudimentary and the main (and fun) part is the interactive mode. Of course you can still edit the files with any text editor.
If you want to load an example do this:
Code: [Select]
chdir "examples"
load "colourdots.lua"
run()
You can examine the active directory with
Code: [Select]
files "*"to list all files or
Code: [Select]
files "*.lua"to list all Lua files.
Now have some fun with that. It reminds me on the old good old days of computing.

EDIT: If you don't know the 256 colour palette anymore, have a look at the attached image. (Colour values from 0-255)
That's the program for drawing the palette:
Code: [Select]
graphic (1)
i=0
for y=0,480,30 do
for x=0,640,40 do
color (i)
fillrectangle (x,y,x+40,y+30)
i=i+1
end
end
inkey()
graphic (0)

Tomaaz

  • Guest
Re: Chipmonkey Lua 0.2
« Reply #2 on: April 15, 2013, 12:51:16 AM »
I don't know... I like Chipmonkey BASIC more, because Chipmonkey Lua looks like a poor version of EGSL (both are based on Lua and have additional features implemented). Chipmonkey BASIC is more old-school, has line numbers and a real BASIC syntax. If I want/need to write something in Lua I'd rather use EGSL or pure Lua interpreter.

Tomaaz

  • Guest
Re: Chipmonkey Lua 0.2
« Reply #3 on: April 15, 2013, 01:07:45 AM »
I tried it under Wine on Linux and it works without any problems and quite fast. Do you remember this topic: http://forum.basicprogramming.org/index.php/topic,2222.0.html? Here is my Lua version:

Code: [Select]
czas = (os.time())

plik = io.open("Bible.txt","r")
tekst = plik:read("*all")
io.close(plik)

zawartosc = string.lower(tekst)
wszystkie = {}
unikalne = {}
posortowane ={}
ilosc = 0

for x in string.gmatch(zawartosc, "%a+") do
if string.len(x) ~= 1 or x == "a" or x == "i"  then
ilosc = ilosc + 1
wszystkie[ilosc] = x
end
end

ilosc = 0
for x = 1, #wszystkie do
if not unikalne[wszystkie[x]] then
unikalne[wszystkie[x]] = 1
ilosc = ilosc + 1
else
unikalne[wszystkie[x]] = unikalne[wszystkie[x]] + 1
end
end

for x, y in pairs(unikalne) do
posortowane[#posortowane + 1] = y
end

table.sort(posortowane)

plik = io.open("words.txt", "w")
plik:write("All words: ", #wszystkie, "\n")
plik:write("Unique words: ", ilosc, "\n\n")
for x = #posortowane, 1, -1 do
for a, b in pairs(unikalne) do
if b == posortowane[x] then
plik:write(a, " - ", b, "\n")
unikalne[a] = nil
break
end
end
end
io.close(plik)

io.write("Done in ", os.time() - czas, " sec.\n" )

On my laptop it takes 14 sec. to complete the task. The source code and a file with a result are attached.
« Last Edit: April 15, 2013, 01:10:36 AM by Tomaaz »

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: Chipmonkey Lua 0.2
« Reply #4 on: May 27, 2013, 09:07:25 PM »
Some news abot this project. I think the screenshot will tell it all ...  ::)

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: Chipmonkey Lua 0.2
« Reply #5 on: May 29, 2013, 09:12:32 AM »
Okay, I've got a whole bunch of keywords implemented so far ...
INPUT, PRINT, CLS, LIST, RUN, NEW, CLEAR, EDIT, DATE$, TIME$, BYE, LEFT$, RIGHT$, MID$, INT, LEN, RND, COLOR, SLEEP, LOAD, CHDIR, SAVE, BACKGROUND, GRAPHIC, FILES, TEXTSIZE, DRAWTEXT, CIRCLE, FILLCIRCLE, RECTANGLE, FILLRECTANGLE, LINE, PSET, IF...THEN, ELSEIF, ELSE, ENDIF, REPEAT, LOOP, WEND, WHILE, UNTIL, FOR...TO, NEXT, STEP

Next I want to implement arrays.

See screenshot for an example. The BASIC program is already converted (automatically) to Lua.
« Last Edit: May 29, 2013, 09:31:07 AM by Cybermonkey »