Improved performance

This commit is contained in:
Łukasz Magiera 2016-01-18 19:42:32 +01:00
parent 75f386b03a
commit 2259a83d76
6 changed files with 2209 additions and 2174 deletions

3
.gitattributes vendored Normal file
View File

@ -0,0 +1,3 @@
*.lua -crlf
*.h -crlf
*.c -crlf

View File

@ -1,5 +1,9 @@
# TARGET=arm-none-eabi
#CC=$(TARGET)-gcc
CC=gcc CC=gcc
CFLAGS=-g -std=gnu99 -Isrc/lib/lua -Iinclude
CFLAGS=-O2 -std=gnu99 -Isrc/lib/lua -Iinclude
BUILD = bin/ BUILD = bin/
SOURCE = src/c/ SOURCE = src/c/
@ -22,14 +26,9 @@ OBJECTS := $(patsubst $(SOURCE)%.c, $(BUILD)%.c.o, $(CFILES))
$(BUILDDIRECTORIES): $(BUILDDIRECTORIES):
mkdir -p $@ mkdir -p $@
#Clean
#Build #Build
all: smallclean $(BUILDDIRECTORIES) luaresources $(BUILD)lupi all: smallclean $(BUILDDIRECTORIES) luaresources $(BUILD)lupi
smallclean:
find . -name '*~' -type f -exec rm {} \;
build: clean all build: clean all
$(BUILD)lupi: $(OBJECTS) $(BUILD)lupi: $(OBJECTS)
@ -51,3 +50,10 @@ cleanresourcues:
clean: cleanresourcues clean: cleanresourcues
-rm -rf $(BUILD) -rm -rf $(BUILD)
smallclean:
find . -name '*~' -type f -exec rm {} \;
# Other
.PHONY: clean cleanresourcues luaresources build smallclean all

View File

@ -157,4 +157,8 @@ function api.totalMemory()
return native.totalMemory() return native.totalMemory()
end end
function api.shutdown()
os.exit(0)
end
return computer return computer

View File

@ -17,6 +17,7 @@ io.write = function(...)
io.flush() io.flush()
native.sleep(20000) native.sleep(20000)
end]]-- end]]--
local write = io.write local write = io.write
local flush = io.flush local flush = io.flush

View File

@ -55,6 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-- --
local strbyte, strlen, strsub, type = string.byte, string.len, string.sub, type local strbyte, strlen, strsub, type = string.byte, string.len, string.sub, type
local lutf8 = utf8
local utf8 = {} local utf8 = {}
-- returns the number of bytes used by the UTF-8 character at byte i in s -- returns the number of bytes used by the UTF-8 character at byte i in s
@ -230,7 +231,27 @@ local function utf8sub(s, i, j)
return strsub(s, startByte, endByte) return strsub(s, startByte, endByte)
end end
utf8.sub = utf8sub function utf8.sub(s,i,j)
i = i or 1
j = j or math.maxinteger
if i<1 or j<1 then
local n = lutf8.len(s)
if not n then return nil end
if i<0 then i = n+1+i end
if j<0 then j = n+1+j end
if i<0 then i = 1 elseif i>n then i = n end
if j<0 then j = 1 elseif j>n then j = n end
end
if j<i then return "" end
i = lutf8.offset(s,i) or math.maxinteger
j = lutf8.offset(s,j+1) or math.maxinteger
if i and j then return s:sub(i,j-1)
elseif i then return s:sub(i)
else return ""
end
end
--utf8.sub = utf8sub
-- replace UTF-8 characters based on a mapping table -- replace UTF-8 characters based on a mapping table
local function utf8replace(s, mapping) local function utf8replace(s, mapping)