English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General > Coders. Releases

 
 
Thread Tools
Old 18 October 2014, 18:03   #1
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Lua interpreter with arbitrary precision math.

Here's a build of the Lua interpreter from Lua 5.2.3: lua.lha

Works with Kicstart 3.0+ and 68020+ (only tested with 68030). Compiled with SASC6.58, so might work with Kicstart 2+. Does NOT require an FPU, ixemul.library, etc. Only needs standard Workbench libraries. This build of Lua doesn't support loading dynamic libraries.

To use, simply unpack the archive anywhere you want, and start from Workbench. You can also run lua.exe from the CLI directly. When starting from the CLI, use lua.exe -l mapm to start the interpreter with the math library.

Example usage (type into the interpreter command line directly):

Code:
mapm.digits(100)
a=mapm.sqrt(12345)
b=mapm.sqrt(54321)
print(a*b)
c=mapm.number"1"
d=mapm.number"3"
e=c/d
print(e*d)
You can also use things like mapm.sin, mapm.cos, etc.

Currently there's no documentation, but you can get some pointers here:

mapm: http://www.tc.umn.edu/~ringx004/mapm-4.9.5a.tar.gz
lmapm: http://webserver2.tecgraf.puc-rio.br...2/lmapm.tar.gz

Mapm is the arbitrary precision floating point library. This contains documentation about the functions. Lmapm is the code that links mapm to lua. The file lmapm.c will show you which functions are available in the interpreter. Sorry, but it will have to do for now.

Last edited by Thorham; 20 October 2014 at 21:33.
Thorham is offline  
Old 20 October 2014, 17:37   #2
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
No one's interested in Lua here?
Thorham is offline  
Old 20 October 2014, 17:51   #3
tolkien
AmigaMan
 
tolkien's Avatar
 
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 760
I like LUA. I have the book Programming in lua. Like the concept but I dont use it.
I hope your work can be used by the talented coders we have around.
tolkien is offline  
Old 20 October 2014, 21:28   #4
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
No offense, but I have never heard of Lua until now (not surprising considering there's over 500+ programming languages - consult the official 'Hello World' collection).

I will probably give it a try sometime over the next few days - I'll need a break from trying to get the 4096 tile in Coagulus' game and from drawing new GFX for my own game.
Lonewolf10 is offline  
Old 20 October 2014, 21:37   #5
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by tolkien View Post
I hope your work can be used by the talented coders we have around.
The intention is only to use it as a programmable calculator, nothing fancy.

Quote:
Originally Posted by Lonewolf10 View Post
there's over 500+ programming languages
Thorham is offline  
Old 20 October 2014, 23:28   #6
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
I prefer Python, but Lua is probably slimmer and faster to run directly on the Amiga.

I've also built the Lua interpreter and compiler with SAS/C, but they give run-time errors for certain programs. My guess is that SAS/C isn't implementing the standard C library correctly, which Lua is entirely dependent on.
Leffmann is offline  
Old 20 October 2014, 23:45   #7
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by Leffmann View Post
I prefer Python, but Lua is probably slimmer and faster to run directly on the Amiga.
Probably a lot easier to build as well.

Quote:
Originally Posted by Leffmann View Post
I've also built the Lua interpreter and compiler with SAS/C, but they give run-time errors for certain programs. My guess is that SAS/C isn't implementing the standard C library correctly, which Lua is entirely dependent on.
I had that problem with things like print(0x1234567a). Just hangs. Fixed it by playing with the compiler options (I'll upload the fixed version later). SASC also shows lots of warnings when compiling Lua. Tried to do it with GCC (no warnings), but I can't seem to link the Lua interpreter with the mapm library properly without ixemul (both work fine without ixemul, combine them, and mapm doesn't work properly). Very annoying (probably something small as I'm a compiler n00b).
Thorham is offline  
Old 21 October 2014, 07:43   #8
jPV
Registered User
 
jPV's Avatar
 
Join Date: Feb 2008
Location: RNO
Posts: 1,006
I like Lua too. I did learn it recently, because there's a native implementation of Lua included in MorphOS by default, and it can be used to replace ARexx. I converted some of my ARexx scripts to Lua and also wrote some new ones. You can find them here if interested.

Lua is still missing something compared to ARexx, but OTOH it's more powerful in many other areas. Nevertheless I enjoy making scripts with both languages.
jPV is offline  
Old 21 October 2014, 19:49   #9
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
I've compiled lua with gcc and then run this

Code:
-- sieve.lua
-- the sieve of Eratosthenes programmed with coroutines
-- typical usage: lua -e N=500 sieve.lua | column

-- generate all the numbers from 2 to n
function gen (n)
  return coroutine.wrap(function ()
    for i=2,n do coroutine.yield(i) end
  end)
end

-- filter the numbers generated by `g', removing multiples of `p'
function filter (p, g)
  return coroutine.wrap(function ()
    for n in g do
      if n%p ~= 0 then coroutine.yield(n) end
    end
  end)
end

local start = os.clock()
c=0
N=N or 500		-- from command line
x = gen(N)		-- generate primes up to N
while 1 do
  local n = x()		-- pick a number until done
  if n == nil then break end
  --print(n)		-- must be a prime number
  c=c+1
  x = filter(n, x)	-- now remove its multiples
end
print(c)
print(string.format("elapsed time: %.2f\n", os.clock() - start))
I've run it with the gcc compiled exe and with the Sas compiled exe.
Here are the results:
Code:
3.Work:t/amath> lua.exe sieve.lua 
95
elapsed time: 4.34

3.Work:t/amath> lua.exe sieve.lua 
95
elapsed time: 4.33

3.Work:t/amath> luagcc sieve.lua 
95
elapsed time: 3.26

3.Work:t/amath> luagcc sieve.lua 
95
elapsed time: 3.26
Gcc (3.4.0), looks like, produced code almost 25% faster than SAS C!
Didn't expect that much.
alkis is offline  
Old 21 October 2014, 22:09   #10
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by alkis View Post
[/CODE]Gcc (3.4.0), looks like, produced code almost 25% faster than SAS C!
Didn't expect that much.
I get 2.15 on my A1200 with Blizzard 1230 IV using my own SASC compiled version. Compiled for 68020 with some options to fix a bug, and without optimizations.
Thorham is offline  
Old 21 October 2014, 22:52   #11
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by Thorham View Post
I get 2.15 on my A1200 with Blizzard 1230 IV using my own SASC compiled version. Compiled for 68020 with some options to fix a bug, and without optimizations.
I've put luagcc in the zone. If you could measure it please, I am curious!
alkis is offline  
Old 22 October 2014, 03:32   #12
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by alkis View Post
I've put luagcc in the zone. If you could measure it please, I am curious!
It crashes when I run the test script, but it somehow still completed the script the first time I tried, and I think it was 1.90 (crashed quickly afterwards).
Thorham is offline  
Old 22 October 2014, 09:12   #13
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Weird. I don't get crashes (emulated A1200). Maybe it overuses the stack. I think I was playing with 500k stack (was going for 50k but I typed one zero too many).
alkis is offline  
Old 22 October 2014, 18:29   #14
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by alkis View Post
Weird. I don't get crashes (emulated A1200). Maybe it overuses the stack. I think I was playing with 500k stack (was going for 50k but I typed one zero too many).
Yeah, tried with stack 1000000, and it works fine. Result for the test is 1.81.
Thorham is offline  
Old 09 August 2018, 19:36   #15
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
ok, gcc6 is GODLIKE

Code:
3.Work:t/amath> lua.exe sieve.lua
95
elapsed time: 5.31

3.Work:t/amath> luagcc sieve.lua
95
elapsed time: 4.64

3.Work:t/amath> /lua sieve.lua [gcc6 68000 version]
95
elapsed time: 3.48

3.Work:t/amath> /lua sieve.lua [gcc6 68020 version]
95
elapsed time: 3.34

3.Work:t/amath> /lua /for.lua [gcc6 68020 version]
5000050000
11.7 seconds
3.Work:t/amath> lua.exe /for.lua
5000050000
26.632 seconds
3.Work:t/amath> luagcc /for.lua 
5000050000
24.58 seconds
!!!! 11.7 down from gcc3.4.0's 24.58, down from 26.6 of SAS C !!!

Code for for.lua
Code:
s = os.clock()
sum = 0
for i=1,100000 do
        sum = sum + i
end
print(sum)
print(tostring(os.clock()-s) .. " seconds")
lua for 68000 and lua020 for 68020 in the linked zip

https://drive.google.com/open?id=1dg...SxkL-YLLzDbXQA
alkis is offline  
Old 10 August 2018, 10:37   #16
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by Thorham View Post
Yeah, tried with stack 1000000, and it works fine. Result for the test is 1.81.

1MB of stack to run an amiga program!? That's nuts!
hooverphonique is offline  
Old 10 August 2018, 13:46   #17
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,322
Huge stacks are common for programs coming from other platforms (understand : pc).
I've found that usually 300k is enough, though.
meynaf is offline  
Old 10 August 2018, 16:39   #18
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by hooverphonique View Post
1MB of stack to run an amiga program!? That's nuts!
It's an interpreter You can run all sort of things, with various levels of recursion and such.

For example the last version I linked runs happily the "for.lua" with 4k stack.
"sieve.lua" crashed with 50k stack, worked with 100k.
alkis is offline  
Old 24 August 2018, 09:32   #19
Krashan
Hardware Designer
 
Join Date: Aug 2018
Location: Bialystok/Poland
Age: 50
Posts: 178
Quote:
Originally Posted by Thorham View Post
This build of Lua doesn't support loading dynamic libraries.
Lua can be made to support dynamic libraries in a form of system libraries. I've done it in MorphOS port and probably backporting it to classic Amiga is straightforward.
Krashan is offline  
Old 06 January 2020, 23:13   #20
MartinW
Registered User
 
Join Date: Mar 2017
Location: Minehead / UK
Posts: 608
Apologies for resurrecting an old thread but any idea what hardware the above tests were performed on?

For example " 11.7 down from gcc3.4.0's 24.58, down from 26.6 of SAS C "

I'm just trying to guage my results with the lua i just built.
MartinW is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Logitech Precision gamepad hasn't worked since 2.3.3 Sigma support.WinUAE 13 20 March 2013 09:29
File timestamps lose precision in shared folders mark_k support.WinUAE 9 06 February 2013 16:25
Talkie infocom interpreter Anakirob project.Amiga Game Factory 2 28 May 2011 03:34
looking for AmigaBasic Interpreter phil321 New to Emulation or Amiga scene 41 19 December 2006 14:26
making a basic interpreter staticgerbil Coders. General 2 27 January 2004 23:28

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:56.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.23335 seconds with 14 queries