marrub
/
LoveToken
Archived
1
0
Fork 0

added examples and a clean target

master
Marrub 2015-06-07 04:25:25 -04:00
parent baa854169c
commit cdb6207632
5 changed files with 86 additions and 0 deletions

View File

@ -1,21 +1,27 @@
CC=
MKDIR=
RM=
PCFLAGS=
PLFLAGS=
LIBNAME=
OUTDIR=bin
LFLAGS=-shared -g -ggdb
CFLAGS=--std=c99 -g -ggdb -O2 -Wall
RMEXTRA=
EXAMPLEBIN=
ifeq ($(OS),Windows_NT)
CC+=mingw32-gcc
MKDIR+=mkdir -p
RM+=rm
PLFLAGS+=-Wl,--out-implib,bin/libLoveToken.a
LIBNAME+=$(OUTDIR)/LoveToken.dll
RMEXTRA+=bin/libLoveToken.a
else
ifeq ($(shell uname -s), Linux)
CC+=gcc
MKDIR+=mkdir -p
RM+=rm
PCFLAGS+=-fPIC
LIBNAME+=$(OUTDIR)/LoveToken.so
endif
@ -25,3 +31,9 @@ all:
$(MKDIR) $(OUTDIR)
$(CC) $(CFLAGS) $(PCFLAGS) -c -o $(OUTDIR)/lt.o src/lt.c
$(CC) $(LFLAGS) -o $(LIBNAME) $(OUTDIR)/lt.o $(PLFLAGS) -liconv
clean:
$(RM) $(LIBNAME) bin/lt.o $(RMEXTRA)
example:
$(CC) $(CFLAGS) -Isrc -Lbin -o bin/example examples/main.c -lLoveToken

1
examples/a.txt Normal file
View File

@ -0,0 +1 @@
The quick brown fox jumps over the !lazy dog.

5
examples/conf.lua Normal file
View File

@ -0,0 +1,5 @@
-- This file is placed under public domain.
function love.conf(t)
t.console = true
t.window.title = "Tokenizer Example"
end

40
examples/main.c Normal file
View File

@ -0,0 +1,40 @@
// This file is placed under public domain.
#include "lt.h"
#include <stdio.h>
int main(int argc, char **argv)
{
LT_Config initCfg = { 0 }; // we don't need to set any options here
LT_Token tk;
LT_OpenFile("a.txt");
LT_Init(initCfg);
while(tk.token != LT_TkNames[TOK_EOF])
{
LT_AssertInfo check;
tk = LT_GetToken();
check = LT_CheckAssert();
if(check.failure)
{
printf("%s\n", check.str);
break;
}
if(tk.string != NULL)
{
printf("%s\n", tk.string);
}
else
{
printf("%s\n", tk.token);
}
}
LT_CloseFile();
LT_Quit();
return 0;
}

28
examples/main.lua Normal file
View File

@ -0,0 +1,28 @@
-- This file is placed under public domain.
local tokenizer = require("lua/tokenizer")
local ffi = require("ffi")
function love.load(arg)
local initCfg = ffi.new("LT_Config") -- we don't need to set any options here
local tk
tokenizer:init(initCfg, "a.txt")
while (tk.token ~= "TOK_EOF") do
tk = tokenizer:getToken()
if (tk.string ~= nil) then
print(tk.string)
else
print(tk.token)
end
end
tokenizer:quit()
end
function love.update(dt)
end
function love.draw(dt)
end