From 4e870aec70508de3e42ec50c07656135cd8c1798 Mon Sep 17 00:00:00 2001 From: gamax92 Date: Sat, 16 Jan 2016 12:03:25 -0700 Subject: [PATCH] Add Lua 5.3 support --- README.md | 4 ++-- src/apis/unicode.lua | 2 +- src/component/gpu.lua | 4 ++-- src/component/keyboard_sdl2.lua | 4 ++-- src/component/screen_sdl2.lua | 2 +- src/main.lua | 21 ++++++++++++++++++--- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9214e7e..c0e8ed2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ OCEmu - OpenComputers Emulator Installation ------------ -Needs lua-5.2, luafilesystem, utf8, luaffi, and SDL2. +Needs lua-5.2, luafilesystem, luautf8, luaffi, and SDL2. luasocket is optional but is required for the Internet Component and higher precision timing. @@ -38,7 +38,7 @@ Follow the luarocks steps below. **Lua Libraries** ``` luarocks-5.2 install luafilesystem -luarocks-5.2 install utf8 +luarocks-5.2 install luautf8 luarocks-5.2 install luasocket luarocks-5.2 install luasec luarocks-5.2 install --server=http://luarocks.org/dev luaffi diff --git a/src/apis/unicode.lua b/src/apis/unicode.lua index c4a70e4..6c24d2b 100644 --- a/src/apis/unicode.lua +++ b/src/apis/unicode.lua @@ -1,6 +1,6 @@ local env = ... -local utf8 = require("utf8") +local utf8 = require("lua-utf8") local function cln(str) return str:gsub("%z.*","") .. "" diff --git a/src/component/gpu.lua b/src/component/gpu.lua index 7b730c3..b9e211d 100644 --- a/src/component/gpu.lua +++ b/src/component/gpu.lua @@ -3,7 +3,7 @@ compCheckArg(1,maxwidth,"number") compCheckArg(2,maxheight,"number") compCheckArg(3,maxtier,"number") -local lua_utf8 = require("utf8") +local utf8 = require("lua-utf8") local bindaddress local depthTbl = {1,4,8} @@ -102,7 +102,7 @@ function obj.fill(x, y, width, height, char) -- Fills a portion of the screen at if bindaddress == nil then return nil, "no screen" end - if lua_utf8.len(char) ~= 1 then + if utf8.len(char) ~= 1 then return nil, "invalid fill value" end return component.cecinvoke(bindaddress, "fill", x, y, width, height, char) diff --git a/src/component/keyboard_sdl2.lua b/src/component/keyboard_sdl2.lua index 951bf35..bf369b5 100644 --- a/src/component/keyboard_sdl2.lua +++ b/src/component/keyboard_sdl2.lua @@ -1,7 +1,7 @@ local address = ... local ffi = require("ffi") -local lua_utf8 = require("utf8") +local utf8 = require("lua-utf8") local SDL = elsa.SDL -- Conversion table for SDL2 keys to LWJGL key codes @@ -18,7 +18,7 @@ function elsa.textinput(event) local textevent = ffi.cast("SDL_TextInputEvent*", event) local text = ffi.string(textevent.text) cprint("textinput",text) - setLatest(lua_utf8.byte(text)) + setLatest(utf8.byte(text)) end function elsa.keydown(event) diff --git a/src/component/screen_sdl2.lua b/src/component/screen_sdl2.lua index 01a76f4..d5dd8bf 100644 --- a/src/component/screen_sdl2.lua +++ b/src/component/screen_sdl2.lua @@ -4,7 +4,7 @@ compCheckArg(2,maxheight,"number") compCheckArg(3,maxtier,"number") local ffi = require("ffi") -local utf8 = require("utf8") +local utf8 = require("lua-utf8") local bit = require("bit32") local SDL = elsa.SDL diff --git a/src/main.lua b/src/main.lua index 6ef0bf8..ed269b7 100644 --- a/src/main.lua +++ b/src/main.lua @@ -124,7 +124,6 @@ local env = { upvalueid = debug.upvalueid, upvaluejoin = debug.upvaluejoin, }, - dofile = dofile, error = error, getmetatable = getmetatable, io = { @@ -145,7 +144,6 @@ local env = { }, ipairs = ipairs, load = load, - loadfile = loadfile, math = { abs = math.abs, acos = math.acos, @@ -166,7 +164,7 @@ local env = { max = math.max, min = math.min, modf = math.modf, - pi = 3.1415926535898, + pi = math.pi, pow = math.pow, rad = math.rad, random = math.random, @@ -230,6 +228,23 @@ local env = { type = type, xpcall = xpcall, } +if _VERSION == "Lua 5.3" then + env._VERSION = "Lua 5.3" + env.coroutine.isyieldable = coroutine.isyieldable + env.math.maxinteger = math.maxinteger + env.math.mininteger = math.mininteger + env.math.tointeger = math.tointeger + env.math.type = math.type + env.math.ult = math.ult + env.string.pack = string.pack + env.string.packsize = string.packsize + env.string.unpack = string.unpack + env.table.move = table.move + env.utf8 = {} + for k,v in pairs(utf8) do + env.utf8[k] = v + end +end setmetatable(env,{ __index = function(_,k) cprint("Missing environment access", "env." .. k)