Commit Graph

1117 Commits

Author SHA1 Message Date
Fabrice Ducos
65a5088092 src/core/org/luaj/vm2/compiler/FuncState.java: reverted changed from generic HashMap to non generic Hashtable for JME portability 2023-04-23 14:40:20 +02:00
Fabrice Ducos
113c3a9b97 README.md updated 2023-04-23 14:16:41 +02:00
Fabrice Ducos
1b8d7c7485 README.md updated 2023-04-23 14:08:03 +02:00
Fabrice Ducos
f364bb0189 README.md updated 2023-04-23 13:49:16 +02:00
Fabrice Ducos
f680cce336 README.md updated 2023-04-23 13:46:38 +02:00
Fabrice Ducos
b0df2ddcb0 build.xml: default task is now "jar-jse" instead of "all" 2023-04-23 13:44:20 +02:00
Fabrice Ducos
2207f7f2e2 src/core/org/luaj/vm2/compiler/FuncState.java:
Replaced the deprecated, non generic Hashtable with generic Map (interface) and HashMap (implementation)

Hashtable h -> Map<LuaValue, Integer> h

this.h = new Hashtable() -> this.h = new HashMap<>()
2023-04-23 12:58:56 +02:00
Fabrice Ducos
8df7dd717c build-coverage.xml: javac target="1.5" -> target="1.8" 2023-04-23 12:27:47 +02:00
Fabrice Ducos
a40e6862f4 build-applet.xml:
-target 1.4 -> -target 1.8

<param name=java_version value="1.4+"/> -> <param name=java_version value="1.8+"/>
2023-04-23 12:24:58 +02:00
Fabrice Ducos
33b6428031 grammar/LuaParser.jj, grammer/Lua5[12].jj: JDK_VERSION upgraded from 1.3 to 1.8 2023-04-23 12:19:04 +02:00
Fabrice Ducos
ee08260ce2 build-applet.xml, build-midlet.xml: source and target of javac upgraded from 1.2, 1.3 or 1.4 to 1.8 2023-04-23 12:07:40 +02:00
Fabrice Ducos
393cf23775 build.xml: includeantruntime="false" added to javac
Reference: https://stackoverflow.com/questions/5103384/ant-warning-includeantruntime-was-not-set
2023-04-23 12:00:20 +02:00
Fabrice Ducos
970cfc579a .gitignore: .java-version added (a .jenv configuration file) 2023-04-23 11:58:52 +02:00
Fabrice Ducos
7aa0389f6f README.md updated 2022-06-15 07:14:27 +02:00
Fabrice Ducos
c09d652874 luaj ported to Windows with the name luaj.bat 2022-06-15 07:12:36 +02:00
Fabrice Ducos
3c863714b4 src/core/org/luaj/vm2/compiler/LexState.java: error message on unexpected symbol fixed (it was returning a strange character
corresponding to an internal token code, meaningless to the user)
2022-06-15 01:11:09 +02:00
Fabrice Ducos
bfb7da97cf luaj: new command for invoking the luaj interpreter 2022-06-15 01:09:05 +02:00
Fabrice Ducos
1aa90eb7fa src/core/org/luaj/vm2/lib/CoroutineLib.java:
Internal classes create, resume, ..., yield, wrap renamed Create, Resume, ... Yield, Wrap

This change was motivated by the fact that yield is a restricted name in JDK 14+

A lowercase 'yield' class was producing a warning in JDK 8 and could potentially not compile in newer JDK.
2022-06-14 22:40:10 +02:00
Fabrice Ducos
610833f025 build.xml: includeantruntime="false" appended to javac tasks in order to ensure repeatable builds by ant 2022-06-14 22:30:41 +02:00
Fabrice Ducos
9e1a62662a Removed deprecated wrapper class constructors (new Byte, ..., new Integer, new Double...)
Replaced with valueOf() in order to silence many warnings from modern versions of the JDK
2022-06-14 22:25:20 +02:00
Fabrice Ducos
314ffd6a23 Update README.md 2022-06-14 22:03:47 +02:00
Fabrice Ducos
7395234ccf build.xml: refactored with separate targets for jme and jse: compile-jme and compile-jse
New versions of ant (e.g. 1.10.11) at this time of writing fail to build jar-jme

because the source (1.2) and target (1.3) are considered too old.

The jme target can now be compiled separately with 'ant jar-jme'

and the jse target with 'ant jar-jse'

The jse target will now be built with source="1.8" and target="1.8"
2022-06-14 21:37:48 +02:00
Enyby
daf3da94e3 Fix #66: Broken license link. 2020-04-01 19:36:00 +03:00
Enyby
30e60a883e Create LICENSE
Source: https://web.archive.org/web/20140514153921/http://sourceforge.net/dbimage.php?id=196142
2020-04-01 19:31:39 +03:00
Enyby
27edcc9a92 Fix possible error in rare cases in LuaTable:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
2019-12-29 16:46:58 +02:00
Enyby
d6737c0bb3 Improve work with weak keys.
```
for _, m in ipairs({'', 'k', 'kv', 'v'}) do
	print('test', m)
	a = {}; setmetatable(a, {__mode = m});
	a[1], a[2], a[3] = {}, {}, {};
	for k, v in pairs(a) do
		print(k, v)
	end
end
print('ok')
```
2019-12-16 15:31:13 +02:00
Enyby
d201bc3012 Fix work with weak tables.
```
a = {}; setmetatable(a, {__mode = 'vk'});
a[1], a[2], a[3] = {}, {}, {};
for k, v in pairs(a) do
	print(k, v)
end
print('ok')
```
2019-12-15 20:39:26 +02:00
Enyby
ca64666242 Fix metamethods for compare with numbers.
```
t = {}
t.__lt = function (a,b,c)
  collectgarbage()
  assert(c == nil)
  if type(a) == 'table' then a = a.x end
  if type(b) == 'table' then b = b.x end
 return a<b, "dummy"
end

function Op(x) return setmetatable({x=x}, t) end

local function test ()
  assert(not(Op(1)<Op(1)) and (Op(1)<Op(2)) and not(Op(2)<Op(1)))
  assert(not(1 < Op(1)) and (Op(1) < 2) and not(2 < Op(1)))
  assert(not(Op('a')<Op('a')) and (Op('a')<Op('b')) and not(Op('b')<Op('a')))
  assert(not('a' < Op('a')) and (Op('a') < 'b') and not(Op('b') < Op('a')))
  assert((Op(1)<=Op(1)) and (Op(1)<=Op(2)) and not(Op(2)<=Op(1)))
  assert((Op('a')<=Op('a')) and (Op('a')<=Op('b')) and not(Op('b')<=Op('a')))
  assert(not(Op(1)>Op(1)) and not(Op(1)>Op(2)) and (Op(2)>Op(1)))
  assert(not(Op('a')>Op('a')) and not(Op('a')>Op('b')) and (Op('b')>Op('a')))
  assert((Op(1)>=Op(1)) and not(Op(1)>=Op(2)) and (Op(2)>=Op(1)))
  assert((1 >= Op(1)) and not(1 >= Op(2)) and (Op(2) >= 1))
  assert((Op('a')>=Op('a')) and not(Op('a')>=Op('b')) and (Op('b')>=Op('a')))
  assert(('a' >= Op('a')) and not(Op('a') >= 'b') and (Op('b') >= Op('a')))
end

test()
```
2019-11-11 02:47:19 +02:00
Enyby
725cf89b6f Fix metamethods for compare with string. 2019-11-11 02:29:20 +02:00
Enyby
da0b06555a Fix pattern error message. 2019-11-09 23:26:48 +02:00
Enyby
ee2d5284e7 Fix '%b' pattern error message. 2019-11-09 23:25:58 +02:00
Enyby
0f0ec4bf7b Add check for too complex patterns.
```
-- bug since 2.5 (C-stack overflow)
do
  local function f (size)
    local s = string.rep("a", size)
    local p = string.rep(".?", size)
    return pcall(string.match, s, p)
  end
  local r, m = f(80)
  assert(r and #m == 80)
  r, m = f(200000)
  assert(not r and string.find(m, "too complex"), tostring(r)..", "..tostring(m))
end
```
2019-11-09 23:25:07 +02:00
Enyby
5813d56f89 Improve error messages for invalid capture index. 2019-11-09 23:21:39 +02:00
Enyby
8c42c4712b Fix empty matches in patterns.
```
do   -- new (5.3.3) semantics for empty matches
  assert(string.gsub("a b cd", " *", "-") == "-a-b-c-d-")

  local res = ""
  local sub = "a  \nbc\t\td"
  local i = 1
  for p, e in string.gmatch(sub, "()%s*()") do
    res = res .. string.sub(sub, i, p - 1) .. "-"
    i = e
  end
  assert(res == "-a-b-c-d-")
end
```
2019-11-09 23:20:06 +02:00
Enyby
6bc8fd6b1b Fix numeric for add order. 2019-11-09 23:12:31 +02:00
Enyby
bf663878cb Add support for metatags to table lib methods: sort, insert, remove, unpack.
```
do   -- testing table library with metamethods
  local function test (proxy, t)
    for i = 1, 10 do
      table.insert(proxy, 1, i)
    end
    assert(#proxy == 10 and #t == 10, tostring(#proxy)..'; '..tostring(#t))
    for i = 1, 10 do
      assert(t[i] == 11 - i)
    end
    table.sort(proxy)
    for i = 1, 10 do
      assert(t[i] == i and proxy[i] == i, i..': '..tostring(proxy[i])..'; '..tostring(t[i]))
    end
    assert(table.concat(proxy, ",") == "1,2,3,4,5,6,7,8,9,10")
    for i = 1, 8 do
      assert(table.remove(proxy, 1) == i)
    end
    assert(#proxy == 2 and #t == 2)
    local a, b, c = table.unpack(proxy)
    assert(a == 9 and b == 10 and c == nil)
  end

  -- all virtual
  local t = {}
  local proxy = setmetatable({}, {
    __len = function () return #t end,
    __index = t,
    __newindex = t,
  })
  test(proxy, t)

  -- only __newindex
  local count = 0
  t = setmetatable({}, {
    __newindex = function (t,k,v) count = count + 1; rawset(t,k,v) end})
  test(t, t)
  assert(count == 10)   -- after first 10, all other sets are not new

  -- no __newindex
  t = setmetatable({}, {
    __index = function (_,k) return k + 1 end,
    __len = function (_) return 5 end})
  assert(table.concat(t, ";") == "2;3;4;5;6")

end

function check (a, f)
  f = f or function (x,y) return x<y end;
  for n = #a, 2, -1 do
    local cmp = f(a[n], a[n-1])
    if cmp then print(tostring(a)..'\n'..n..': "'..tostring(a[n])..'" < "'..tostring(a[n-1])..'"') end
    assert(not cmp)
  end
end

for b = 1, 2 do
	a = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
	     "Oct", "Nov", "Dec"}
	if b == 2 then a[15] = 'Aaa' a[14] = 'Iii' a[13] = 'Mmm' end
	print(#a)
	table.sort(a)
	check(a)
end
```
2019-11-04 07:57:49 +02:00
Enyby
e120008f9b Validate table.remove pos. 2019-11-03 16:08:01 +02:00
Enyby
9a20aa8077 Check pos bounds for table.insert. 2019-11-03 15:55:32 +02:00
Enyby
99f21b6277 Speed up table.sort. 2019-11-03 14:03:53 +02:00
Enyby
53bd4bf71f Fix compiler Bug{
what = [[label between local definitions can mix-up their initializations]],
report = [[Karel Tuma, 2016/03/01]],
since = [[5.2]],
fix = nil,
example = [[
do
  local k = 0
  local x
  ::foo::
  local y       -- should be reset to nil after goto, but it is not
  assert(not y)
  y = true
  k = k + 1
  if k < 2 then goto foo end
end
]],
patch = [[
--- lparser.c	2015/11/02 16:09:30	2.149
+++ lparser.c	2016/03/03 12:03:37
@@ -1226,7 +1226,7 @@
   checkrepeated(fs, ll, label);  /* check for repeated labels */
   checknext(ls, TK_DBCOLON);  /* skip double colon */
   /* create new entry for this label */
-  l = newlabelentry(ls, ll, label, line, fs->pc);
+  l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs));
   skipnoopstat(ls);  /* skip other no-op statements */
   if (block_follow(ls, 0)) {  /* label is last no-op statement in the block? */
     /* assume that locals are already out of scope */
]]
}
2019-11-02 17:02:21 +02:00
Enyby
b57eb247ba Fix table.unpack. 2019-11-02 15:18:48 +02:00
Enyby
05e82f1c3f Add package.config. #49 2019-10-27 23:08:44 +02:00
Enyby
9b2f0a2805 Fix os.tmpname. 2019-10-22 07:00:21 +03:00
Enyby
ef8175050b Remove unused field. 2019-10-21 23:26:10 +03:00
Enyby
0d2aa6cc54 Switch little-endian by default as original Lua does. 2019-10-21 23:25:30 +03:00
Enyby
fe7bd07450 Fix lexer bugs.
Wrong work with spaces.
2019-10-21 10:20:06 +03:00
Enyby
f0e9348ae2 Fix lexer bugs.
Already handled by inside isalnum.
2019-10-21 10:17:26 +03:00
Enyby
22e7a8c620 Fix lexer bugs.
Already handled by case above.
2019-10-21 10:16:43 +03:00
Enyby
c8461b8128 Fix pattern classes in string lib.
```
local ref = {
}
for cl in string.gmatch('acdglpsuwxACDGLPSUWX', '.') do
	local list = ''
	for i = 0, 255 do
		if string.match(string.char(i), '%'..cl) then
			list = list..i..','
		end
	end
	if ref[cl] then
		assert(ref[cl] == list, cl..':\n'..list..'\n'..ref[cl])
	else
		print(cl..' = "'..list..'",')
	end
end

print('+')
```
2019-10-21 08:43:53 +03:00
Enyby
3a6c382570 Fix 'error' call. #60 2019-10-20 19:19:14 +03:00