├── golua ├── go.mod ├── lua │ ├── lua52 │ │ ├── lua.hpp │ │ ├── dummy.go │ │ ├── lapi.h │ │ ├── lundump.h │ │ ├── lfunc.h │ │ ├── ldebug.h │ │ ├── lualib.h │ │ ├── ltm.h │ │ ├── lstring.h │ │ ├── ltable.h │ │ ├── lvm.h │ │ ├── ldo.h │ │ ├── lzio.h │ │ ├── lzio.c │ │ ├── linit.c │ │ ├── lmem.h │ │ ├── ltm.c │ │ ├── lctype.h │ │ ├── llex.h │ │ ├── lctype.c │ │ ├── lmem.c │ │ └── lcode.h │ ├── lua53 │ │ ├── lua.hpp │ │ ├── dummy.go │ │ ├── lapi.h │ │ ├── lundump.h │ │ ├── lprefix.h │ │ ├── lualib.h │ │ ├── ldebug.h │ │ ├── lstring.h │ │ ├── lzio.c │ │ ├── lzio.h │ │ ├── lfunc.h │ │ ├── linit.c │ │ ├── ltm.h │ │ ├── lctype.h │ │ ├── ldo.h │ │ ├── ltable.h │ │ ├── lctype.c │ │ ├── llex.h │ │ ├── lmem.h │ │ └── lmem.c │ ├── lua54 │ │ ├── lua.hpp │ │ ├── dummy.go │ │ ├── lundump.h │ │ ├── lprefix.h │ │ ├── lualib.h │ │ ├── lzio.c │ │ ├── lapi.h │ │ ├── lopnames.h │ │ ├── lzio.h │ │ ├── lstring.h │ │ ├── linit.c │ │ ├── lfunc.h │ │ ├── ljumptab.h │ │ ├── ldebug.h │ │ ├── ltable.h │ │ ├── lctype.h │ │ ├── lctype.c │ │ ├── llex.h │ │ └── ltm.h │ ├── lua51 │ │ ├── dummy.go │ │ ├── lapi.h │ │ ├── linit.c │ │ ├── lstring.h │ │ ├── lundump.h │ │ ├── ldebug.h │ │ ├── ltm.h │ │ ├── lualib.h │ │ ├── lfunc.h │ │ ├── lvm.h │ │ ├── ltable.h │ │ ├── lmem.h │ │ ├── lzio.h │ │ ├── ltm.c │ │ ├── lzio.c │ │ ├── ldo.h │ │ ├── llex.h │ │ ├── lmem.c │ │ ├── lparser.h │ │ ├── llimits.h │ │ ├── lcode.h │ │ └── lopcodes.c │ ├── dummy.go │ ├── golua.h │ ├── buildlua.sh │ ├── lua_defs_lua52.go │ ├── lua_defs_lua53.go │ ├── lua_defs_lua54.go │ └── lua_defs_lua51.go ├── _example │ ├── calls.lua │ ├── quickstart.go │ ├── panic.go │ ├── basic.go │ ├── dump_load.go │ ├── error.go │ ├── alloc.go │ └── userdata.go ├── TODO ├── .travis.yml └── LICENSE ├── handlers ├── md5sum.txt └── biquge.lua ├── pdfpresets ├── a5 ├── a6 ├── b5 ├── b6 ├── c4 ├── c5 ├── c6 ├── a0 ├── a1 ├── a2 ├── a3 ├── b0 ├── b1 ├── b2 ├── b3 ├── b4 ├── c0 ├── c1 ├── c2 ├── c3 ├── a4 ├── dxg ├── ko1 ├── ko2 ├── ko3 ├── kv ├── kindle ├── kpw1 ├── kpw2 ├── kpw3 ├── kpw4 ├── ipad9 ├── 10inch ├── 6inch ├── 7inch ├── ipad10 ├── iphone7 ├── iphone8 ├── iphonex ├── mobile ├── ipadair4 ├── ipadmini3 ├── ipadmini4 ├── ipadmini5 ├── ipadmini6 ├── ipadpro11 ├── ipadpro129 ├── iphone11 ├── iphone12 ├── iphone13 ├── iphone14 ├── iphone15 ├── iphone6s ├── iphonese ├── iphonexr ├── iphonexs ├── pixel2xl ├── iphone11pro ├── iphone12mini ├── iphone12pro ├── iphone13pro ├── iphone14plus ├── iphone14pro ├── iphone15plus ├── iphone15pro ├── iphone6splus ├── iphone7plus ├── iphone8plus ├── iphonexsmax ├── iphone11promax ├── iphone12promax ├── iphone13promax ├── iphone14promax ├── iphone15promax └── pc ├── .github ├── dependabot.yml └── workflows │ ├── md5sum.yml │ └── go.tidy.yml ├── ebook ├── bs │ ├── utils.go │ ├── chapter_test.go │ ├── source_test.go │ ├── unixtime.go │ ├── book_test.go │ ├── bs3.go │ └── sources.go └── ebook.go ├── .gitignore ├── handler ├── handler.go └── 69shuba.go ├── luawrapper └── luaapi.go ├── config └── novel.go ├── lua └── init.lua └── go.mod /golua/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/aarzilli/golua 2 | 3 | go 1.15 4 | -------------------------------------------------------------------------------- /handlers/md5sum.txt: -------------------------------------------------------------------------------- 1 | 818aaa956348d1d127a93f7b0a2492c5 biquge.lua 2 | -------------------------------------------------------------------------------- /pdfpresets/a5: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "a5", 4 | "pageWidth": 420, 5 | "pageHeight": 595 6 | } -------------------------------------------------------------------------------- /pdfpresets/a6: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "a6", 4 | "pageWidth": 298, 5 | "pageHeight": 420 6 | } -------------------------------------------------------------------------------- /pdfpresets/b5: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "b5", 4 | "pageWidth": 499, 5 | "pageHeight": 709 6 | } -------------------------------------------------------------------------------- /pdfpresets/b6: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "b6", 4 | "pageWidth": 354, 5 | "pageHeight": 499 6 | } -------------------------------------------------------------------------------- /pdfpresets/c4: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "c4", 4 | "pageWidth": 649, 5 | "pageHeight": 918 6 | } -------------------------------------------------------------------------------- /pdfpresets/c5: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "c5", 4 | "pageWidth": 459, 5 | "pageHeight": 649 6 | } -------------------------------------------------------------------------------- /pdfpresets/c6: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "c6", 4 | "pageWidth": 323, 5 | "pageHeight": 459 6 | } -------------------------------------------------------------------------------- /pdfpresets/a0: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "a0", 4 | "pageWidth": 2384, 5 | "pageHeight": 3370 6 | } -------------------------------------------------------------------------------- /pdfpresets/a1: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "a1", 4 | "pageWidth": 1684, 5 | "pageHeight": 2384 6 | } -------------------------------------------------------------------------------- /pdfpresets/a2: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "a2", 4 | "pageWidth": 1191, 5 | "pageHeight": 1684 6 | } -------------------------------------------------------------------------------- /pdfpresets/a3: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "a3", 4 | "pageWidth": 842, 5 | "pageHeight": 1191 6 | } -------------------------------------------------------------------------------- /pdfpresets/b0: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "b0", 4 | "pageWidth": 2835, 5 | "pageHeight": 4008 6 | } -------------------------------------------------------------------------------- /pdfpresets/b1: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "b1", 4 | "pageWidth": 2004, 5 | "pageHeight": 2835 6 | } -------------------------------------------------------------------------------- /pdfpresets/b2: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "b2", 4 | "pageWidth": 1417, 5 | "pageHeight": 2004 6 | } -------------------------------------------------------------------------------- /pdfpresets/b3: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "b3", 4 | "pageWidth": 1001, 5 | "pageHeight": 1417 6 | } -------------------------------------------------------------------------------- /pdfpresets/b4: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "b4", 4 | "pageWidth": 709, 5 | "pageHeight": 1001 6 | } -------------------------------------------------------------------------------- /pdfpresets/c0: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "c0", 4 | "pageWidth": 2599, 5 | "pageHeight": 3677 6 | } -------------------------------------------------------------------------------- /pdfpresets/c1: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "c1", 4 | "pageWidth": 1837, 5 | "pageHeight": 2599 6 | } -------------------------------------------------------------------------------- /pdfpresets/c2: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "c2", 4 | "pageWidth": 1298, 5 | "pageHeight": 1837 6 | } -------------------------------------------------------------------------------- /pdfpresets/c3: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "c3", 4 | "pageWidth": 918, 5 | "pageHeight": 1298 6 | } -------------------------------------------------------------------------------- /pdfpresets/a4: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "a4", 4 | "pageWidth": 595.28, 5 | "pageHeight": 841.89 6 | } -------------------------------------------------------------------------------- /pdfpresets/dxg: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "dxg", 4 | "pageWidth": 595.28, 5 | "pageHeight": 841.89 6 | } -------------------------------------------------------------------------------- /pdfpresets/ko1: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "ko1", 4 | "contentFontSize": 10, 5 | "pageWidth": 255.12, 6 | "pageHeight": 331.65 7 | } -------------------------------------------------------------------------------- /pdfpresets/ko2: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "ko2", 4 | "contentFontSize": 10, 5 | "pageWidth": 297.64, 6 | "pageHeight": 386.93 7 | } -------------------------------------------------------------------------------- /pdfpresets/ko3: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "ko3", 4 | "contentFontSize": 10, 5 | "pageWidth": 297.64, 6 | "pageHeight": 386.93 7 | } -------------------------------------------------------------------------------- /pdfpresets/kv: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "kv", 4 | "contentFontSize": 10, 5 | "pageWidth": 255.12, 6 | "pageHeight": 331.65 7 | } -------------------------------------------------------------------------------- /pdfpresets/kindle: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "kindle", 4 | "contentFontSize": 10, 5 | "pageWidth": 255.12, 6 | "pageHeight": 331.65 7 | } -------------------------------------------------------------------------------- /pdfpresets/kpw1: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "kpw1", 4 | "contentFontSize": 10, 5 | "pageWidth": 255.12, 6 | "pageHeight": 331.65 7 | } -------------------------------------------------------------------------------- /pdfpresets/kpw2: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "kpw2", 4 | "contentFontSize": 10, 5 | "pageWidth": 255.12, 6 | "pageHeight": 331.65 7 | } -------------------------------------------------------------------------------- /pdfpresets/kpw3: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "contentFontSize": 10, 4 | "pageType": "kpw3", 5 | "pageWidth": 255.12, 6 | "pageHeight": 331.65 7 | } -------------------------------------------------------------------------------- /pdfpresets/kpw4: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "kpw4", 4 | "contentFontSize": 10, 5 | "pageWidth": 255.12, 6 | "pageHeight": 331.65 7 | } -------------------------------------------------------------------------------- /pdfpresets/ipad9: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "ipad9", 6 | "pageWidth": 472.5, 7 | "pageHeight": 648.5 8 | } -------------------------------------------------------------------------------- /pdfpresets/10inch: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "10inch", 4 | "titleFontSize": 12, 5 | "contentFontSize": 10, 6 | "pageWidth": 595.28, 7 | "pageHeight": 841.89 8 | } -------------------------------------------------------------------------------- /pdfpresets/6inch: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "6inch", 4 | "titleFontSize": 12, 5 | "contentFontSize": 10, 6 | "pageWidth": 255.12, 7 | "pageHeight": 331.65 8 | } -------------------------------------------------------------------------------- /pdfpresets/7inch: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "7inch", 4 | "titleFontSize": 12, 5 | "contentFontSize": 10, 6 | "pageWidth": 297.64, 7 | "pageHeight": 386.93 8 | } -------------------------------------------------------------------------------- /pdfpresets/ipad10: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "ipad10", 6 | "pageWidth": 504.5, 7 | "pageHeight": 747.3 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone7: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone7", 6 | "pageWidth": 186.8, 7 | "pageHeight": 342.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone8: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone8", 6 | "pageWidth": 186.8, 7 | "pageHeight": 342.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphonex: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphonex", 6 | "pageWidth": 199.5, 7 | "pageHeight": 444.6 8 | } -------------------------------------------------------------------------------- /pdfpresets/mobile: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "mobile", 4 | "titleFontSize": 32, 5 | "contentFontSize": 28, 6 | "pageWidth": 595.28, 7 | "pageHeight": 841.89 8 | } -------------------------------------------------------------------------------- /pdfpresets/ipadair4: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "ipadair4", 6 | "pageWidth": 504.5, 7 | "pageHeight": 747.3 8 | } -------------------------------------------------------------------------------- /pdfpresets/ipadmini3: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "ipadmini3", 6 | "pageWidth": 396.3, 7 | "pageHeight": 513.3 8 | } -------------------------------------------------------------------------------- /pdfpresets/ipadmini4: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "ipadmini4", 6 | "pageWidth": 396.3, 7 | "pageHeight": 513.3 8 | } -------------------------------------------------------------------------------- /pdfpresets/ipadmini5: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "ipadmini5", 6 | "pageWidth": 396.3, 7 | "pageHeight": 513.3 8 | } -------------------------------------------------------------------------------- /pdfpresets/ipadmini6: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "ipadmini6", 6 | "pageWidth": 370.7, 7 | "pageHeight": 581.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/ipadpro11: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "ipadpro11", 6 | "pageWidth": 513.1, 7 | "pageHeight": 756.2 8 | } -------------------------------------------------------------------------------- /pdfpresets/ipadpro129: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "ipadpro129", 6 | "pageWidth": 630.0, 7 | "pageHeight": 865.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone11: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone11", 6 | "pageWidth": 206.3, 7 | "pageHeight": 459.5 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone12: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone12", 6 | "pageWidth": 206.5, 7 | "pageHeight": 460.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone13: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone13", 6 | "pageWidth": 206.5, 7 | "pageHeight": 460.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone14: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone14", 6 | "pageWidth": 206.5, 7 | "pageHeight": 460.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone15: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone15", 6 | "pageWidth": 208.1, 7 | "pageHeight": 464.5 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone6s: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone6s", 6 | "pageWidth": 186.8, 7 | "pageHeight": 342.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphonese: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphonese", 6 | "pageWidth": 186.8, 7 | "pageHeight": 342.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphonexr: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphonexr", 6 | "pageWidth": 206.3, 7 | "pageHeight": 459.5 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphonexs: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphonexs", 6 | "pageWidth": 199.5, 7 | "pageHeight": 444.6 8 | } -------------------------------------------------------------------------------- /pdfpresets/pixel2xl: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "pixel2xl", 4 | "titleFontSize": 12, 5 | "contentFontSize": 10, 6 | "pageWidth": 217.4, 7 | "pageHeight": 447.6 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone11pro: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone11pro", 6 | "pageWidth": 199.5, 7 | "pageHeight": 444.6 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone12mini: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone12mini", 6 | "pageWidth": 184.2, 7 | "pageHeight": 411.0 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone12pro: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone12pro", 6 | "pageWidth": 206.5, 7 | "pageHeight": 460.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone13pro: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone13pro", 6 | "pageWidth": 206.5, 7 | "pageHeight": 460.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone14plus: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone14plus", 6 | "pageWidth": 227.7, 7 | "pageHeight": 507.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone14pro: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone14pro", 6 | "pageWidth": 208.1, 7 | "pageHeight": 464.5 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone15plus: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone15plus", 6 | "pageWidth": 227.7, 7 | "pageHeight": 508.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone15pro: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone15pro", 6 | "pageWidth": 208.1, 7 | "pageHeight": 464.5 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone6splus: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone6splus", 6 | "pageWidth": 218.7, 7 | "pageHeight": 400.3 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone7plus: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone7plus", 6 | "pageWidth": 218.7, 7 | "pageHeight": 400.3 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone8plus: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone8plus", 6 | "pageWidth": 218.7, 7 | "pageHeight": 400.3 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphonexsmax: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphonexsmax", 6 | "pageWidth": 220.2, 7 | "pageHeight": 490.6 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone11promax: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone11promax", 6 | "pageWidth": 220.2, 7 | "pageHeight": 490.6 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone12promax: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone12promax", 6 | "pageWidth": 227.7, 7 | "pageHeight": 507.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone13promax: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone13promax", 6 | "pageWidth": 227.7, 7 | "pageHeight": 507.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone14promax: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone14promax", 6 | "pageWidth": 227.7, 7 | "pageHeight": 508.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/iphone15promax: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "titleFontSize": 12, 4 | "contentFontSize": 10, 5 | "pageType": "iphone15promax", 6 | "pageWidth": 227.7, 7 | "pageHeight": 508.1 8 | } -------------------------------------------------------------------------------- /pdfpresets/pc: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pdf", 3 | "pageType": "pc", 4 | "leftMargin": 72, 5 | "topMargin": 89.9, 6 | "titleFontSize": 16, 7 | "contentFontSize": 12, 8 | "pageWidth": 595.28, 9 | "pageHeight": 841.89 10 | } -------------------------------------------------------------------------------- /golua/lua/lua52/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /golua/lua/lua53/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /golua/lua/lua54/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /golua/lua/lua51/dummy.go: -------------------------------------------------------------------------------- 1 | // +build dummy 2 | 3 | // Package lua contains only a C header files. 4 | // 5 | // This Go file is part of a workaround for `go mod vendor`. 6 | // Please see the file dummy.go in the parent directory for more information. 7 | package lua 8 | -------------------------------------------------------------------------------- /golua/lua/lua52/dummy.go: -------------------------------------------------------------------------------- 1 | // +build dummy 2 | 3 | // Package lua contains only a C header files. 4 | // 5 | // This Go file is part of a workaround for `go mod vendor`. 6 | // Please see the file dummy.go in the parent directory for more information. 7 | package lua 8 | -------------------------------------------------------------------------------- /golua/lua/lua53/dummy.go: -------------------------------------------------------------------------------- 1 | // +build dummy 2 | 3 | // Package lua contains only a C header files. 4 | // 5 | // This Go file is part of a workaround for `go mod vendor`. 6 | // Please see the file dummy.go in the parent directory for more information. 7 | package lua 8 | -------------------------------------------------------------------------------- /golua/lua/lua54/dummy.go: -------------------------------------------------------------------------------- 1 | // +build dummy 2 | 3 | // Package lua contains only a C header files. 4 | // 5 | // This Go file is part of a workaround for `go mod vendor`. 6 | // Please see the file dummy.go in the parent directory for more information. 7 | package lua 8 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gomod 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "21:00" 8 | open-pull-requests-limit: 10 9 | ignore: 10 | - dependency-name: github.com/signintech/gopdf 11 | versions: 12 | - 0.9.15 13 | -------------------------------------------------------------------------------- /golua/_example/calls.lua: -------------------------------------------------------------------------------- 1 | -- The only point of this file is to generate an interesting stack trace 2 | 3 | function call3(n) 4 | if n == 3 then 5 | error("Some error") 6 | end 7 | end 8 | 9 | function call2() 10 | for i = 1, 4, 1 do 11 | call3(i) 12 | end 13 | end 14 | 15 | function call1() 16 | call2() 17 | end 18 | 19 | call1() 20 | -------------------------------------------------------------------------------- /golua/lua/lua51/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /ebook/bs/utils.go: -------------------------------------------------------------------------------- 1 | package bs 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func urlFix(uri, host string) string { 9 | if !strings.HasPrefix(uri, "/") { 10 | return uri 11 | } 12 | if !strings.HasPrefix(uri, "//") { 13 | return fmt.Sprintf("%s%s", host, uri) 14 | } 15 | return fmt.Sprintf("%s:%s", strings.Split(host, ":")[0], uri) 16 | } 17 | -------------------------------------------------------------------------------- /ebook/bs/chapter_test.go: -------------------------------------------------------------------------------- 1 | package bs 2 | 3 | import ( 4 | "log" 5 | "testing" 6 | ) 7 | 8 | func TestChapter(t *testing.T) { 9 | setupBookSources() 10 | c, e := NewChapterFromURL("http://www.b5200.net/46_46254/17700048.html") 11 | if e != nil { 12 | t.Error(e) 13 | return 14 | } 15 | log.Println("chapter title:", c.GetTitle()) 16 | log.Println("chapter content:", c.GetContent()) 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | *.o 7 | *.a 8 | 9 | *.zip 10 | *.ttf 11 | 12 | # Test binary, build with `go test -c` 13 | *.test 14 | 15 | # Output of the go coverage tool, specifically when used with LiteIDE 16 | *.out 17 | 18 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 19 | .glide/ 20 | 21 | .idea/ 22 | .vscode 23 | -------------------------------------------------------------------------------- /golua/TODO: -------------------------------------------------------------------------------- 1 | - find all calls to lua api that can result in lua_error calls and rework them (for example checkarg stuff) 2 | - lua.go: Dump implementing lua_dump 3 | - lua.go: Load implementing lua_load 4 | - AtPanic slightly broken when nil is passed, if we think passing nil has value to extract the current atpanic function we should also make sure it doesn't break everything 5 | - threads implementation is probably fucked completely should look into it 6 | - lauxlib.go:CheckOption is not implemented -------------------------------------------------------------------------------- /golua/_example/quickstart.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/aarzilli/golua/lua" 4 | 5 | func adder(L *lua.State) int { 6 | a := L.ToInteger(1) 7 | b := L.ToInteger(2) 8 | L.PushInteger(int64(a + b)) 9 | return 1 10 | } 11 | 12 | func main() { 13 | L := lua.NewState() 14 | defer L.Close() 15 | L.OpenLibs() 16 | 17 | L.GetGlobal("print") 18 | L.PushString("Hello World!") 19 | L.Call(1, 0) 20 | 21 | L.Register("adder", adder) 22 | L.DoString("print(adder(2, 2))") 23 | } 24 | -------------------------------------------------------------------------------- /golua/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | dist: xenial 3 | before_install: 4 | - sudo add-apt-repository ppa:vbernat/haproxy-1.6 -y 5 | - sudo apt-get -qq update 6 | - sudo apt-get install -y liblua5.1-dev 7 | - sudo apt-get install -y liblua5.2-dev 8 | - sudo apt-get install -y liblua5.3-dev 9 | install: true 10 | script: 11 | - go test -v github.com/aarzilli/golua/lua 12 | - go test -v -tags lua52 github.com/aarzilli/golua/lua 13 | - go test -v -tags lua53 github.com/aarzilli/golua/lua 14 | 15 | -------------------------------------------------------------------------------- /golua/lua/lua52/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.7.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /golua/lua/lua53/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /ebook/bs/source_test.go: -------------------------------------------------------------------------------- 1 | package bs 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestReadBookSourceFromLocalFileSystem(t *testing.T) { 9 | 10 | } 11 | 12 | func TestReadBookSourceFromURL(t *testing.T) { 13 | setupBookSources() 14 | for _, b := range allBookSources.BookSourceCollection { 15 | fmt.Println(b.BookSourceGroup, b.BookSourceName, b.BookSourceURL, b.Enable) 16 | } 17 | if allBookSources.Length() == 0 { 18 | t.Error("no book sources read") 19 | } 20 | } 21 | 22 | func TestSearchBooks(t *testing.T) { 23 | setupBookSources() 24 | sr:= SearchBooks(`斗破苍穹`) 25 | if sr == nil { 26 | t.Error("can't find 斗破苍穹") 27 | } 28 | fmt.Println(sr) 29 | } -------------------------------------------------------------------------------- /ebook/bs/unixtime.go: -------------------------------------------------------------------------------- 1 | package bs 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | "time" 8 | ) 9 | 10 | // UnixTime convert from JSON value to time type 11 | type UnixTime time.Time 12 | 13 | // UnmarshalJSON convert from JSON value 14 | func (t *UnixTime) UnmarshalJSON(data []byte) (err error) { 15 | r := strings.Replace(string(data), `"`, ``, -1) 16 | ti, err := strconv.ParseInt(r, 10, 64) 17 | if err != nil { 18 | return err 19 | } 20 | *(*time.Time)(t) = time.Unix(ti/1000, 0) 21 | return 22 | } 23 | 24 | // MarshalJSON convert time type to JSON value 25 | func (t UnixTime) MarshalJSON() ([]byte, error) { 26 | ts := fmt.Sprintf("%v", time.Time(t).Unix()*1000) 27 | return []byte(ts), nil 28 | } 29 | -------------------------------------------------------------------------------- /golua/_example/panic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/aarzilli/golua/lua" 4 | import "fmt" 5 | 6 | func test(L *lua.State) int { 7 | fmt.Println("hello world! from go!") 8 | return 0 9 | } 10 | 11 | func main() { 12 | 13 | var L *lua.State 14 | 15 | L = lua.NewState() 16 | defer L.Close() 17 | L.OpenLibs() 18 | 19 | currentPanicf := L.AtPanic(nil) 20 | currentPanicf = L.AtPanic(currentPanicf) 21 | newPanic := func(L1 *lua.State) int { 22 | fmt.Println("I AM PANICKING!!!", currentPanicf) 23 | if currentPanicf != nil { 24 | return currentPanicf(L1) 25 | } 26 | 27 | return 1 28 | } 29 | 30 | L.AtPanic(newPanic) 31 | 32 | //force a panic 33 | L.PushNil() 34 | L.Call(0, 0) 35 | 36 | fmt.Println("End") 37 | } 38 | -------------------------------------------------------------------------------- /golua/lua/dummy.go: -------------------------------------------------------------------------------- 1 | // +build dummy 2 | 3 | // This file is part of a workaround for `go mod vendor` which won't 4 | // vendor C files if there are no Go files in the same directory. 5 | // This prevents the C header files in lua/ from being vendored. 6 | // 7 | // This Go file imports the lua package where there is another 8 | // dummy.go file which is the second part of this workaround. 9 | // 10 | // These two files combined make it so `go mod vendor` behaves correctly. 11 | // 12 | // See this issue for reference: https://github.com/golang/go/issues/26366 13 | 14 | package lua 15 | 16 | import ( 17 | _ "github.com/aarzilli/golua/lua/lua51" 18 | _ "github.com/aarzilli/golua/lua/lua52" 19 | _ "github.com/aarzilli/golua/lua/lua53" 20 | _ "github.com/aarzilli/golua/lua/lua54" 21 | ) 22 | -------------------------------------------------------------------------------- /handler/handler.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/missdeer/getnovel/config" 8 | ) 9 | 10 | var ( 11 | novelSiteHandlers []*config.NovelSiteHandler 12 | ) 13 | 14 | func ListHandlers() { 15 | fmt.Println("当前支持小说网站:") 16 | for _, h := range novelSiteHandlers { 17 | for _, site := range h.Sites { 18 | fmt.Println("\t" + site.Title + ": " + strings.Join(site.Urls, ", ")) 19 | } 20 | } 21 | } 22 | 23 | func RunHandler(runHandler func(*config.NovelSiteHandler) bool) bool { 24 | for _, handler := range novelSiteHandlers { 25 | if runHandler(handler) { 26 | return true 27 | } 28 | } 29 | 30 | return false 31 | } 32 | 33 | func registerNovelSiteHandler(handler *config.NovelSiteHandler) { 34 | novelSiteHandlers = append(novelSiteHandlers, handler) 35 | } 36 | -------------------------------------------------------------------------------- /.github/workflows/md5sum.yml: -------------------------------------------------------------------------------- 1 | name: md5sum 2 | on: 3 | push: 4 | paths: 5 | - 'handlers/*.lua' 6 | - '.github/workflows/md5sum.yml' 7 | 8 | jobs: 9 | md5sum: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Check out code 13 | uses: actions/checkout@v2 14 | 15 | - name: Set up Git 16 | env: 17 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} 18 | run: | 19 | git config user.name "auto-md5sum[bot]" 20 | git config user.email "auto-md5sum[bot]@users.noreply.github.com" 21 | git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git 22 | 23 | - name: update 24 | run: | 25 | cd handlers 26 | md5sum *.lua > md5sum.txt 27 | git commit -m "auto update md5sum at $(date)" md5sum.txt 28 | git push -f origin master -------------------------------------------------------------------------------- /golua/lua/lua52/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.39.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (lu_byte* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | /* data to catch conversion errors */ 23 | #define LUAC_TAIL "\x19\x93\r\n\x1a\n" 24 | 25 | /* size in bytes of header of binary files */ 26 | #define LUAC_HEADERSIZE (sizeof(LUA_SIGNATURE)-sizeof(char)+2+6+sizeof(LUAC_TAIL)-sizeof(char)) 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /golua/lua/lua51/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Initialization of libraries for lua.c 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | #include "lua.h" 12 | 13 | #include "lualib.h" 14 | #include "lauxlib.h" 15 | 16 | 17 | static const luaL_Reg lualibs[] = { 18 | {"", luaopen_base}, 19 | {LUA_LOADLIBNAME, luaopen_package}, 20 | {LUA_TABLIBNAME, luaopen_table}, 21 | {LUA_IOLIBNAME, luaopen_io}, 22 | {LUA_OSLIBNAME, luaopen_os}, 23 | {LUA_STRLIBNAME, luaopen_string}, 24 | {LUA_MATHLIBNAME, luaopen_math}, 25 | {LUA_DBLIBNAME, luaopen_debug}, 26 | {NULL, NULL} 27 | }; 28 | 29 | 30 | LUALIB_API void luaL_openlibs (lua_State *L) { 31 | const luaL_Reg *lib = lualibs; 32 | for (; lib->func; lib++) { 33 | lua_pushcfunction(L, lib->func); 34 | lua_pushstring(L, lib->name); 35 | lua_call(L, 1, 0); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /golua/lua/lua53/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /golua/lua/lua51/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lgc.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | 15 | 16 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 17 | 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 19 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 22 | (sizeof(s)/sizeof(char))-1)) 23 | 24 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 25 | 26 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 27 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 28 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /golua/_example/basic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/aarzilli/golua/lua" 4 | import "fmt" 5 | 6 | func test(L *lua.State) int { 7 | fmt.Println("hello world! from go!") 8 | return 0 9 | } 10 | 11 | func test2(L *lua.State) int { 12 | arg := L.CheckInteger(-1) 13 | argfrombottom := L.CheckInteger(1) 14 | fmt.Print("test2 arg: ") 15 | fmt.Println(arg) 16 | fmt.Print("from bottom: ") 17 | fmt.Println(argfrombottom) 18 | return 0 19 | } 20 | 21 | func main() { 22 | L := lua.NewState() 23 | defer L.Close() 24 | L.OpenLibs() 25 | 26 | L.GetGlobal("print") 27 | L.PushString("Hello World!") 28 | L.Call(1, 0) 29 | 30 | L.PushGoFunction(test) 31 | L.PushGoFunction(test) 32 | L.PushGoFunction(test) 33 | L.PushGoFunction(test) 34 | 35 | L.PushGoFunction(test2) 36 | L.PushInteger(42) 37 | L.Call(1, 0) 38 | 39 | L.Call(0, 0) 40 | L.Call(0, 0) 41 | L.Call(0, 0) 42 | 43 | // this will fail as we didn't register test2 function 44 | err := L.DoString("test2(42)") 45 | 46 | fmt.Printf("Ciao %v\n", err) 47 | } 48 | -------------------------------------------------------------------------------- /golua/lua/lua54/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | /* 22 | ** Encode major-minor version in one byte, one nibble for each 23 | */ 24 | #define MYINT(s) (s[0]-'0') /* assume one-digit numerals */ 25 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 26 | 27 | #define LUAC_FORMAT 0 /* this is the official format */ 28 | 29 | /* load one chunk; from lundump.c */ 30 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 31 | 32 | /* dump one chunk; from ldump.c */ 33 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 34 | void* data, int strip); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /golua/_example/dump_load.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aarzilli/golua/lua" 7 | ) 8 | 9 | // dumpAndLoadTest: dump a function chunk to bytecodes, then load bytecodes and call function 10 | func dumpAndLoadTest(L *lua.State) { 11 | loadret := L.LoadString(`print("msg from dump_and_load_test")`) 12 | if loadret != 0 { 13 | panic(fmt.Sprintf("LoadString error: %v", loadret)) 14 | } 15 | dumpret := L.Dump() 16 | if dumpret != 0 { 17 | panic(fmt.Sprintf("Dump error: %v", dumpret)) 18 | } 19 | 20 | isstring := L.IsString(-1) 21 | if !isstring { 22 | panic("stack top not a string") 23 | } 24 | bytecodes := L.ToBytes(-1) 25 | loadret = L.Load(bytecodes, "chunk_from_dump_and_load_test") 26 | if loadret != 0 { 27 | panic(fmt.Sprintf("Load error: %v", loadret)) 28 | } 29 | err := L.Call(0, 0) 30 | if err != nil { 31 | panic(fmt.Sprintf("Call error: %v", err)) 32 | } 33 | } 34 | 35 | func main() { 36 | L := lua.NewState() 37 | defer L.Close() 38 | L.OpenLibs() 39 | 40 | dumpAndLoadTest(L) 41 | } 42 | -------------------------------------------------------------------------------- /golua/lua/lua54/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /golua/lua/lua51/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (char* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | #ifdef luac_c 23 | /* print one chunk; from print.c */ 24 | LUAI_FUNC void luaU_print (const Proto* f, int full); 25 | #endif 26 | 27 | /* for header of binary files -- this is Lua 5.1 */ 28 | #define LUAC_VERSION 0x51 29 | 30 | /* for header of binary files -- this is the official format */ 31 | #define LUAC_FORMAT 0 32 | 33 | /* size of header of binary files */ 34 | #define LUAC_HEADERSIZE 12 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /golua/lua/lua53/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /ebook/ebook.go: -------------------------------------------------------------------------------- 1 | package ebook 2 | 3 | // IBook interface for variant ebook generators 4 | type IBook interface { 5 | Info() 6 | Begin() 7 | End() 8 | SetAuthor(string) 9 | SetTitle(string) 10 | AppendContent(string, string, string) 11 | SetMargins(float64, float64) 12 | SetPageType(string) 13 | SetPageSize(float64, float64) 14 | SetPDFFontSize(int, int) 15 | SetHTMLH1Font(string, string) 16 | SetHTMLH2Font(string, string) 17 | SetHTMLBodyFont(string, string) 18 | SetHTMLParaFont(string, string, string) 19 | SetLineSpacing(float64) 20 | SetFontFile(string) 21 | PagesPerFile(int) 22 | ChaptersPerFile(int) 23 | Output(string) 24 | } 25 | 26 | const ( 27 | creator = `GetNovel,仅限个人研究学习,对其造成的所有后果,软件/库作者不承担任何责任` 28 | ) 29 | 30 | // NewBook create an instance and return as an interface 31 | func NewBook(bookType string) IBook { 32 | switch bookType { 33 | case "pdf": 34 | return &pdfBook{} 35 | case "mobi": 36 | return &kindlegenMobiBook{} 37 | case "epub": 38 | return &epubBook{} 39 | case "html": 40 | return &singleHTMLBook{} 41 | default: 42 | return nil 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /luawrapper/luaapi.go: -------------------------------------------------------------------------------- 1 | package luawrapper 2 | 3 | import ( 4 | "github.com/aarzilli/golua/lua" 5 | "github.com/missdeer/golib/ic" 6 | "golang.org/x/net/html/charset" 7 | ) 8 | 9 | func ConvertEncoding(L *lua.State) int { 10 | fromEncoding := L.CheckString(1) 11 | toEncoding := L.CheckString(2) 12 | fromStr := L.CheckString(3) 13 | toStr := ic.ConvertString(fromEncoding, toEncoding, fromStr) 14 | L.PushString(toStr) 15 | return 1 16 | } 17 | 18 | func DetectContentCharset(L *lua.State) int { 19 | dataStr := L.CheckString(1) 20 | data := []byte(dataStr) 21 | if _, name, ok := charset.DetermineEncoding(data, ""); ok { 22 | L.PushString(name) 23 | return 1 24 | } 25 | L.PushString("utf-8") 26 | return 1 27 | } 28 | 29 | func RegisterLuaAPIs(L *lua.State) { 30 | // add string.convert(from, to, str) method 31 | L.GetGlobal("string") 32 | L.PushGoFunction(ConvertEncoding) 33 | L.SetField(-2, "convert") 34 | L.Pop(1) 35 | 36 | // add string.charsetdet(str) method 37 | L.GetGlobal("string") 38 | L.PushGoFunction(DetectContentCharset) 39 | L.SetField(-2, "charsetdet") 40 | L.Pop(1) 41 | } 42 | -------------------------------------------------------------------------------- /.github/workflows/go.tidy.yml: -------------------------------------------------------------------------------- 1 | name: go tidy 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | paths: 8 | - '.github/workflows/go.tidy.yml' 9 | - 'go.mod' 10 | - 'go.sum' 11 | 12 | jobs: 13 | fix: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - 17 | name: Checkout 18 | uses: actions/checkout@v2 19 | - 20 | name: Tidy 21 | run: | 22 | rm -f go.sum 23 | go mod tidy 24 | - 25 | name: Set up Git 26 | env: 27 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} 28 | run: | 29 | git config user.name "auto-go-mod-tidy[bot]" 30 | git config user.email "auto-go-mod-tidy[bot]@users.noreply.github.com" 31 | git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git 32 | - 33 | name: Commit and push changes 34 | run: | 35 | git add . 36 | if output=$(git status --porcelain) && [ ! -z "$output" ]; then 37 | git commit -m 'auto go mod tidy' 38 | git push 39 | fi 40 | -------------------------------------------------------------------------------- /golua/_example/error.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/aarzilli/golua/lua" 4 | import "fmt" 5 | import "errors" 6 | import "os" 7 | 8 | func testDefault(L *lua.State) { 9 | err := L.DoString("print(\"Unknown variable\" .. x)") 10 | fmt.Printf("Error is: %v\n", err) 11 | if err == nil { 12 | fmt.Printf("Error shouldn't have been nil\n") 13 | os.Exit(1) 14 | } 15 | } 16 | 17 | func faultyfunc(L *lua.State) int { 18 | panic(errors.New("An error")) 19 | } 20 | 21 | func testRegistered(L *lua.State) { 22 | L.Register("faultyfunc", faultyfunc) 23 | err := L.DoString("faultyfunc()") 24 | fmt.Printf("Error is %v\n", err) 25 | if err == nil { 26 | fmt.Printf("Error shouldn't have been nil\n") 27 | os.Exit(1) 28 | } 29 | } 30 | 31 | func test2(L *lua.State) { 32 | err := L.DoString("error(\"Some error\")") 33 | fmt.Printf("Error is %v\n", err) 34 | if err == nil { 35 | fmt.Printf("Error shouldn't have been nil\n") 36 | os.Exit(1) 37 | } 38 | } 39 | 40 | func main() { 41 | L := lua.NewState() 42 | defer L.Close() 43 | L.OpenLibs() 44 | 45 | testDefault(L) 46 | testRegistered(L) 47 | test2(L) 48 | } 49 | -------------------------------------------------------------------------------- /golua/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /golua/lua/lua52/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.8.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 29 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 30 | int pc); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /handlers/biquge.lua: -------------------------------------------------------------------------------- 1 | 2 | -- 定义 CanHandle 函数 3 | local function customCanHandle(url) 4 | -- ... CanHandle 的实现 5 | end 6 | 7 | -- 定义 PreprocessChapterListURL 函数 8 | local function customPreprocessChapterListURL(u) 9 | -- ... PreprocessChapterListURL 的实现 10 | end 11 | 12 | -- 定义 ExtractChapterList 函数 13 | local function customExtractChapterList(u, rawPageContent) 14 | -- ... 此处应放置解析章节列表的逻辑 15 | local title = "书名" -- 示例书名 16 | local chapters = { 17 | NovelChapterInfo(1, "第一章", "http://example.com/ch1"), 18 | NovelChapterInfo(2, "第二章", "http://example.com/ch2") 19 | -- ... 更多章节 20 | } 21 | return title, chapters 22 | end 23 | 24 | -- 定义 ExtractChapterContent 函数 25 | local function customExtractChapterContent(rawPageContent) 26 | -- ... ExtractChapterContent 的实现 27 | end 28 | 29 | -- 实例化 GetNovelSiteExternalHandler 并添加到 handlers 数组 30 | local handlerInstance = GetNovelSiteExternalHandler:new( 31 | "Example Handler", 32 | {"http://example.com", "http://example.net"}, 33 | customCanHandle, 34 | customPreprocessChapterListURL, 35 | customExtractChapterList, 36 | customExtractChapterContent 37 | ) 38 | 39 | RegisterHandler(handlerInstance) 40 | -------------------------------------------------------------------------------- /golua/lua/lua51/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 24 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, 25 | const TValue *p2); 26 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, 27 | const TValue *p2); 28 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); 29 | LUAI_FUNC void luaG_errormsg (lua_State *L); 30 | LUAI_FUNC int luaG_checkcode (const Proto *pt); 31 | LUAI_FUNC int luaG_checkopenop (Instruction i); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /golua/lua/lua52/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.7.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | /* Active Lua function (given call info) */ 21 | #define ci_func(ci) (clLvalue((ci)->func)) 22 | 23 | 24 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 25 | const char *opname); 26 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2); 27 | LUAI_FUNC l_noret luaG_aritherror (lua_State *L, const TValue *p1, 28 | const TValue *p2); 29 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 30 | const TValue *p2); 31 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 32 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /golua/lua/lua51/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_MOD, 29 | TM_POW, 30 | TM_UNM, 31 | TM_LEN, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | LUAI_DATA const char *const luaT_typenames[]; 47 | 48 | 49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 51 | TMS event); 52 | LUAI_FUNC void luaT_init (lua_State *L); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /golua/lua/lua51/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* Key to file-handle type */ 15 | #define LUA_FILEHANDLE "FILE*" 16 | 17 | 18 | #define LUA_COLIBNAME "coroutine" 19 | LUALIB_API int (luaopen_base) (lua_State *L); 20 | 21 | #define LUA_TABLIBNAME "table" 22 | LUALIB_API int (luaopen_table) (lua_State *L); 23 | 24 | #define LUA_IOLIBNAME "io" 25 | LUALIB_API int (luaopen_io) (lua_State *L); 26 | 27 | #define LUA_OSLIBNAME "os" 28 | LUALIB_API int (luaopen_os) (lua_State *L); 29 | 30 | #define LUA_STRLIBNAME "string" 31 | LUALIB_API int (luaopen_string) (lua_State *L); 32 | 33 | #define LUA_MATHLIBNAME "math" 34 | LUALIB_API int (luaopen_math) (lua_State *L); 35 | 36 | #define LUA_DBLIBNAME "debug" 37 | LUALIB_API int (luaopen_debug) (lua_State *L); 38 | 39 | #define LUA_LOADLIBNAME "package" 40 | LUALIB_API int (luaopen_package) (lua_State *L); 41 | 42 | 43 | /* open all previous libraries */ 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); 45 | 46 | 47 | 48 | #ifndef lua_assert 49 | #define lua_assert(x) ((void)0) 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /golua/lua/lua51/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); 29 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 30 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 31 | int pc); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /golua/lua/lua51/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 30 | StkId val); 31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 32 | StkId val); 33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); 34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /golua/_example/alloc.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/aarzilli/golua/lua" 4 | import "unsafe" 5 | import "fmt" 6 | 7 | var refHolder = map[unsafe.Pointer][]byte{} 8 | 9 | //a terrible allocator! 10 | //meant to be illustrative of the mechanics, 11 | //not usable as an actual implementation 12 | func AllocatorF(ptr unsafe.Pointer, osize uint, nsize uint) unsafe.Pointer { 13 | if nsize == 0 { 14 | if _, ok := refHolder[ptr]; ok { 15 | delete(refHolder, ptr) 16 | } 17 | ptr = unsafe.Pointer(nil) 18 | } else if osize != nsize { 19 | slice := make([]byte, nsize) 20 | 21 | if oldslice, ok := refHolder[ptr]; ok { 22 | copy(slice, oldslice) 23 | _ = oldslice 24 | delete(refHolder, ptr) 25 | } 26 | 27 | ptr = unsafe.Pointer(&(slice[0])) 28 | refHolder[ptr] = slice 29 | } 30 | //fmt.Println("in allocf"); 31 | return ptr 32 | } 33 | 34 | func A2(ptr unsafe.Pointer, osize uint, nsize uint) unsafe.Pointer { 35 | return AllocatorF(ptr, osize, nsize) 36 | } 37 | 38 | func main() { 39 | 40 | //refHolder = make([][]byte,0,500); 41 | 42 | L := lua.NewStateAlloc(AllocatorF) 43 | defer L.Close() 44 | L.OpenLibs() 45 | 46 | L.SetAllocf(A2) 47 | 48 | for i := 0; i < 10; i++ { 49 | L.GetGlobal("print") 50 | L.PushString("Hello World!") 51 | L.Call(1, 0) 52 | } 53 | 54 | fmt.Println(len(refHolder)) 55 | } 56 | -------------------------------------------------------------------------------- /golua/lua/lua52/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.43.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_BITLIBNAME "bit32" 33 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 34 | 35 | #define LUA_MATHLIBNAME "math" 36 | LUAMOD_API int (luaopen_math) (lua_State *L); 37 | 38 | #define LUA_DBLIBNAME "debug" 39 | LUAMOD_API int (luaopen_debug) (lua_State *L); 40 | 41 | #define LUA_LOADLIBNAME "package" 42 | LUAMOD_API int (luaopen_package) (lua_State *L); 43 | 44 | 45 | /* open all previous libraries */ 46 | LUALIB_API void (luaL_openlibs) (lua_State *L); 47 | 48 | 49 | 50 | #if !defined(lua_assert) 51 | #define lua_assert(x) ((void)0) 52 | #endif 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /golua/lua/lua54/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /golua/lua/lua51/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.nk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define key2tval(n) (&(n)->i_key.tvk) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); 22 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 24 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); 25 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 26 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 27 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); 28 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 29 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 30 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 31 | LUAI_FUNC int luaH_getn (Table *t); 32 | 33 | 34 | #if defined(LUA_DEBUG) 35 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 36 | LUAI_FUNC int luaH_isdummy (Node *n); 37 | #endif 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /golua/lua/lua52/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.11.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with `fast' access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_DIV, 29 | TM_MOD, 30 | TM_POW, 31 | TM_UNM, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | #define ttypename(x) luaT_typenames_[(x) + 1] 47 | #define objtypename(x) ttypename(ttypenv(x)) 48 | 49 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 50 | 51 | 52 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 53 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 54 | TMS event); 55 | LUAI_FUNC void luaT_init (lua_State *L); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /config/novel.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/missdeer/getnovel/ebook" 7 | ) 8 | 9 | type TOCPattern struct { 10 | Host string 11 | BookTitle string 12 | BookTitlePos int 13 | Item string 14 | ArticleTitlePos int 15 | ArticleURLPos int 16 | IsAbsoluteURL bool 17 | } 18 | 19 | type PageContentMarker struct { 20 | Host string 21 | Start []byte 22 | End []byte 23 | } 24 | 25 | type NovelChapterInfo struct { 26 | Index int 27 | Title string 28 | URL string 29 | } 30 | 31 | type NovelSite struct { 32 | Title string 33 | Urls []string 34 | } 35 | 36 | type NovelSiteHandler struct { 37 | Sites []NovelSite 38 | CanHandle func(string) bool // (url) -> can handle 39 | PreprocessChapterListURL func(string) string // (original url) -> final url 40 | ExtractChapterList func(string, []byte) (string, []*NovelChapterInfo) // (url, raw page content) (title, chapters) 41 | ExtractChapterContent func(string, []byte) []byte // (raw page content) -> cleanup content 42 | PreprocessContentLink func(string) (string, http.Header) // (url) -> (final url, headers) 43 | Download func(string, ebook.IBook) 44 | Begin func() 45 | End func() 46 | } 47 | -------------------------------------------------------------------------------- /golua/lua/golua.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct { void *t; void *v; } GoInterface; 4 | 5 | #define GOLUA_DEFAULT_MSGHANDLER "golua_default_msghandler" 6 | 7 | /* function to setup metatables, etc */ 8 | void clua_initstate(lua_State* L); 9 | void clua_hide_pcall(lua_State *L); 10 | 11 | unsigned int clua_togofunction(lua_State* L, int index); 12 | unsigned int clua_togostruct(lua_State *L, int index); 13 | void clua_pushcallback(lua_State* L); 14 | void clua_pushgofunction(lua_State* L, unsigned int fid); 15 | void clua_pushgostruct(lua_State *L, unsigned int fid); 16 | void clua_setgostate(lua_State* L, size_t gostateindex); 17 | int dump_chunk (lua_State *L); 18 | int load_chunk(lua_State *L, const char *b, int size, const char* chunk_name); 19 | size_t clua_getgostate(lua_State* L); 20 | GoInterface clua_atpanic(lua_State* L, unsigned int panicf_id); 21 | int clua_callluacfunc(lua_State* L, lua_CFunction f); 22 | lua_State* clua_newstate(void* goallocf); 23 | void clua_setallocf(lua_State* L, void* goallocf); 24 | 25 | void clua_openbase(lua_State* L); 26 | void clua_openio(lua_State* L); 27 | void clua_openmath(lua_State* L); 28 | void clua_openpackage(lua_State* L); 29 | void clua_openstring(lua_State* L); 30 | void clua_opentable(lua_State* L); 31 | void clua_openos(lua_State* L); 32 | void clua_sethook(lua_State* L, int n); 33 | 34 | int clua_isgofunction(lua_State *L, int n); 35 | int clua_isgostruct(lua_State *L, int n); 36 | 37 | -------------------------------------------------------------------------------- /golua/lua/lua52/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.49.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 16 | 17 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 18 | 19 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 20 | (sizeof(s)/sizeof(char))-1)) 21 | 22 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 23 | 24 | 25 | /* 26 | ** test whether a string is a reserved word 27 | */ 28 | #define isreserved(s) ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0) 29 | 30 | 31 | /* 32 | ** equality for short strings, which are always internalized 33 | */ 34 | #define eqshrstr(a,b) check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b)) 35 | 36 | 37 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC int luaS_eqstr (TString *a, TString *b); 40 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 41 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 42 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 43 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /golua/lua/lua53/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_BITLIBNAME "bit32" 39 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 40 | 41 | #define LUA_MATHLIBNAME "math" 42 | LUAMOD_API int (luaopen_math) (lua_State *L); 43 | 44 | #define LUA_DBLIBNAME "debug" 45 | LUAMOD_API int (luaopen_debug) (lua_State *L); 46 | 47 | #define LUA_LOADLIBNAME "package" 48 | LUAMOD_API int (luaopen_package) (lua_State *L); 49 | 50 | 51 | /* open all previous libraries */ 52 | LUALIB_API void (luaL_openlibs) (lua_State *L); 53 | 54 | 55 | 56 | #if !defined(lua_assert) 57 | #define lua_assert(x) ((void)0) 58 | #endif 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /golua/lua/lua52/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.16.1.2 2013/08/30 15:49:41 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.tvk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define invalidateTMcache(t) ((t)->flags = 0) 19 | 20 | /* returns the key, given the value of a table entry */ 21 | #define keyfromval(v) \ 22 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 23 | 24 | 25 | LUAI_FUNC const TValue *luaH_getint (Table *t, int key); 26 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value); 27 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 28 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 29 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 30 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 31 | LUAI_FUNC Table *luaH_new (lua_State *L); 32 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize); 33 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 34 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 35 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 36 | LUAI_FUNC int luaH_getn (Table *t); 37 | 38 | 39 | #if defined(LUA_DEBUG) 40 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 41 | LUAI_FUNC int luaH_isdummy (Node *n); 42 | #endif 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /golua/lua/lua53/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.14.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 24 | const TValue *p2); 25 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 26 | const TValue *p2, 27 | const char *msg); 28 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 29 | const TValue *p2); 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 31 | const TValue *p2); 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 33 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 34 | TString *src, int line); 35 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 36 | LUAI_FUNC void luaG_traceexec (lua_State *L); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /golua/lua/lua54/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /golua/lua/lua54/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* Increments 'L->top.p', checking for stack overflows */ 16 | #define api_incr_top(L) {L->top.p++; \ 17 | api_check(L, L->top.p <= L->ci->top.p, \ 18 | "stack overflow");} 19 | 20 | 21 | /* 22 | ** If a call returns too many multiple returns, the callee may not have 23 | ** stack space to accommodate all results. In this case, this macro 24 | ** increases its stack space ('L->ci->top.p'). 25 | */ 26 | #define adjustresults(L,nres) \ 27 | { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \ 28 | L->ci->top.p = L->top.p; } 29 | 30 | 31 | /* Ensure the stack has at least 'n' elements */ 32 | #define api_checknelems(L,n) \ 33 | api_check(L, (n) < (L->top.p - L->ci->func.p), \ 34 | "not enough elements in the stack") 35 | 36 | 37 | /* 38 | ** To reduce the overhead of returning from C functions, the presence of 39 | ** to-be-closed variables in these functions is coded in the CallInfo's 40 | ** field 'nresults', in a way that functions with no to-be-closed variables 41 | ** with zero, one, or "all" wanted results have no overhead. Functions 42 | ** with other number of wanted results, as well as functions with 43 | ** variables to be closed, have an extra check. 44 | */ 45 | 46 | #define hastocloseCfunc(n) ((n) < LUA_MULTRET) 47 | 48 | /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */ 49 | #define codeNresults(n) (-(n) - 3) 50 | #define decodeNresults(n) (-(n) - 3) 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /golua/lua/lua52/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.18.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) (ttisstring(o) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttisnumber(o) || (((o) = luaV_tonumber(o,n)) != NULL)) 19 | 20 | #define equalobj(L,o1,o2) (ttisequal(o1, o2) && luaV_equalobj_(L, o1, o2)) 21 | 22 | #define luaV_rawequalobj(o1,o2) equalobj(NULL,o1,o2) 23 | 24 | 25 | /* not to called directly */ 26 | LUAI_FUNC int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2); 27 | 28 | 29 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 30 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 31 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 32 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 33 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 34 | StkId val); 35 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 36 | StkId val); 37 | LUAI_FUNC void luaV_finishOp (lua_State *L); 38 | LUAI_FUNC void luaV_execute (lua_State *L); 39 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 40 | LUAI_FUNC void luaV_arith (lua_State *L, StkId ra, const TValue *rb, 41 | const TValue *rc, TMS op); 42 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /golua/lua/lua53/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.61.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | 17 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 18 | #define sizeudata(u) sizeludata((u)->len) 19 | 20 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 21 | (sizeof(s)/sizeof(char))-1)) 22 | 23 | 24 | /* 25 | ** test whether a string is a reserved word 26 | */ 27 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 28 | 29 | 30 | /* 31 | ** equality for short strings, which are always internalized 32 | */ 33 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 34 | 35 | 36 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 37 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_clearcache (global_State *g); 41 | LUAI_FUNC void luaS_init (lua_State *L); 42 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 43 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 44 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 45 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 46 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /golua/lua/lua53/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.37.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /ebook/bs/book_test.go: -------------------------------------------------------------------------------- 1 | package bs 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "sort" 7 | "testing" 8 | ) 9 | 10 | func setupBookSources() { 11 | if allBookSources.Length() != 0 { 12 | log.Println("Already have", allBookSources.Length(), "book sources totally") 13 | return 14 | } 15 | for _, u := range bookSourceURLs { 16 | bss := ReadBookSourceFromURL(u) 17 | log.Println("Got", len(bss), "book sources from", u) 18 | // for _, bs := range bss { 19 | // log.Println(bs.BookSourceGroup, "Book source", bs.BookSourceName, "at", bs.BookSourceURL) 20 | // } 21 | } 22 | sort.Sort(ByBookSourceURL(allBookSources.BookSourceCollection)) 23 | log.Println("Got", allBookSources.Length(), "book sources totally") 24 | } 25 | 26 | func TestBook(t *testing.T) { 27 | setupBookSources() 28 | book, err := NewBookFromURL("https://www.mangg.net/id68990/") 29 | if err != nil { 30 | t.Error(err) 31 | } 32 | if book == nil { 33 | t.Error("no matched book source") 34 | } 35 | fmt.Println("===========Book Start===========") 36 | chapters := book.GetChapterList() 37 | fmt.Printf("Got %d chapters\n", len(chapters)) 38 | fmt.Printf("Chapter 1 url: %s\n", chapters[0].ChapterURL) 39 | fmt.Printf("Chapter 1 title: %s\n", chapters[0].GetTitle()) 40 | fmt.Printf("Chapter 1 content: %s\n", chapters[0].GetContent()) 41 | fmt.Printf("Book name: %v\n", book.GetName()) 42 | fmt.Printf("Book introduce: %v\n", book.GetIntroduce()) 43 | fmt.Printf("Book author: %v\n", book.GetAuthor()) 44 | if book.BookSourceInst == nil { 45 | t.Error("no matched book source") 46 | } 47 | fmt.Println("Found book source:", *book.BookSourceInst) 48 | fmt.Println("===========Book End=============") 49 | } 50 | -------------------------------------------------------------------------------- /golua/lua/lua51/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | #define MEMERRMSG "not enough memory" 17 | 18 | 19 | #define luaM_reallocv(L,b,on,n,e) \ 20 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ 21 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ 22 | luaM_toobig(L)) 23 | 24 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 25 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 26 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 27 | 28 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) 29 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 30 | #define luaM_newvector(L,n,t) \ 31 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 32 | 33 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 34 | if ((nelems)+1 > (size)) \ 35 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 36 | 37 | #define luaM_reallocvector(L, v,oldn,n,t) \ 38 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 39 | 40 | 41 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 42 | size_t size); 43 | LUAI_FUNC void *luaM_toobig (lua_State *L); 44 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 45 | size_t size_elem, int limit, 46 | const char *errormsg); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /golua/lua/lua52/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.20.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) if (L->stack_last - L->top <= (n)) \ 17 | luaD_growstack(L, n); else condmovestack(L); 18 | 19 | 20 | #define incr_top(L) {L->top++; luaD_checkstack(L,0);} 21 | 22 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 23 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 24 | 25 | 26 | /* type of protected functions, to be ran by `runprotected' */ 27 | typedef void (*Pfunc) (lua_State *L, void *ud); 28 | 29 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 30 | const char *mode); 31 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 32 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 33 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults, 34 | int allowyield); 35 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 36 | ptrdiff_t oldtop, ptrdiff_t ef); 37 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 38 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 39 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 40 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 41 | 42 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 43 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /golua/lua/lua54/lopnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopnames.h $ 3 | ** Opcode names 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #if !defined(lopnames_h) 8 | #define lopnames_h 9 | 10 | #include 11 | 12 | 13 | /* ORDER OP */ 14 | 15 | static const char *const opnames[] = { 16 | "MOVE", 17 | "LOADI", 18 | "LOADF", 19 | "LOADK", 20 | "LOADKX", 21 | "LOADFALSE", 22 | "LFALSESKIP", 23 | "LOADTRUE", 24 | "LOADNIL", 25 | "GETUPVAL", 26 | "SETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "GETI", 30 | "GETFIELD", 31 | "SETTABUP", 32 | "SETTABLE", 33 | "SETI", 34 | "SETFIELD", 35 | "NEWTABLE", 36 | "SELF", 37 | "ADDI", 38 | "ADDK", 39 | "SUBK", 40 | "MULK", 41 | "MODK", 42 | "POWK", 43 | "DIVK", 44 | "IDIVK", 45 | "BANDK", 46 | "BORK", 47 | "BXORK", 48 | "SHRI", 49 | "SHLI", 50 | "ADD", 51 | "SUB", 52 | "MUL", 53 | "MOD", 54 | "POW", 55 | "DIV", 56 | "IDIV", 57 | "BAND", 58 | "BOR", 59 | "BXOR", 60 | "SHL", 61 | "SHR", 62 | "MMBIN", 63 | "MMBINI", 64 | "MMBINK", 65 | "UNM", 66 | "BNOT", 67 | "NOT", 68 | "LEN", 69 | "CONCAT", 70 | "CLOSE", 71 | "TBC", 72 | "JMP", 73 | "EQ", 74 | "LT", 75 | "LE", 76 | "EQK", 77 | "EQI", 78 | "LTI", 79 | "LEI", 80 | "GTI", 81 | "GEI", 82 | "TEST", 83 | "TESTSET", 84 | "CALL", 85 | "TAILCALL", 86 | "RETURN", 87 | "RETURN0", 88 | "RETURN1", 89 | "FORLOOP", 90 | "FORPREP", 91 | "TFORPREP", 92 | "TFORCALL", 93 | "TFORLOOP", 94 | "SETLIST", 95 | "CLOSURE", 96 | "VARARG", 97 | "VARARGPREP", 98 | "EXTRAARG", 99 | NULL 100 | }; 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /golua/lua/lua54/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /golua/lua/buildlua.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | OS=$(uname -s) 4 | CoreCount=1 5 | 6 | case "$OS" in 7 | "Darwin") 8 | PLAT="macosx" 9 | CoreCount=$(getconf _NPROCESSORS_ONLN) 10 | ;; 11 | "Linux") 12 | PLAT="linux" 13 | CoreCount=$(getconf _NPROCESSORS_ONLN) 14 | ;; 15 | "MINGW"* | "MSYS_NT"*) 16 | PLAT="mingw" 17 | CoreCount=$(nproc) 18 | ;; 19 | "FreeBSD" | "NetBSD" | "OpenBSD" | "DragonFly") 20 | PLAT="freebsd" 21 | CoreCount=$(getconf _NPROCESSORS_ONLN) 22 | ;; 23 | esac 24 | echo $PLAT 25 | 26 | find . -name 'lua*' -type d | while read dir; do 27 | echo $dir $PLAT 28 | cd $dir 29 | make clean 30 | if [ "$OS" == "Darwin" ]; then 31 | make MYCFLAGS="-arch x86_64 -arch arm64" MYLDFLAGS="-arch x86_64 -arch arm64" $PLAT -j $CoreCount 32 | else 33 | make $PLAT -j $CoreCount 34 | fi 35 | cd .. 36 | done 37 | 38 | if [ ! -d luajit ]; then 39 | curl -sSL -o LuaJIT.zip https://codeload.github.com/LuaJIT/LuaJIT/zip/refs/heads/v2.1 40 | unzip -q LuaJIT.zip 41 | mv LuaJIT-2.1 luajit 42 | fi 43 | cd luajit 44 | if [ "$OS" == "Darwin" ]; then 45 | env MACOSX_DEPLOYMENT_TARGET=12.0 make clean 46 | env MACOSX_DEPLOYMENT_TARGET=12.0 CFLAGS="-arch x86_64" LDFLAGS="-arch x86_64" make -j $CoreCount BUILDMODE=static 47 | arch=$(uname -m) 48 | if [ "$arch" == "arm64" ]; then 49 | mv src/libluajit.a ./libluajit-amd64.a 50 | env MACOSX_DEPLOYMENT_TARGET=12.0 make clean 51 | env MACOSX_DEPLOYMENT_TARGET=12.0 CFLAGS="-arch arm64" LDFLAGS="-arch arm64" make -j $CoreCount BUILDMODE=static 52 | mv src/libluajit.a ./libluajit-arm64.a 53 | lipo -create -output libluajit.a libluajit-arm64.a libluajit-amd64.a 54 | else 55 | mv src/libluajit.a ./libluajit.a 56 | fi 57 | else 58 | make -j $CoreCount BUILDMODE=static 59 | mv src/*.a ./libluajit.a 60 | fi 61 | cd .. 62 | -------------------------------------------------------------------------------- /golua/lua/lua52/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.26.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 36 | 37 | 38 | #define luaZ_resizebuffer(L, buff, size) \ 39 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 40 | (buff)->buffsize = size) 41 | 42 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 43 | 44 | 45 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 46 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 47 | void *data); 48 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 49 | 50 | 51 | 52 | /* --------- Private Part ------------------ */ 53 | 54 | struct Zio { 55 | size_t n; /* bytes still unread */ 56 | const char *p; /* current position in buffer */ 57 | lua_Reader reader; /* reader function */ 58 | void* data; /* additional data */ 59 | lua_State *L; /* Lua state (for reader) */ 60 | }; 61 | 62 | 63 | LUAI_FUNC int luaZ_fill (ZIO *z); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /golua/lua/lua53/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /golua/lua/lua51/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define char2int(c) cast(int, cast(unsigned char, (c))) 21 | 22 | #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) 23 | 24 | typedef struct Mbuffer { 25 | char *buffer; 26 | size_t n; 27 | size_t buffsize; 28 | } Mbuffer; 29 | 30 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 31 | 32 | #define luaZ_buffer(buff) ((buff)->buffer) 33 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 34 | #define luaZ_bufflen(buff) ((buff)->n) 35 | 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 41 | (buff)->buffsize = size) 42 | 43 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 44 | 45 | 46 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 50 | LUAI_FUNC int luaZ_lookahead (ZIO *z); 51 | 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; 60 | void* data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /golua/lua/lua54/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* 16 | ** Memory-allocation error message must be preallocated (it cannot 17 | ** be created after memory is exhausted) 18 | */ 19 | #define MEMERRMSG "not enough memory" 20 | 21 | 22 | /* 23 | ** Size of a TString: Size of the header plus space for the string 24 | ** itself (including final '\0'). 25 | */ 26 | #define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char)) 27 | 28 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 29 | (sizeof(s)/sizeof(char))-1)) 30 | 31 | 32 | /* 33 | ** test whether a string is a reserved word 34 | */ 35 | #define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0) 36 | 37 | 38 | /* 39 | ** equality for short strings, which are always internalized 40 | */ 41 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b)) 42 | 43 | 44 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 45 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 46 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 47 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 48 | LUAI_FUNC void luaS_clearcache (global_State *g); 49 | LUAI_FUNC void luaS_init (lua_State *L); 50 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 51 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); 52 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 53 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 54 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /golua/lua/lua53/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15.1.1 2017/04/19 17:39:34 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | /* 33 | ** Upvalues for Lua closures 34 | */ 35 | struct UpVal { 36 | TValue *v; /* points to stack or to its own value */ 37 | lu_mem refcount; /* reference counter */ 38 | union { 39 | struct { /* (when open) */ 40 | UpVal *next; /* linked list */ 41 | int touched; /* mark to avoid cycles with dead threads */ 42 | } open; 43 | TValue value; /* the value (when closed) */ 44 | } u; 45 | }; 46 | 47 | #define upisopen(up) ((up)->v != &(up)->u.value) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 57 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 58 | int pc); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /golua/lua/lua54/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {LUA_GNAME, luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | {NULL, NULL} 54 | }; 55 | 56 | 57 | LUALIB_API void luaL_openlibs (lua_State *L) { 58 | const luaL_Reg *lib; 59 | /* "require" functions from 'loadedlibs' and set results to global table */ 60 | for (lib = loadedlibs; lib->func; lib++) { 61 | luaL_requiref(L, lib->name, lib->func, 1); 62 | lua_pop(L, 1); /* remove lib */ 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /golua/lua/lua52/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.35.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) 29 | return EOZ; 30 | z->n = size - 1; /* discount char being returned */ 31 | z->p = buff; 32 | return cast_uchar(*(z->p++)); 33 | } 34 | 35 | 36 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 37 | z->L = L; 38 | z->reader = reader; 39 | z->data = data; 40 | z->n = 0; 41 | z->p = NULL; 42 | } 43 | 44 | 45 | /* --------------------------------------------------------------- read --- */ 46 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 47 | while (n) { 48 | size_t m; 49 | if (z->n == 0) { /* no bytes in buffer? */ 50 | if (luaZ_fill(z) == EOZ) /* try to read more */ 51 | return n; /* no more input; return number of missing bytes */ 52 | else { 53 | z->n++; /* luaZ_fill consumed first byte; put it back */ 54 | z->p--; 55 | } 56 | } 57 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 58 | memcpy(b, z->p, m); 59 | z->n -= m; 60 | z->p += m; 61 | b = (char *)b + m; 62 | n -= m; 63 | } 64 | return 0; 65 | } 66 | 67 | /* ------------------------------------------------------------------------ */ 68 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 69 | if (n > buff->buffsize) { 70 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 71 | luaZ_resizebuffer(L, buff, n); 72 | } 73 | return buff->buffer; 74 | } 75 | 76 | 77 | -------------------------------------------------------------------------------- /golua/lua/lua51/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define ltm_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lobject.h" 16 | #include "lstate.h" 17 | #include "lstring.h" 18 | #include "ltable.h" 19 | #include "ltm.h" 20 | 21 | 22 | 23 | const char *const luaT_typenames[] = { 24 | "nil", "boolean", "userdata", "number", 25 | "string", "table", "function", "userdata", "thread", 26 | "proto", "upval" 27 | }; 28 | 29 | 30 | void luaT_init (lua_State *L) { 31 | static const char *const luaT_eventname[] = { /* ORDER TM */ 32 | "__index", "__newindex", 33 | "__gc", "__mode", "__eq", 34 | "__add", "__sub", "__mul", "__div", "__mod", 35 | "__pow", "__unm", "__len", "__lt", "__le", 36 | "__concat", "__call" 37 | }; 38 | int i; 39 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 41 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ 42 | } 43 | } 44 | 45 | 46 | /* 47 | ** function to be used with macro "fasttm": optimized for absence of 48 | ** tag methods 49 | */ 50 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 51 | const TValue *tm = luaH_getstr(events, ename); 52 | lua_assert(event <= TM_EQ); 53 | if (ttisnil(tm)) { /* no tag method? */ 54 | events->flags |= cast_byte(1u<metatable; 66 | break; 67 | case LUA_TUSERDATA: 68 | mt = uvalue(o)->metatable; 69 | break; 70 | default: 71 | mt = G(L)->mt[ttype(o)]; 72 | } 73 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 74 | } 75 | 76 | -------------------------------------------------------------------------------- /golua/lua/lua52/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.32.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | /* 9 | ** If you embed Lua in your program and need to open the standard 10 | ** libraries, call luaL_openlibs in your program. If you need a 11 | ** different set of libraries, copy this file to your project and edit 12 | ** it to suit your needs. 13 | */ 14 | 15 | 16 | #define linit_c 17 | #define LUA_LIB 18 | 19 | #include "lua.h" 20 | 21 | #include "lualib.h" 22 | #include "lauxlib.h" 23 | 24 | 25 | /* 26 | ** these libs are loaded by lua.c and are readily available to any Lua 27 | ** program 28 | */ 29 | static const luaL_Reg loadedlibs[] = { 30 | {"_G", luaopen_base}, 31 | {LUA_LOADLIBNAME, luaopen_package}, 32 | {LUA_COLIBNAME, luaopen_coroutine}, 33 | {LUA_TABLIBNAME, luaopen_table}, 34 | {LUA_IOLIBNAME, luaopen_io}, 35 | {LUA_OSLIBNAME, luaopen_os}, 36 | {LUA_STRLIBNAME, luaopen_string}, 37 | {LUA_BITLIBNAME, luaopen_bit32}, 38 | {LUA_MATHLIBNAME, luaopen_math}, 39 | {LUA_DBLIBNAME, luaopen_debug}, 40 | {NULL, NULL} 41 | }; 42 | 43 | 44 | /* 45 | ** these libs are preloaded and must be required before used 46 | */ 47 | static const luaL_Reg preloadedlibs[] = { 48 | {NULL, NULL} 49 | }; 50 | 51 | 52 | LUALIB_API void luaL_openlibs (lua_State *L) { 53 | const luaL_Reg *lib; 54 | /* call open functions from 'loadedlibs' and set results to global table */ 55 | for (lib = loadedlibs; lib->func; lib++) { 56 | luaL_requiref(L, lib->name, lib->func, 1); 57 | lua_pop(L, 1); /* remove lib */ 58 | } 59 | /* add open functions from 'preloadedlibs' into 'package.preload' table */ 60 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 61 | for (lib = preloadedlibs; lib->func; lib++) { 62 | lua_pushcfunction(L, lib->func); 63 | lua_setfield(L, -2, lib->name); 64 | } 65 | lua_pop(L, 1); /* remove _PRELOAD table */ 66 | } 67 | 68 | -------------------------------------------------------------------------------- /golua/lua/lua54/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \ 15 | cast_int(sizeof(TValue)) * (n)) 16 | 17 | #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \ 18 | cast_int(sizeof(TValue *)) * (n)) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | #define upisopen(up) ((up)->v.p != &(up)->u.value) 33 | 34 | 35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v.p)) 36 | 37 | 38 | /* 39 | ** maximum number of misses before giving up the cache of closures 40 | ** in prototypes 41 | */ 42 | #define MAXMISS 10 43 | 44 | 45 | 46 | /* special status to close upvalues preserving the top of the stack */ 47 | #define CLOSEKTOP (-1) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 57 | LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy); 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 59 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 60 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 61 | int pc); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /golua/lua/lua51/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** a generic input stream interface 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) return EOZ; 29 | z->n = size - 1; 30 | z->p = buff; 31 | return char2int(*(z->p++)); 32 | } 33 | 34 | 35 | int luaZ_lookahead (ZIO *z) { 36 | if (z->n == 0) { 37 | if (luaZ_fill(z) == EOZ) 38 | return EOZ; 39 | else { 40 | z->n++; /* luaZ_fill removed first byte; put back it */ 41 | z->p--; 42 | } 43 | } 44 | return char2int(*z->p); 45 | } 46 | 47 | 48 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 49 | z->L = L; 50 | z->reader = reader; 51 | z->data = data; 52 | z->n = 0; 53 | z->p = NULL; 54 | } 55 | 56 | 57 | /* --------------------------------------------------------------- read --- */ 58 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 59 | while (n) { 60 | size_t m; 61 | if (luaZ_lookahead(z) == EOZ) 62 | return n; /* return number of missing bytes */ 63 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 64 | memcpy(b, z->p, m); 65 | z->n -= m; 66 | z->p += m; 67 | b = (char *)b + m; 68 | n -= m; 69 | } 70 | return 0; 71 | } 72 | 73 | /* ------------------------------------------------------------------------ */ 74 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 75 | if (n > buff->buffsize) { 76 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 77 | luaZ_resizebuffer(L, buff, n); 78 | } 79 | return buff->buffer; 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /golua/lua/lua53/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {"_G", luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | #if defined(LUA_COMPAT_BITLIB) 54 | {LUA_BITLIBNAME, luaopen_bit32}, 55 | #endif 56 | {NULL, NULL} 57 | }; 58 | 59 | 60 | LUALIB_API void luaL_openlibs (lua_State *L) { 61 | const luaL_Reg *lib; 62 | /* "require" functions from 'loadedlibs' and set results to global table */ 63 | for (lib = loadedlibs; lib->func; lib++) { 64 | luaL_requiref(L, lib->name, lib->func, 1); 65 | lua_pop(L, 1); /* remove lib */ 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /golua/lua/lua52/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.40.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro avoids the runtime division MAX_SIZET/(e), as 'e' is 19 | ** always constant. 20 | ** The macro is somewhat complex to avoid warnings: 21 | ** +1 avoids warnings of "comparison has constant result"; 22 | ** cast to 'void' avoids warnings of "value unused". 23 | */ 24 | #define luaM_reallocv(L,b,on,n,e) \ 25 | (cast(void, \ 26 | (cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \ 27 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 28 | 29 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 30 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 31 | #define luaM_freearray(L, b, n) luaM_reallocv(L, (b), n, 0, sizeof((b)[0])) 32 | 33 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 34 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 35 | #define luaM_newvector(L,n,t) \ 36 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 37 | 38 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 39 | 40 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 41 | if ((nelems)+1 > (size)) \ 42 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 43 | 44 | #define luaM_reallocvector(L, v,oldn,n,t) \ 45 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 46 | 47 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 48 | 49 | /* not to be called directly */ 50 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 51 | size_t size); 52 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 53 | size_t size_elem, int limit, 54 | const char *what); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /ebook/bs/bs3.go: -------------------------------------------------------------------------------- 1 | package bs 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // BookSourceV3 book source structure 8 | type BookSourceV3 struct { 9 | BookSourceGroup string `json:"bookSourceGroup"` 10 | BookSourceName string `json:"bookSourceName"` 11 | BookSourceURL string `json:"bookSourceUrl"` 12 | Enable bool `json:"enabled"` 13 | Header string `json:"header"` 14 | RuleBookInfo struct { 15 | Author string `json:"author"` 16 | CoverURL string `json:"coverUrl"` 17 | Intro string `json:"intro"` 18 | Kind string `json:"kind"` 19 | LastChapter string `json:"lastChapter"` 20 | Name string `json:"name"` 21 | TOCURL string `json:"tocUrl"` 22 | } `json:"ruleBookInfo"` 23 | RuleContent struct { 24 | Content string `json:"content"` 25 | NextContentURL string `json:"nextContentUrl"` 26 | SourceRegex string `json:"sourceRegex"` 27 | } `json:"ruleContent"` 28 | RuleExplore struct { 29 | Author string `json:"author"` 30 | BookList string `json:"bookList"` 31 | BookURL string `json:"bookUrl"` 32 | CoverURL string `json:"coverUrl"` 33 | Intro string `json:"intro"` 34 | Kind string `json:"kind"` 35 | LastChapter string `json:"lastChapter"` 36 | Name string `json:"name"` 37 | } `json:"ruleExplore"` 38 | RuleSearch struct { 39 | Author string `json:"author"` 40 | BookList string `json:"bookList"` 41 | BookURL string `json:"bookUrl"` 42 | CoverURL string `json:"coverUrl"` 43 | Intro string `json:"intro"` 44 | Kind string `json:"kind"` 45 | LastChapter string `json:"lastChapter"` 46 | Name string `json:"name"` 47 | } `json:"ruleSearch"` 48 | RuleTOC struct { 49 | ChapterList string `json:"chapterList"` 50 | ChapterName string `json:"chapterName"` 51 | ChapterURL string `json:"chapterUrl"` 52 | } `json:"ruleToc"` 53 | SearchURL string `json:"searchUrl"` 54 | Weight int `json:"weight"` 55 | } 56 | 57 | func (bs BookSourceV3) String() string { 58 | return fmt.Sprintf("%s( %s )", bs.BookSourceName, bs.BookSourceURL) 59 | } 60 | -------------------------------------------------------------------------------- /golua/lua/lua53/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.22.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | 55 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 56 | 57 | 58 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 59 | 60 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 61 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 62 | TMS event); 63 | LUAI_FUNC void luaT_init (lua_State *L); 64 | 65 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 66 | const TValue *p2, TValue *p3, int hasres); 67 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 68 | StkId res, TMS event); 69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 70 | StkId res, TMS event); 71 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 72 | const TValue *p2, TMS event); 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /golua/lua/lua51/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) \ 17 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ 18 | luaD_growstack(L, n); \ 19 | else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); 20 | 21 | 22 | #define incr_top(L) {luaD_checkstack(L,1); L->top++;} 23 | 24 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 25 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 26 | 27 | #define saveci(L,p) ((char *)(p) - (char *)L->base_ci) 28 | #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) 29 | 30 | 31 | /* results from luaD_precall */ 32 | #define PCRLUA 0 /* initiated a call to a Lua function */ 33 | #define PCRC 1 /* did a call to a C function */ 34 | #define PCRYIELD 2 /* C funtion yielded */ 35 | 36 | 37 | /* type of protected functions, to be ran by `runprotected' */ 38 | typedef void (*Pfunc) (lua_State *L, void *ud); 39 | 40 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); 41 | LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 45 | ptrdiff_t oldtop, ptrdiff_t ef); 46 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 47 | LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); 48 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 49 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 50 | 51 | LUAI_FUNC void luaD_throw (lua_State *L, int errcode); 52 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 53 | 54 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /golua/lua/lua52/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.14.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define ltm_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lobject.h" 16 | #include "lstate.h" 17 | #include "lstring.h" 18 | #include "ltable.h" 19 | #include "ltm.h" 20 | 21 | 22 | static const char udatatypename[] = "userdata"; 23 | 24 | LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = { 25 | "no value", 26 | "nil", "boolean", udatatypename, "number", 27 | "string", "table", "function", udatatypename, "thread", 28 | "proto", "upval" /* these last two cases are used for tests only */ 29 | }; 30 | 31 | 32 | void luaT_init (lua_State *L) { 33 | static const char *const luaT_eventname[] = { /* ORDER TM */ 34 | "__index", "__newindex", 35 | "__gc", "__mode", "__len", "__eq", 36 | "__add", "__sub", "__mul", "__div", "__mod", 37 | "__pow", "__unm", "__lt", "__le", 38 | "__concat", "__call" 39 | }; 40 | int i; 41 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 43 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ 44 | } 45 | } 46 | 47 | 48 | /* 49 | ** function to be used with macro "fasttm": optimized for absence of 50 | ** tag methods 51 | */ 52 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 53 | const TValue *tm = luaH_getstr(events, ename); 54 | lua_assert(event <= TM_EQ); 55 | if (ttisnil(tm)) { /* no tag method? */ 56 | events->flags |= cast_byte(1u<metatable; 68 | break; 69 | case LUA_TUSERDATA: 70 | mt = uvalue(o)->metatable; 71 | break; 72 | default: 73 | mt = G(L)->mt[ttypenv(o)]; 74 | } 75 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 76 | } 77 | 78 | -------------------------------------------------------------------------------- /lua/init.lua: -------------------------------------------------------------------------------- 1 | -- NovelChapterInfo 结构体的模拟 2 | function NovelChapterInfo(index, title, url) 3 | return { Index = index, Title = title, URL = url } 4 | end 5 | 6 | -- 定义 GetNovelSiteExternalHandler 类型 7 | GetNovelSiteExternalHandler = {} 8 | GetNovelSiteExternalHandler.__index = GetNovelSiteExternalHandler 9 | 10 | -- 构造函数 11 | function GetNovelSiteExternalHandler:new(title, urls, canHandleFunc, preprocessChapterListURLFunc, extractChapterListFunc, extractChapterContentFunc) 12 | local instance = {} 13 | setmetatable(instance, GetNovelSiteExternalHandler) 14 | 15 | instance.Title = title 16 | instance.Urls = urls 17 | instance.CanHandle = canHandleFunc 18 | instance.PreprocessChapterListURL = preprocessChapterListURLFunc 19 | instance.ExtractChapterList = extractChapterListFunc 20 | instance.ExtractChapterContent = extractChapterContentFunc 21 | 22 | return instance 23 | end 24 | 25 | -- 创建 handlers 全局数组 26 | local handlers = {} 27 | 28 | -- 全局变量,用于存储当前处理器 29 | local currentHandler = nil 30 | 31 | -- RegisterHandler 注册处理器 32 | function RegisterHandler(handler) 33 | table.insert(handlers, handler) 34 | end 35 | 36 | -- FindHandler 查找可处理指定 URL 的处理器 37 | function FindHandler(url) 38 | for _, handler in ipairs(handlers) do 39 | if handler.CanHandle(url) then 40 | currentHandler = handler 41 | return true 42 | end 43 | end 44 | return false 45 | end 46 | 47 | -- 定义 PreprocessChapterListURL 预处理章节列表 URL,其实就是根据 URL 的特征,将其转换为章节列表的 URL 48 | function PreprocessChapterListURL(url) 49 | if currentHandler ~= nil then 50 | return currentHandler.PreprocessChapterListURL(url) 51 | end 52 | end 53 | 54 | -- 定义 ExtractChapterList 从url中提取章节列表 55 | function ExtractChapterList(url, rawPageContent) 56 | if currentHandler ~= nil then 57 | return currentHandler.ExtractChapterList(url, rawPageContent) 58 | end 59 | end 60 | 61 | -- 定义 ExtractChapterContent 清洗章节内容,比如去除一些干扰用的字符串等,仅保留正文内容 62 | function ExtractChapterContent(rawPageContent) 63 | if currentHandler ~= nil then 64 | return currentHandler.ExtractChapterContent(rawPageContent) 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /golua/_example/userdata.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/aarzilli/golua/lua" 4 | import "unsafe" 5 | import "fmt" 6 | 7 | type Userdata struct { 8 | a, b int 9 | } 10 | 11 | func userDataProper(L *lua.State) { 12 | rawptr := L.NewUserdata(uintptr(unsafe.Sizeof(Userdata{}))) 13 | var ptr *Userdata 14 | ptr = (*Userdata)(rawptr) 15 | ptr.a = 2 16 | ptr.b = 3 17 | 18 | fmt.Println(ptr) 19 | 20 | rawptr2 := L.ToUserdata(-1) 21 | ptr2 := (*Userdata)(rawptr2) 22 | 23 | fmt.Println(ptr2) 24 | } 25 | 26 | func example_function(L *lua.State) int { 27 | fmt.Println("Heeeeelllllooooooooooo nuuurse!!!!") 28 | return 0 29 | } 30 | 31 | func goDefinedFunctions(L *lua.State) { 32 | /* example_function is registered inside Lua VM */ 33 | L.Register("example_function", example_function) 34 | 35 | /* This code demonstrates checking that a value on the stack is a go function */ 36 | L.CheckStack(1) 37 | L.GetGlobal("example_function") 38 | if !L.IsGoFunction(-1) { 39 | panic("Not a go function") 40 | } 41 | L.Pop(1) 42 | 43 | /* We call example_function from inside Lua VM */ 44 | L.MustDoString("example_function()") 45 | } 46 | 47 | type TestObject struct { 48 | AField int 49 | } 50 | 51 | func goDefinedObjects(L *lua.State) { 52 | t := &TestObject{42} 53 | 54 | L.PushGoStruct(t) 55 | L.SetGlobal("t") 56 | 57 | /* This code demonstrates checking that a value on the stack is a go object */ 58 | L.CheckStack(1) 59 | L.GetGlobal("t") 60 | if !L.IsGoStruct(-1) { 61 | panic("Not a go struct") 62 | } 63 | L.Pop(1) 64 | 65 | /* This code demonstrates access and assignment to a field of a go object */ 66 | L.MustDoString("print('AField of t is: ' .. t.AField .. ' before assignment');") 67 | L.MustDoString("t.AField = 10;") 68 | L.MustDoString("print('AField of t is: ' .. t.AField .. ' after assignment');") 69 | } 70 | 71 | func main() { 72 | L := lua.NewState() 73 | defer L.Close() 74 | L.OpenLibs() 75 | 76 | /* 77 | This function stores a go object inside Lua VM 78 | */ 79 | userDataProper(L) 80 | 81 | /* 82 | This function demonstrates exposing a function implemented in go to interpreted Lua code 83 | */ 84 | goDefinedFunctions(L) 85 | 86 | goDefinedObjects(L) 87 | } 88 | -------------------------------------------------------------------------------- /ebook/bs/sources.go: -------------------------------------------------------------------------------- 1 | package bs 2 | 3 | import ( 4 | "log" 5 | "net/url" 6 | "sync" 7 | ) 8 | 9 | // BookSourceCollection is an array that the element type is a BookSourceV2 10 | type BookSourceCollection []*BookSourceV2 11 | 12 | // BookSources wrapper for operating array in concurrent environment 13 | type BookSources struct { 14 | BookSourceCollection 15 | sync.RWMutex 16 | } 17 | 18 | type ByBookSourceURL []*BookSourceV2 19 | 20 | func (bss ByBookSourceURL) Len() int { 21 | return len(bss) 22 | } 23 | 24 | func (bss ByBookSourceURL) Less(i, j int) bool { 25 | return bss[i].BookSourceURL < bss[j].BookSourceURL 26 | } 27 | 28 | func (bss ByBookSourceURL) Swap(i, j int) { 29 | bss[i], bss[j] = bss[j], bss[i] 30 | } 31 | 32 | // Add add a book source to array 33 | func (bss *BookSources) Add(bs *BookSourceV2) { 34 | bss.Lock() 35 | bss.BookSourceCollection = append(bss.BookSourceCollection, bs) 36 | bss.Unlock() 37 | } 38 | 39 | // Clear remove all elements 40 | func (bss *BookSources) Clear() { 41 | bss.Lock() 42 | bss.BookSourceCollection = []*BookSourceV2{} 43 | bss.Unlock() 44 | } 45 | 46 | // Length returns count of book sources 47 | func (bss *BookSources) Length() int { 48 | bss.RLock() 49 | defer bss.RUnlock() 50 | return len(bss.BookSourceCollection) 51 | } 52 | 53 | // FindBookSourceByHost find the first matched book source 54 | func (bss *BookSources) FindBookSourceByHost(host string) *BookSourceV2 { 55 | u, e := url.Parse(host) 56 | if e != nil { 57 | log.Println(e) 58 | return nil 59 | } 60 | bss.RLock() 61 | defer bss.RUnlock() 62 | for _, v := range bss.BookSourceCollection { 63 | if v.BookSourceURL == host { 64 | return v 65 | } 66 | bsu, e := url.Parse(v.BookSourceURL) 67 | if e != nil { 68 | continue 69 | } 70 | if bsu.Host == u.Host { 71 | return v 72 | } 73 | } 74 | return nil 75 | } 76 | 77 | // FindBookSourcesByHost find all the matched book sources 78 | func (bss *BookSources) FindBookSourcesByHost(host string) (res BookSources) { 79 | bss.RLock() 80 | defer bss.RUnlock() 81 | for _, v := range bss.BookSourceCollection { 82 | if v.BookSourceURL == host { 83 | res.BookSourceCollection = append(res.BookSourceCollection, v) 84 | } 85 | } 86 | return 87 | } 88 | -------------------------------------------------------------------------------- /golua/lua/lua52/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /golua/lua/lua53/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /golua/lua/lua54/ljumptab.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ljumptab.h $ 3 | ** Jump Table for the Lua interpreter 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #undef vmdispatch 9 | #undef vmcase 10 | #undef vmbreak 11 | 12 | #define vmdispatch(x) goto *disptab[x]; 13 | 14 | #define vmcase(l) L_##l: 15 | 16 | #define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i)); 17 | 18 | 19 | static const void *const disptab[NUM_OPCODES] = { 20 | 21 | #if 0 22 | ** you can update the following list with this command: 23 | ** 24 | ** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h 25 | ** 26 | #endif 27 | 28 | &&L_OP_MOVE, 29 | &&L_OP_LOADI, 30 | &&L_OP_LOADF, 31 | &&L_OP_LOADK, 32 | &&L_OP_LOADKX, 33 | &&L_OP_LOADFALSE, 34 | &&L_OP_LFALSESKIP, 35 | &&L_OP_LOADTRUE, 36 | &&L_OP_LOADNIL, 37 | &&L_OP_GETUPVAL, 38 | &&L_OP_SETUPVAL, 39 | &&L_OP_GETTABUP, 40 | &&L_OP_GETTABLE, 41 | &&L_OP_GETI, 42 | &&L_OP_GETFIELD, 43 | &&L_OP_SETTABUP, 44 | &&L_OP_SETTABLE, 45 | &&L_OP_SETI, 46 | &&L_OP_SETFIELD, 47 | &&L_OP_NEWTABLE, 48 | &&L_OP_SELF, 49 | &&L_OP_ADDI, 50 | &&L_OP_ADDK, 51 | &&L_OP_SUBK, 52 | &&L_OP_MULK, 53 | &&L_OP_MODK, 54 | &&L_OP_POWK, 55 | &&L_OP_DIVK, 56 | &&L_OP_IDIVK, 57 | &&L_OP_BANDK, 58 | &&L_OP_BORK, 59 | &&L_OP_BXORK, 60 | &&L_OP_SHRI, 61 | &&L_OP_SHLI, 62 | &&L_OP_ADD, 63 | &&L_OP_SUB, 64 | &&L_OP_MUL, 65 | &&L_OP_MOD, 66 | &&L_OP_POW, 67 | &&L_OP_DIV, 68 | &&L_OP_IDIV, 69 | &&L_OP_BAND, 70 | &&L_OP_BOR, 71 | &&L_OP_BXOR, 72 | &&L_OP_SHL, 73 | &&L_OP_SHR, 74 | &&L_OP_MMBIN, 75 | &&L_OP_MMBINI, 76 | &&L_OP_MMBINK, 77 | &&L_OP_UNM, 78 | &&L_OP_BNOT, 79 | &&L_OP_NOT, 80 | &&L_OP_LEN, 81 | &&L_OP_CONCAT, 82 | &&L_OP_CLOSE, 83 | &&L_OP_TBC, 84 | &&L_OP_JMP, 85 | &&L_OP_EQ, 86 | &&L_OP_LT, 87 | &&L_OP_LE, 88 | &&L_OP_EQK, 89 | &&L_OP_EQI, 90 | &&L_OP_LTI, 91 | &&L_OP_LEI, 92 | &&L_OP_GTI, 93 | &&L_OP_GEI, 94 | &&L_OP_TEST, 95 | &&L_OP_TESTSET, 96 | &&L_OP_CALL, 97 | &&L_OP_TAILCALL, 98 | &&L_OP_RETURN, 99 | &&L_OP_RETURN0, 100 | &&L_OP_RETURN1, 101 | &&L_OP_FORLOOP, 102 | &&L_OP_FORPREP, 103 | &&L_OP_TFORPREP, 104 | &&L_OP_TFORCALL, 105 | &&L_OP_TFORLOOP, 106 | &&L_OP_SETLIST, 107 | &&L_OP_CLOSURE, 108 | &&L_OP_VARARG, 109 | &&L_OP_VARARGPREP, 110 | &&L_OP_EXTRAARG 111 | 112 | }; 113 | -------------------------------------------------------------------------------- /golua/lua/lua53/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.29.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Macro to check stack size and grow stack if needed. Parameters 18 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 19 | ** stack across reallocations, doing the work only when needed. 20 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 21 | ** at every check. 22 | */ 23 | #define luaD_checkstackaux(L,n,pre,pos) \ 24 | if (L->stack_last - L->top <= (n)) \ 25 | { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); } 26 | 27 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 28 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 29 | 30 | 31 | 32 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 33 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 34 | 35 | 36 | /* type of protected functions, to be ran by 'runprotected' */ 37 | typedef void (*Pfunc) (lua_State *L, void *ud); 38 | 39 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 40 | const char *mode); 41 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 45 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 46 | ptrdiff_t oldtop, ptrdiff_t ef); 47 | LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 48 | int nres); 49 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 50 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 51 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 52 | LUAI_FUNC void luaD_inctop (lua_State *L); 53 | 54 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 55 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /golua/lua/lua53/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.23.1.2 2018/05/24 19:39:05 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->i_key.nk.next) 16 | 17 | 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 20 | 21 | /* 22 | ** writable version of 'gkey'; allows updates to individual fields, 23 | ** but not to the whole (which has incompatible type) 24 | */ 25 | #define wgkey(n) (&(n)->i_key.nk) 26 | 27 | #define invalidateTMcache(t) ((t)->flags = 0) 28 | 29 | 30 | /* true when 't' is using 'dummynode' as its hash part */ 31 | #define isdummy(t) ((t)->lastfree == NULL) 32 | 33 | 34 | /* allocated size for hash nodes */ 35 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 36 | 37 | 38 | /* returns the key, given the value of a table entry */ 39 | #define keyfromval(v) \ 40 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 41 | 42 | 43 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 44 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 45 | TValue *value); 46 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 47 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 48 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 49 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 50 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 51 | LUAI_FUNC Table *luaH_new (lua_State *L); 52 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 53 | unsigned int nhsize); 54 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 55 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 56 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 57 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 58 | 59 | 60 | #if defined(LUA_DEBUG) 61 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 62 | LUAI_FUNC int luaH_isdummy (const Table *t); 63 | #endif 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /golua/lua/lua54/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast_int((pc) - (p)->code) - 1) 15 | 16 | 17 | /* Active Lua function (given call info) */ 18 | #define ci_func(ci) (clLvalue(s2v((ci)->func.p))) 19 | 20 | 21 | #define resethookcount(L) (L->hookcount = L->basehookcount) 22 | 23 | /* 24 | ** mark for entries in 'lineinfo' array that has absolute information in 25 | ** 'abslineinfo' array 26 | */ 27 | #define ABSLINEINFO (-0x80) 28 | 29 | 30 | /* 31 | ** MAXimum number of successive Instructions WiTHout ABSolute line 32 | ** information. (A power of two allows fast divisions.) 33 | */ 34 | #if !defined(MAXIWTHABS) 35 | #define MAXIWTHABS 128 36 | #endif 37 | 38 | 39 | LUAI_FUNC int luaG_getfuncline (const Proto *f, int pc); 40 | LUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, 41 | StkId *pos); 42 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 43 | const char *opname); 44 | LUAI_FUNC l_noret luaG_callerror (lua_State *L, const TValue *o); 45 | LUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o, 46 | const char *what); 47 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 48 | const TValue *p2); 49 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 50 | const TValue *p2, 51 | const char *msg); 52 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 53 | const TValue *p2); 54 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 55 | const TValue *p2); 56 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 57 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 58 | TString *src, int line); 59 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 60 | LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc); 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /golua/lua/lua_defs_lua52.go: -------------------------------------------------------------------------------- 1 | //+build lua52 2 | 3 | package lua 4 | 5 | /* 6 | #include 7 | #include 8 | #include 9 | 10 | */ 11 | import "C" 12 | 13 | type LuaValType int 14 | 15 | const ( 16 | LUA_TNIL = LuaValType(C.LUA_TNIL) 17 | LUA_TNUMBER = LuaValType(C.LUA_TNUMBER) 18 | LUA_TBOOLEAN = LuaValType(C.LUA_TBOOLEAN) 19 | LUA_TSTRING = LuaValType(C.LUA_TSTRING) 20 | LUA_TTABLE = LuaValType(C.LUA_TTABLE) 21 | LUA_TFUNCTION = LuaValType(C.LUA_TFUNCTION) 22 | LUA_TUSERDATA = LuaValType(C.LUA_TUSERDATA) 23 | LUA_TTHREAD = LuaValType(C.LUA_TTHREAD) 24 | LUA_TLIGHTUSERDATA = LuaValType(C.LUA_TLIGHTUSERDATA) 25 | ) 26 | 27 | const ( 28 | LUA_OK = C.LUA_OK 29 | LUA_VERSION = C.LUA_VERSION 30 | LUA_RELEASE = C.LUA_RELEASE 31 | LUA_VERSION_NUM = C.LUA_VERSION_NUM 32 | LUA_COPYRIGHT = C.LUA_COPYRIGHT 33 | LUA_AUTHORS = C.LUA_AUTHORS 34 | LUA_MULTRET = C.LUA_MULTRET 35 | LUA_REGISTRYINDEX = C.LUA_REGISTRYINDEX 36 | LUA_YIELD = C.LUA_YIELD 37 | LUA_ERRRUN = C.LUA_ERRRUN 38 | LUA_ERRSYNTAX = C.LUA_ERRSYNTAX 39 | LUA_ERRMEM = C.LUA_ERRMEM 40 | LUA_ERRERR = C.LUA_ERRERR 41 | LUA_TNONE = C.LUA_TNONE 42 | LUA_MINSTACK = C.LUA_MINSTACK 43 | LUA_GCSTOP = C.LUA_GCSTOP 44 | LUA_GCRESTART = C.LUA_GCRESTART 45 | LUA_GCCOLLECT = C.LUA_GCCOLLECT 46 | LUA_GCCOUNT = C.LUA_GCCOUNT 47 | LUA_GCCOUNTB = C.LUA_GCCOUNTB 48 | LUA_GCSTEP = C.LUA_GCSTEP 49 | LUA_GCSETPAUSE = C.LUA_GCSETPAUSE 50 | LUA_GCSETSTEPMUL = C.LUA_GCSETSTEPMUL 51 | LUA_HOOKCALL = C.LUA_HOOKCALL 52 | LUA_HOOKRET = C.LUA_HOOKRET 53 | LUA_HOOKLINE = C.LUA_HOOKLINE 54 | LUA_HOOKCOUNT = C.LUA_HOOKCOUNT 55 | LUA_MASKCALL = C.LUA_MASKCALL 56 | LUA_MASKRET = C.LUA_MASKRET 57 | LUA_MASKLINE = C.LUA_MASKLINE 58 | LUA_MASKCOUNT = C.LUA_MASKCOUNT 59 | LUA_ERRFILE = C.LUA_ERRFILE 60 | LUA_NOREF = C.LUA_NOREF 61 | LUA_REFNIL = C.LUA_REFNIL 62 | LUA_FILEHANDLE = C.LUA_FILEHANDLE 63 | LUA_COLIBNAME = C.LUA_COLIBNAME 64 | LUA_TABLIBNAME = C.LUA_TABLIBNAME 65 | LUA_IOLIBNAME = C.LUA_IOLIBNAME 66 | LUA_OSLIBNAME = C.LUA_OSLIBNAME 67 | LUA_STRLIBNAME = C.LUA_STRLIBNAME 68 | LUA_MATHLIBNAME = C.LUA_MATHLIBNAME 69 | LUA_DBLIBNAME = C.LUA_DBLIBNAME 70 | LUA_LOADLIBNAME = C.LUA_LOADLIBNAME 71 | ) 72 | -------------------------------------------------------------------------------- /golua/lua/lua_defs_lua53.go: -------------------------------------------------------------------------------- 1 | //+build lua53 2 | 3 | package lua 4 | 5 | /* 6 | #include 7 | #include 8 | #include 9 | 10 | */ 11 | import "C" 12 | 13 | type LuaValType int 14 | 15 | const ( 16 | LUA_TNIL = LuaValType(C.LUA_TNIL) 17 | LUA_TNUMBER = LuaValType(C.LUA_TNUMBER) 18 | LUA_TBOOLEAN = LuaValType(C.LUA_TBOOLEAN) 19 | LUA_TSTRING = LuaValType(C.LUA_TSTRING) 20 | LUA_TTABLE = LuaValType(C.LUA_TTABLE) 21 | LUA_TFUNCTION = LuaValType(C.LUA_TFUNCTION) 22 | LUA_TUSERDATA = LuaValType(C.LUA_TUSERDATA) 23 | LUA_TTHREAD = LuaValType(C.LUA_TTHREAD) 24 | LUA_TLIGHTUSERDATA = LuaValType(C.LUA_TLIGHTUSERDATA) 25 | ) 26 | 27 | const ( 28 | LUA_OK = C.LUA_OK 29 | LUA_VERSION = C.LUA_VERSION 30 | LUA_RELEASE = C.LUA_RELEASE 31 | LUA_VERSION_NUM = C.LUA_VERSION_NUM 32 | LUA_COPYRIGHT = C.LUA_COPYRIGHT 33 | LUA_AUTHORS = C.LUA_AUTHORS 34 | LUA_MULTRET = C.LUA_MULTRET 35 | LUA_REGISTRYINDEX = C.LUA_REGISTRYINDEX 36 | LUA_YIELD = C.LUA_YIELD 37 | LUA_ERRRUN = C.LUA_ERRRUN 38 | LUA_ERRSYNTAX = C.LUA_ERRSYNTAX 39 | LUA_ERRMEM = C.LUA_ERRMEM 40 | LUA_ERRERR = C.LUA_ERRERR 41 | LUA_TNONE = C.LUA_TNONE 42 | LUA_MINSTACK = C.LUA_MINSTACK 43 | LUA_GCSTOP = C.LUA_GCSTOP 44 | LUA_GCRESTART = C.LUA_GCRESTART 45 | LUA_GCCOLLECT = C.LUA_GCCOLLECT 46 | LUA_GCCOUNT = C.LUA_GCCOUNT 47 | LUA_GCCOUNTB = C.LUA_GCCOUNTB 48 | LUA_GCSTEP = C.LUA_GCSTEP 49 | LUA_GCSETPAUSE = C.LUA_GCSETPAUSE 50 | LUA_GCSETSTEPMUL = C.LUA_GCSETSTEPMUL 51 | LUA_HOOKCALL = C.LUA_HOOKCALL 52 | LUA_HOOKRET = C.LUA_HOOKRET 53 | LUA_HOOKLINE = C.LUA_HOOKLINE 54 | LUA_HOOKCOUNT = C.LUA_HOOKCOUNT 55 | LUA_MASKCALL = C.LUA_MASKCALL 56 | LUA_MASKRET = C.LUA_MASKRET 57 | LUA_MASKLINE = C.LUA_MASKLINE 58 | LUA_MASKCOUNT = C.LUA_MASKCOUNT 59 | LUA_ERRFILE = C.LUA_ERRFILE 60 | LUA_NOREF = C.LUA_NOREF 61 | LUA_REFNIL = C.LUA_REFNIL 62 | LUA_FILEHANDLE = C.LUA_FILEHANDLE 63 | LUA_COLIBNAME = C.LUA_COLIBNAME 64 | LUA_TABLIBNAME = C.LUA_TABLIBNAME 65 | LUA_IOLIBNAME = C.LUA_IOLIBNAME 66 | LUA_OSLIBNAME = C.LUA_OSLIBNAME 67 | LUA_STRLIBNAME = C.LUA_STRLIBNAME 68 | LUA_MATHLIBNAME = C.LUA_MATHLIBNAME 69 | LUA_DBLIBNAME = C.LUA_DBLIBNAME 70 | LUA_LOADLIBNAME = C.LUA_LOADLIBNAME 71 | ) 72 | -------------------------------------------------------------------------------- /golua/lua/lua_defs_lua54.go: -------------------------------------------------------------------------------- 1 | //+build lua54 2 | 3 | package lua 4 | 5 | /* 6 | #include 7 | #include 8 | #include 9 | 10 | */ 11 | import "C" 12 | 13 | type LuaValType int 14 | 15 | const ( 16 | LUA_TNIL = LuaValType(C.LUA_TNIL) 17 | LUA_TNUMBER = LuaValType(C.LUA_TNUMBER) 18 | LUA_TBOOLEAN = LuaValType(C.LUA_TBOOLEAN) 19 | LUA_TSTRING = LuaValType(C.LUA_TSTRING) 20 | LUA_TTABLE = LuaValType(C.LUA_TTABLE) 21 | LUA_TFUNCTION = LuaValType(C.LUA_TFUNCTION) 22 | LUA_TUSERDATA = LuaValType(C.LUA_TUSERDATA) 23 | LUA_TTHREAD = LuaValType(C.LUA_TTHREAD) 24 | LUA_TLIGHTUSERDATA = LuaValType(C.LUA_TLIGHTUSERDATA) 25 | ) 26 | 27 | const ( 28 | LUA_OK = C.LUA_OK 29 | LUA_VERSION = C.LUA_VERSION 30 | LUA_RELEASE = C.LUA_RELEASE 31 | LUA_VERSION_NUM = C.LUA_VERSION_NUM 32 | LUA_COPYRIGHT = C.LUA_COPYRIGHT 33 | LUA_AUTHORS = C.LUA_AUTHORS 34 | LUA_MULTRET = C.LUA_MULTRET 35 | LUA_REGISTRYINDEX = C.LUA_REGISTRYINDEX 36 | LUA_YIELD = C.LUA_YIELD 37 | LUA_ERRRUN = C.LUA_ERRRUN 38 | LUA_ERRSYNTAX = C.LUA_ERRSYNTAX 39 | LUA_ERRMEM = C.LUA_ERRMEM 40 | LUA_ERRERR = C.LUA_ERRERR 41 | LUA_TNONE = C.LUA_TNONE 42 | LUA_MINSTACK = C.LUA_MINSTACK 43 | LUA_GCSTOP = C.LUA_GCSTOP 44 | LUA_GCRESTART = C.LUA_GCRESTART 45 | LUA_GCCOLLECT = C.LUA_GCCOLLECT 46 | LUA_GCCOUNT = C.LUA_GCCOUNT 47 | LUA_GCCOUNTB = C.LUA_GCCOUNTB 48 | LUA_GCSTEP = C.LUA_GCSTEP 49 | LUA_GCSETPAUSE = C.LUA_GCSETPAUSE 50 | LUA_GCSETSTEPMUL = C.LUA_GCSETSTEPMUL 51 | LUA_HOOKCALL = C.LUA_HOOKCALL 52 | LUA_HOOKRET = C.LUA_HOOKRET 53 | LUA_HOOKLINE = C.LUA_HOOKLINE 54 | LUA_HOOKCOUNT = C.LUA_HOOKCOUNT 55 | LUA_MASKCALL = C.LUA_MASKCALL 56 | LUA_MASKRET = C.LUA_MASKRET 57 | LUA_MASKLINE = C.LUA_MASKLINE 58 | LUA_MASKCOUNT = C.LUA_MASKCOUNT 59 | LUA_ERRFILE = C.LUA_ERRFILE 60 | LUA_NOREF = C.LUA_NOREF 61 | LUA_REFNIL = C.LUA_REFNIL 62 | LUA_FILEHANDLE = C.LUA_FILEHANDLE 63 | LUA_COLIBNAME = C.LUA_COLIBNAME 64 | LUA_TABLIBNAME = C.LUA_TABLIBNAME 65 | LUA_IOLIBNAME = C.LUA_IOLIBNAME 66 | LUA_OSLIBNAME = C.LUA_OSLIBNAME 67 | LUA_STRLIBNAME = C.LUA_STRLIBNAME 68 | LUA_MATHLIBNAME = C.LUA_MATHLIBNAME 69 | LUA_DBLIBNAME = C.LUA_DBLIBNAME 70 | LUA_LOADLIBNAME = C.LUA_LOADLIBNAME 71 | ) 72 | -------------------------------------------------------------------------------- /golua/lua/lua54/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->u.next) 16 | 17 | 18 | /* 19 | ** Clear all bits of fast-access metamethods, which means that the table 20 | ** may have any of these metamethods. (First access that fails after the 21 | ** clearing will set the bit again.) 22 | */ 23 | #define invalidateTMcache(t) ((t)->flags &= ~maskflags) 24 | 25 | 26 | /* true when 't' is using 'dummynode' as its hash part */ 27 | #define isdummy(t) ((t)->lastfree == NULL) 28 | 29 | 30 | /* allocated size for hash nodes */ 31 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 32 | 33 | 34 | /* returns the Node, given the value of a table entry */ 35 | #define nodefromval(v) cast(Node *, (v)) 36 | 37 | 38 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 39 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 40 | TValue *value); 41 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 42 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 43 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 44 | LUAI_FUNC void luaH_newkey (lua_State *L, Table *t, const TValue *key, 45 | TValue *value); 46 | LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key, 47 | TValue *value); 48 | LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key, 49 | const TValue *slot, TValue *value); 50 | LUAI_FUNC Table *luaH_new (lua_State *L); 51 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 52 | unsigned int nhsize); 53 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 54 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 55 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 56 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 57 | LUAI_FUNC unsigned int luaH_realasize (const Table *t); 58 | 59 | 60 | #if defined(LUA_DEBUG) 61 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 62 | #endif 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /golua/lua/lua52/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.72.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | 17 | 18 | /* 19 | * WARNING: if you change the order of this enumeration, 20 | * grep "ORDER RESERVED" 21 | */ 22 | enum RESERVED { 23 | /* terminal symbols denoted by reserved words */ 24 | TK_AND = FIRST_RESERVED, TK_BREAK, 25 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 26 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 27 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 28 | /* other terminal symbols */ 29 | TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_DBCOLON, TK_EOS, 30 | TK_NUMBER, TK_NAME, TK_STRING 31 | }; 32 | 33 | /* number of reserved words */ 34 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 35 | 36 | 37 | typedef union { 38 | lua_Number r; 39 | TString *ts; 40 | } SemInfo; /* semantics information */ 41 | 42 | 43 | typedef struct Token { 44 | int token; 45 | SemInfo seminfo; 46 | } Token; 47 | 48 | 49 | /* state of the lexer plus state of the parser when shared by all 50 | functions */ 51 | typedef struct LexState { 52 | int current; /* current character (charint) */ 53 | int linenumber; /* input line counter */ 54 | int lastline; /* line of last token `consumed' */ 55 | Token t; /* current token */ 56 | Token lookahead; /* look ahead token */ 57 | struct FuncState *fs; /* current function (parser) */ 58 | struct lua_State *L; 59 | ZIO *z; /* input stream */ 60 | Mbuffer *buff; /* buffer for tokens */ 61 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 62 | TString *source; /* current source name */ 63 | TString *envn; /* environment variable name */ 64 | char decpoint; /* locale decimal point */ 65 | } LexState; 66 | 67 | 68 | LUAI_FUNC void luaX_init (lua_State *L); 69 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 70 | TString *source, int firstchar); 71 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 72 | LUAI_FUNC void luaX_next (LexState *ls); 73 | LUAI_FUNC int luaX_lookahead (LexState *ls); 74 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 75 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /golua/lua/lua52/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.11.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lctype.h" 11 | 12 | #if !LUA_USE_CTYPE /* { */ 13 | 14 | #include 15 | 16 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 17 | 0x00, /* EOZ */ 18 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 19 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 22 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 23 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 24 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 25 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 26 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 27 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 28 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 29 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 30 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 31 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 32 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 33 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50 | }; 51 | 52 | #endif /* } */ 53 | -------------------------------------------------------------------------------- /golua/lua/lua51/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | /* maximum length of a reserved word */ 17 | #define TOKEN_LEN (sizeof("function")/sizeof(char)) 18 | 19 | 20 | /* 21 | * WARNING: if you change the order of this enumeration, 22 | * grep "ORDER RESERVED" 23 | */ 24 | enum RESERVED { 25 | /* terminal symbols denoted by reserved words */ 26 | TK_AND = FIRST_RESERVED, TK_BREAK, 27 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 28 | TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 29 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 30 | /* other terminal symbols */ 31 | TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, 32 | TK_NAME, TK_STRING, TK_EOS 33 | }; 34 | 35 | /* number of reserved words */ 36 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 37 | 38 | 39 | /* array with token `names' */ 40 | LUAI_DATA const char *const luaX_tokens []; 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | TString *ts; 46 | } SemInfo; /* semantics information */ 47 | 48 | 49 | typedef struct Token { 50 | int token; 51 | SemInfo seminfo; 52 | } Token; 53 | 54 | 55 | typedef struct LexState { 56 | int current; /* current character (charint) */ 57 | int linenumber; /* input line counter */ 58 | int lastline; /* line of last token `consumed' */ 59 | Token t; /* current token */ 60 | Token lookahead; /* look ahead token */ 61 | struct FuncState *fs; /* `FuncState' is private to the parser */ 62 | struct lua_State *L; 63 | ZIO *z; /* input stream */ 64 | Mbuffer *buff; /* buffer for tokens */ 65 | TString *source; /* current source name */ 66 | char decpoint; /* locale decimal point */ 67 | } LexState; 68 | 69 | 70 | LUAI_FUNC void luaX_init (lua_State *L); 71 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 72 | TString *source); 73 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 74 | LUAI_FUNC void luaX_next (LexState *ls); 75 | LUAI_FUNC void luaX_lookahead (LexState *ls); 76 | LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); 77 | LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); 78 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 79 | 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /golua/lua/lua53/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.12.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 20 | 0x00, /* EOZ */ 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 22 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 26 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 27 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 28 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 29 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 30 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 31 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 32 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 33 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 34 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 35 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 36 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 | }; 54 | 55 | #endif /* } */ 56 | -------------------------------------------------------------------------------- /golua/lua/lua51/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lmem_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "ldebug.h" 16 | #include "ldo.h" 17 | #include "lmem.h" 18 | #include "lobject.h" 19 | #include "lstate.h" 20 | 21 | 22 | 23 | /* 24 | ** About the realloc function: 25 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 26 | ** (`osize' is the old size, `nsize' is the new size) 27 | ** 28 | ** Lua ensures that (ptr == NULL) iff (osize == 0). 29 | ** 30 | ** * frealloc(ud, NULL, 0, x) creates a new block of size `x' 31 | ** 32 | ** * frealloc(ud, p, x, 0) frees the block `p' 33 | ** (in this specific case, frealloc must return NULL). 34 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 35 | ** (which is equivalent to free(NULL) in ANSI C) 36 | ** 37 | ** frealloc returns NULL if it cannot create or reallocate the area 38 | ** (any reallocation to an equal or smaller size cannot fail!) 39 | */ 40 | 41 | 42 | 43 | #define MINSIZEARRAY 4 44 | 45 | 46 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 47 | int limit, const char *errormsg) { 48 | void *newblock; 49 | int newsize; 50 | if (*size >= limit/2) { /* cannot double it? */ 51 | if (*size >= limit) /* cannot grow even a little? */ 52 | luaG_runerror(L, errormsg); 53 | newsize = limit; /* still have at least one free place */ 54 | } 55 | else { 56 | newsize = (*size)*2; 57 | if (newsize < MINSIZEARRAY) 58 | newsize = MINSIZEARRAY; /* minimum size */ 59 | } 60 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 61 | *size = newsize; /* update only when everything else is OK */ 62 | return newblock; 63 | } 64 | 65 | 66 | void *luaM_toobig (lua_State *L) { 67 | luaG_runerror(L, "memory allocation error: block too big"); 68 | return NULL; /* to avoid warnings */ 69 | } 70 | 71 | 72 | 73 | /* 74 | ** generic allocation routine. 75 | */ 76 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 77 | global_State *g = G(L); 78 | lua_assert((osize == 0) == (block == NULL)); 79 | block = (*g->frealloc)(g->ud, block, osize, nsize); 80 | if (block == NULL && nsize > 0) 81 | luaD_throw(L, LUA_ERRMEM); 82 | lua_assert((nsize == 0) == (block == NULL)); 83 | g->totalbytes = (g->totalbytes - osize) + nsize; 84 | return block; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /golua/lua/lua_defs_lua51.go: -------------------------------------------------------------------------------- 1 | //+build !lua52,!lua53,!lua54 2 | 3 | package lua 4 | 5 | /* 6 | #include 7 | #include 8 | #include 9 | 10 | */ 11 | import "C" 12 | 13 | type LuaValType int 14 | 15 | const ( 16 | LUA_TNIL = LuaValType(C.LUA_TNIL) 17 | LUA_TNUMBER = LuaValType(C.LUA_TNUMBER) 18 | LUA_TBOOLEAN = LuaValType(C.LUA_TBOOLEAN) 19 | LUA_TSTRING = LuaValType(C.LUA_TSTRING) 20 | LUA_TTABLE = LuaValType(C.LUA_TTABLE) 21 | LUA_TFUNCTION = LuaValType(C.LUA_TFUNCTION) 22 | LUA_TUSERDATA = LuaValType(C.LUA_TUSERDATA) 23 | LUA_TTHREAD = LuaValType(C.LUA_TTHREAD) 24 | LUA_TLIGHTUSERDATA = LuaValType(C.LUA_TLIGHTUSERDATA) 25 | ) 26 | 27 | const ( 28 | LUA_VERSION = C.LUA_VERSION 29 | LUA_RELEASE = C.LUA_RELEASE 30 | LUA_VERSION_NUM = C.LUA_VERSION_NUM 31 | LUA_COPYRIGHT = C.LUA_COPYRIGHT 32 | LUA_AUTHORS = C.LUA_AUTHORS 33 | LUA_MULTRET = C.LUA_MULTRET 34 | LUA_REGISTRYINDEX = C.LUA_REGISTRYINDEX 35 | LUA_ENVIRONINDEX = C.LUA_ENVIRONINDEX 36 | LUA_GLOBALSINDEX = C.LUA_GLOBALSINDEX 37 | LUA_YIELD = C.LUA_YIELD 38 | LUA_ERRRUN = C.LUA_ERRRUN 39 | LUA_ERRSYNTAX = C.LUA_ERRSYNTAX 40 | LUA_ERRMEM = C.LUA_ERRMEM 41 | LUA_ERRERR = C.LUA_ERRERR 42 | LUA_TNONE = C.LUA_TNONE 43 | LUA_MINSTACK = C.LUA_MINSTACK 44 | LUA_GCSTOP = C.LUA_GCSTOP 45 | LUA_GCRESTART = C.LUA_GCRESTART 46 | LUA_GCCOLLECT = C.LUA_GCCOLLECT 47 | LUA_GCCOUNT = C.LUA_GCCOUNT 48 | LUA_GCCOUNTB = C.LUA_GCCOUNTB 49 | LUA_GCSTEP = C.LUA_GCSTEP 50 | LUA_GCSETPAUSE = C.LUA_GCSETPAUSE 51 | LUA_GCSETSTEPMUL = C.LUA_GCSETSTEPMUL 52 | LUA_HOOKCALL = C.LUA_HOOKCALL 53 | LUA_HOOKRET = C.LUA_HOOKRET 54 | LUA_HOOKLINE = C.LUA_HOOKLINE 55 | LUA_HOOKCOUNT = C.LUA_HOOKCOUNT 56 | LUA_HOOKTAILRET = C.LUA_HOOKTAILRET 57 | LUA_MASKCALL = C.LUA_MASKCALL 58 | LUA_MASKRET = C.LUA_MASKRET 59 | LUA_MASKLINE = C.LUA_MASKLINE 60 | LUA_MASKCOUNT = C.LUA_MASKCOUNT 61 | LUA_ERRFILE = C.LUA_ERRFILE 62 | LUA_NOREF = C.LUA_NOREF 63 | LUA_REFNIL = C.LUA_REFNIL 64 | LUA_FILEHANDLE = C.LUA_FILEHANDLE 65 | LUA_COLIBNAME = C.LUA_COLIBNAME 66 | LUA_TABLIBNAME = C.LUA_TABLIBNAME 67 | LUA_IOLIBNAME = C.LUA_IOLIBNAME 68 | LUA_OSLIBNAME = C.LUA_OSLIBNAME 69 | LUA_STRLIBNAME = C.LUA_STRLIBNAME 70 | LUA_MATHLIBNAME = C.LUA_MATHLIBNAME 71 | LUA_DBLIBNAME = C.LUA_DBLIBNAME 72 | LUA_LOADLIBNAME = C.LUA_LOADLIBNAME 73 | ) 74 | -------------------------------------------------------------------------------- /golua/lua/lua51/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression descriptor 17 | */ 18 | 19 | typedef enum { 20 | VVOID, /* no value */ 21 | VNIL, 22 | VTRUE, 23 | VFALSE, 24 | VK, /* info = index of constant in `k' */ 25 | VKNUM, /* nval = numerical value */ 26 | VLOCAL, /* info = local register */ 27 | VUPVAL, /* info = index of upvalue in `upvalues' */ 28 | VGLOBAL, /* info = index of table; aux = index of global name in `k' */ 29 | VINDEXED, /* info = table register; aux = index register (or `k') */ 30 | VJMP, /* info = instruction pc */ 31 | VRELOCABLE, /* info = instruction pc */ 32 | VNONRELOC, /* info = result register */ 33 | VCALL, /* info = instruction pc */ 34 | VVARARG /* info = instruction pc */ 35 | } expkind; 36 | 37 | typedef struct expdesc { 38 | expkind k; 39 | union { 40 | struct { int info, aux; } s; 41 | lua_Number nval; 42 | } u; 43 | int t; /* patch list of `exit when true' */ 44 | int f; /* patch list of `exit when false' */ 45 | } expdesc; 46 | 47 | 48 | typedef struct upvaldesc { 49 | lu_byte k; 50 | lu_byte info; 51 | } upvaldesc; 52 | 53 | 54 | struct BlockCnt; /* defined in lparser.c */ 55 | 56 | 57 | /* state needed to generate code for a given function */ 58 | typedef struct FuncState { 59 | Proto *f; /* current function header */ 60 | Table *h; /* table to find (and reuse) elements in `k' */ 61 | struct FuncState *prev; /* enclosing function */ 62 | struct LexState *ls; /* lexical state */ 63 | struct lua_State *L; /* copy of the Lua state */ 64 | struct BlockCnt *bl; /* chain of current blocks */ 65 | int pc; /* next position to code (equivalent to `ncode') */ 66 | int lasttarget; /* `pc' of last `jump target' */ 67 | int jpc; /* list of pending jumps to `pc' */ 68 | int freereg; /* first free register */ 69 | int nk; /* number of elements in `k' */ 70 | int np; /* number of elements in `p' */ 71 | short nlocvars; /* number of elements in `locvars' */ 72 | lu_byte nactvar; /* number of active local variables */ 73 | upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ 74 | unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ 75 | } FuncState; 76 | 77 | 78 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 79 | const char *name); 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /golua/lua/lua53/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.79.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | 17 | #if !defined(LUA_ENV) 18 | #define LUA_ENV "_ENV" 19 | #endif 20 | 21 | 22 | /* 23 | * WARNING: if you change the order of this enumeration, 24 | * grep "ORDER RESERVED" 25 | */ 26 | enum RESERVED { 27 | /* terminal symbols denoted by reserved words */ 28 | TK_AND = FIRST_RESERVED, TK_BREAK, 29 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 30 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 31 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 32 | /* other terminal symbols */ 33 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 34 | TK_SHL, TK_SHR, 35 | TK_DBCOLON, TK_EOS, 36 | TK_FLT, TK_INT, TK_NAME, TK_STRING 37 | }; 38 | 39 | /* number of reserved words */ 40 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | lua_Integer i; 46 | TString *ts; 47 | } SemInfo; /* semantics information */ 48 | 49 | 50 | typedef struct Token { 51 | int token; 52 | SemInfo seminfo; 53 | } Token; 54 | 55 | 56 | /* state of the lexer plus state of the parser when shared by all 57 | functions */ 58 | typedef struct LexState { 59 | int current; /* current character (charint) */ 60 | int linenumber; /* input line counter */ 61 | int lastline; /* line of last token 'consumed' */ 62 | Token t; /* current token */ 63 | Token lookahead; /* look ahead token */ 64 | struct FuncState *fs; /* current function (parser) */ 65 | struct lua_State *L; 66 | ZIO *z; /* input stream */ 67 | Mbuffer *buff; /* buffer for tokens */ 68 | Table *h; /* to avoid collection/reuse strings */ 69 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 70 | TString *source; /* current source name */ 71 | TString *envn; /* environment variable name */ 72 | } LexState; 73 | 74 | 75 | LUAI_FUNC void luaX_init (lua_State *L); 76 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 77 | TString *source, int firstchar); 78 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 79 | LUAI_FUNC void luaX_next (LexState *ls); 80 | LUAI_FUNC int luaX_lookahead (LexState *ls); 81 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 82 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /golua/lua/lua54/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua. 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | 65 | /* 66 | ** In ASCII, this 'ltolower' is correct for alphabetic characters and 67 | ** for '.'. That is enough for Lua needs. ('check_exp' ensures that 68 | ** the character either is an upper-case letter or is unchanged by 69 | ** the transformation, which holds for lower-case letters and '.'.) 70 | */ 71 | #define ltolower(c) \ 72 | check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \ 73 | (c) | ('A' ^ 'a')) 74 | 75 | 76 | /* one entry for each character and for -1 (EOZ) */ 77 | LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];) 78 | 79 | 80 | #else /* }{ */ 81 | 82 | /* 83 | ** use standard C ctypes 84 | */ 85 | 86 | #include 87 | 88 | 89 | #define lislalpha(c) (isalpha(c) || (c) == '_') 90 | #define lislalnum(c) (isalnum(c) || (c) == '_') 91 | #define lisdigit(c) (isdigit(c)) 92 | #define lisspace(c) (isspace(c)) 93 | #define lisprint(c) (isprint(c)) 94 | #define lisxdigit(c) (isxdigit(c)) 95 | 96 | #define ltolower(c) (tolower(c)) 97 | 98 | #endif /* } */ 99 | 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /golua/lua/lua53/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro reallocs a vector 'b' from 'on' to 'n' elements, where 19 | ** each element has size 'e'. In case of arithmetic overflow of the 20 | ** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because 21 | ** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e). 22 | ** 23 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 24 | ** comparison avoids a runtime comparison when overflow cannot occur. 25 | ** The compiler should be able to optimize the real test by itself, but 26 | ** when it does it, it may give a warning about "comparison is always 27 | ** false due to limited range of data type"; the +1 tricks the compiler, 28 | ** avoiding this warning but also this optimization.) 29 | */ 30 | #define luaM_reallocv(L,b,on,n,e) \ 31 | (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \ 32 | ? luaM_toobig(L) : cast_void(0)) , \ 33 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 34 | 35 | /* 36 | ** Arrays of chars do not need any test 37 | */ 38 | #define luaM_reallocvchar(L,b,on,n) \ 39 | cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 40 | 41 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 42 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 43 | #define luaM_freearray(L, b, n) luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0) 44 | 45 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 46 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 47 | #define luaM_newvector(L,n,t) \ 48 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 49 | 50 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 51 | 52 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 53 | if ((nelems)+1 > (size)) \ 54 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 55 | 56 | #define luaM_reallocvector(L, v,oldn,n,t) \ 57 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 58 | 59 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 60 | 61 | /* not to be called directly */ 62 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 63 | size_t size); 64 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 65 | size_t size_elem, int limit, 66 | const char *what); 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /golua/lua/lua54/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | 20 | #if defined (LUA_UCID) /* accept UniCode IDentifiers? */ 21 | /* consider all non-ascii codepoints to be alphabetic */ 22 | #define NONA 0x01 23 | #else 24 | #define NONA 0x00 /* default */ 25 | #endif 26 | 27 | 28 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 29 | 0x00, /* EOZ */ 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 31 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 35 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 36 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 37 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 38 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 39 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 40 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 41 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 42 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 43 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 44 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 45 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 46 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 8. */ 47 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 48 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 9. */ 49 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 50 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* a. */ 51 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 52 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* b. */ 53 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 54 | 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, /* c. */ 55 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 56 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* d. */ 57 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 58 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* e. */ 59 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 60 | NONA, NONA, NONA, NONA, NONA, 0x00, 0x00, 0x00, /* f. */ 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 62 | }; 63 | 64 | #endif /* } */ 65 | -------------------------------------------------------------------------------- /golua/lua/lua54/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include 11 | 12 | #include "lobject.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Single-char tokens (terminal symbols) are represented by their own 18 | ** numeric code. Other tokens start at the following value. 19 | */ 20 | #define FIRST_RESERVED (UCHAR_MAX + 1) 21 | 22 | 23 | #if !defined(LUA_ENV) 24 | #define LUA_ENV "_ENV" 25 | #endif 26 | 27 | 28 | /* 29 | * WARNING: if you change the order of this enumeration, 30 | * grep "ORDER RESERVED" 31 | */ 32 | enum RESERVED { 33 | /* terminal symbols denoted by reserved words */ 34 | TK_AND = FIRST_RESERVED, TK_BREAK, 35 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 36 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 37 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 38 | /* other terminal symbols */ 39 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 40 | TK_SHL, TK_SHR, 41 | TK_DBCOLON, TK_EOS, 42 | TK_FLT, TK_INT, TK_NAME, TK_STRING 43 | }; 44 | 45 | /* number of reserved words */ 46 | #define NUM_RESERVED (cast_int(TK_WHILE-FIRST_RESERVED + 1)) 47 | 48 | 49 | typedef union { 50 | lua_Number r; 51 | lua_Integer i; 52 | TString *ts; 53 | } SemInfo; /* semantics information */ 54 | 55 | 56 | typedef struct Token { 57 | int token; 58 | SemInfo seminfo; 59 | } Token; 60 | 61 | 62 | /* state of the lexer plus state of the parser when shared by all 63 | functions */ 64 | typedef struct LexState { 65 | int current; /* current character (charint) */ 66 | int linenumber; /* input line counter */ 67 | int lastline; /* line of last token 'consumed' */ 68 | Token t; /* current token */ 69 | Token lookahead; /* look ahead token */ 70 | struct FuncState *fs; /* current function (parser) */ 71 | struct lua_State *L; 72 | ZIO *z; /* input stream */ 73 | Mbuffer *buff; /* buffer for tokens */ 74 | Table *h; /* to avoid collection/reuse strings */ 75 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 76 | TString *source; /* current source name */ 77 | TString *envn; /* environment variable name */ 78 | } LexState; 79 | 80 | 81 | LUAI_FUNC void luaX_init (lua_State *L); 82 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 83 | TString *source, int firstchar); 84 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 85 | LUAI_FUNC void luaX_next (LexState *ls); 86 | LUAI_FUNC int luaX_lookahead (LexState *ls); 87 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 88 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 89 | 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/missdeer/getnovel 2 | 3 | go 1.24.0 4 | 5 | toolchain go1.24.1 6 | 7 | require ( 8 | github.com/PuerkitoBio/goquery v1.11.0 9 | github.com/aarzilli/golua v0.0.0-20210507130708-11106aa57765 10 | github.com/bmaupin/go-epub v1.1.0 11 | github.com/gin-gonic/gin v1.10.1 12 | github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 13 | github.com/google/uuid v1.6.0 14 | github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7 15 | github.com/jessevdk/go-flags v1.6.1 16 | github.com/missdeer/golib v1.0.9 17 | github.com/mozillazg/go-pinyin v0.21.0 18 | github.com/signintech/gopdf v0.23.1 19 | gitlab.com/ambrevar/golua v0.0.0-20180622185024-6b6c7877b31e 20 | golang.org/x/net v0.48.0 21 | golang.org/x/sync v0.19.0 22 | golang.org/x/text v0.32.0 23 | ) 24 | 25 | require ( 26 | github.com/andybalholm/cascadia v1.3.3 // indirect 27 | github.com/bytedance/sonic v1.11.6 // indirect 28 | github.com/bytedance/sonic/loader v0.1.1 // indirect 29 | github.com/cloudwego/base64x v0.1.4 // indirect 30 | github.com/cloudwego/iasm v0.2.0 // indirect 31 | github.com/gabriel-vasile/mimetype v1.4.3 // indirect 32 | github.com/gin-contrib/sse v0.1.0 // indirect 33 | github.com/go-playground/locales v0.14.1 // indirect 34 | github.com/go-playground/universal-translator v0.18.1 // indirect 35 | github.com/go-playground/validator/v10 v10.20.0 // indirect 36 | github.com/goccy/go-json v0.10.2 // indirect 37 | github.com/gofrs/uuid v4.4.0+incompatible // indirect 38 | github.com/json-iterator/go v1.1.12 // indirect 39 | github.com/klauspost/cpuid/v2 v2.2.7 // indirect 40 | github.com/kr/pretty v0.3.0 // indirect 41 | github.com/leodido/go-urn v1.4.0 // indirect 42 | github.com/mattn/go-isatty v0.0.20 // indirect 43 | github.com/mattn/go-runewidth v0.0.4 // indirect 44 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 45 | github.com/modern-go/reflect2 v1.0.2 // indirect 46 | github.com/olekukonko/tablewriter v0.0.1 // indirect 47 | github.com/pelletier/go-toml/v2 v2.2.2 // indirect 48 | github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 // indirect 49 | github.com/pkg/errors v0.9.1 // indirect 50 | github.com/rogpeppe/go-internal v1.8.0 // indirect 51 | github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect 52 | github.com/twitchyliquid64/golang-asm v0.15.1 // indirect 53 | github.com/ugorji/go/codec v1.2.12 // indirect 54 | github.com/vincent-petithory/dataurl v1.0.0 // indirect 55 | golang.org/x/arch v0.8.0 // indirect 56 | golang.org/x/crypto v0.46.0 // indirect 57 | golang.org/x/image v0.18.0 // indirect 58 | golang.org/x/sys v0.39.0 // indirect 59 | google.golang.org/protobuf v1.34.1 // indirect 60 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect 61 | gopkg.in/yaml.v3 v3.0.1 // indirect 62 | ) 63 | 64 | replace github.com/aarzilli/golua => ./golua 65 | -------------------------------------------------------------------------------- /golua/lua/lua51/llimits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Limits, basic types, and some other `installation-dependent' definitions 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llimits_h 8 | #define llimits_h 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | #include "lua.h" 16 | 17 | 18 | typedef LUAI_UINT32 lu_int32; 19 | 20 | typedef LUAI_UMEM lu_mem; 21 | 22 | typedef LUAI_MEM l_mem; 23 | 24 | 25 | 26 | /* chars used as small naturals (so that `char' is reserved for characters) */ 27 | typedef unsigned char lu_byte; 28 | 29 | 30 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) 31 | 32 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) 33 | 34 | 35 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ 36 | 37 | /* 38 | ** conversion of pointer to integer 39 | ** this is for hashing only; there is no problem if the integer 40 | ** cannot hold the whole pointer value 41 | */ 42 | #define IntPoint(p) ((unsigned int)(lu_mem)(p)) 43 | 44 | 45 | 46 | /* type to ensure maximum alignment */ 47 | typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; 48 | 49 | 50 | /* result of a `usual argument conversion' over lua_Number */ 51 | typedef LUAI_UACNUMBER l_uacNumber; 52 | 53 | 54 | /* internal assertions for in-house debugging */ 55 | #ifdef lua_assert 56 | 57 | #define check_exp(c,e) (lua_assert(c), (e)) 58 | #define api_check(l,e) lua_assert(e) 59 | 60 | #else 61 | 62 | #define lua_assert(c) ((void)0) 63 | #define check_exp(c,e) (e) 64 | #define api_check luai_apicheck 65 | 66 | #endif 67 | 68 | 69 | #ifndef UNUSED 70 | #define UNUSED(x) ((void)(x)) /* to avoid warnings */ 71 | #endif 72 | 73 | 74 | #ifndef cast 75 | #define cast(t, exp) ((t)(exp)) 76 | #endif 77 | 78 | #define cast_byte(i) cast(lu_byte, (i)) 79 | #define cast_num(i) cast(lua_Number, (i)) 80 | #define cast_int(i) cast(int, (i)) 81 | 82 | 83 | 84 | /* 85 | ** type for virtual-machine instructions 86 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 87 | */ 88 | typedef lu_int32 Instruction; 89 | 90 | 91 | 92 | /* maximum stack for a Lua function */ 93 | #define MAXSTACK 250 94 | 95 | 96 | 97 | /* minimum size for the string table (must be power of 2) */ 98 | #ifndef MINSTRTABSIZE 99 | #define MINSTRTABSIZE 32 100 | #endif 101 | 102 | 103 | /* minimum size for string buffer */ 104 | #ifndef LUA_MINBUFFER 105 | #define LUA_MINBUFFER 32 106 | #endif 107 | 108 | 109 | #ifndef lua_lock 110 | #define lua_lock(L) ((void) 0) 111 | #define lua_unlock(L) ((void) 0) 112 | #endif 113 | 114 | #ifndef luai_threadyield 115 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} 116 | #endif 117 | 118 | 119 | /* 120 | ** macro to control inclusion of some hard tests on stack reallocation 121 | */ 122 | #ifndef HARDSTACKTESTS 123 | #define condhardstacktests(x) ((void)0) 124 | #else 125 | #define condhardstacktests(x) x 126 | #endif 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /golua/lua/lua51/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, 28 | OPR_CONCAT, 29 | OPR_NE, OPR_EQ, 30 | OPR_LT, OPR_LE, OPR_GT, OPR_GE, 31 | OPR_AND, OPR_OR, 32 | OPR_NOBINOPR 33 | } BinOpr; 34 | 35 | 36 | typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 37 | 38 | 39 | #define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) 40 | 41 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 42 | 43 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 44 | 45 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 46 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 47 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 48 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 49 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 50 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 51 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 52 | LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); 53 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 54 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 55 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 56 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 57 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 58 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 59 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 60 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 61 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 62 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 63 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 64 | LUAI_FUNC int luaK_jump (FuncState *fs); 65 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 66 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 67 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 68 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 69 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 70 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); 71 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 72 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); 73 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /golua/lua/lua52/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.84.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lmem_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "ldebug.h" 16 | #include "ldo.h" 17 | #include "lgc.h" 18 | #include "lmem.h" 19 | #include "lobject.h" 20 | #include "lstate.h" 21 | 22 | 23 | 24 | /* 25 | ** About the realloc function: 26 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 27 | ** (`osize' is the old size, `nsize' is the new size) 28 | ** 29 | ** * frealloc(ud, NULL, x, s) creates a new block of size `s' (no 30 | ** matter 'x'). 31 | ** 32 | ** * frealloc(ud, p, x, 0) frees the block `p' 33 | ** (in this specific case, frealloc must return NULL); 34 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 35 | ** (which is equivalent to free(NULL) in ANSI C) 36 | ** 37 | ** frealloc returns NULL if it cannot create or reallocate the area 38 | ** (any reallocation to an equal or smaller size cannot fail!) 39 | */ 40 | 41 | 42 | 43 | #define MINSIZEARRAY 4 44 | 45 | 46 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 47 | int limit, const char *what) { 48 | void *newblock; 49 | int newsize; 50 | if (*size >= limit/2) { /* cannot double it? */ 51 | if (*size >= limit) /* cannot grow even a little? */ 52 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); 53 | newsize = limit; /* still have at least one free place */ 54 | } 55 | else { 56 | newsize = (*size)*2; 57 | if (newsize < MINSIZEARRAY) 58 | newsize = MINSIZEARRAY; /* minimum size */ 59 | } 60 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 61 | *size = newsize; /* update only when everything else is OK */ 62 | return newblock; 63 | } 64 | 65 | 66 | l_noret luaM_toobig (lua_State *L) { 67 | luaG_runerror(L, "memory allocation error: block too big"); 68 | } 69 | 70 | 71 | 72 | /* 73 | ** generic allocation routine. 74 | */ 75 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 76 | void *newblock; 77 | global_State *g = G(L); 78 | size_t realosize = (block) ? osize : 0; 79 | lua_assert((realosize == 0) == (block == NULL)); 80 | #if defined(HARDMEMTESTS) 81 | if (nsize > realosize && g->gcrunning) 82 | luaC_fullgc(L, 1); /* force a GC whenever possible */ 83 | #endif 84 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); 85 | if (newblock == NULL && nsize > 0) { 86 | api_check(L, nsize > realosize, 87 | "realloc cannot fail when shrinking a block"); 88 | if (g->gcrunning) { 89 | luaC_fullgc(L, 1); /* try to free some memory... */ 90 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ 91 | } 92 | if (newblock == NULL) 93 | luaD_throw(L, LUA_ERRMEM); 94 | } 95 | lua_assert((nsize == 0) == (newblock == NULL)); 96 | g->GCdebt = (g->GCdebt + nsize) - realosize; 97 | return newblock; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /golua/lua/lua53/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.91.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lmem_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lgc.h" 20 | #include "lmem.h" 21 | #include "lobject.h" 22 | #include "lstate.h" 23 | 24 | 25 | 26 | /* 27 | ** About the realloc function: 28 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 29 | ** ('osize' is the old size, 'nsize' is the new size) 30 | ** 31 | ** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no 32 | ** matter 'x'). 33 | ** 34 | ** * frealloc(ud, p, x, 0) frees the block 'p' 35 | ** (in this specific case, frealloc must return NULL); 36 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 37 | ** (which is equivalent to free(NULL) in ISO C) 38 | ** 39 | ** frealloc returns NULL if it cannot create or reallocate the area 40 | ** (any reallocation to an equal or smaller size cannot fail!) 41 | */ 42 | 43 | 44 | 45 | #define MINSIZEARRAY 4 46 | 47 | 48 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 49 | int limit, const char *what) { 50 | void *newblock; 51 | int newsize; 52 | if (*size >= limit/2) { /* cannot double it? */ 53 | if (*size >= limit) /* cannot grow even a little? */ 54 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); 55 | newsize = limit; /* still have at least one free place */ 56 | } 57 | else { 58 | newsize = (*size)*2; 59 | if (newsize < MINSIZEARRAY) 60 | newsize = MINSIZEARRAY; /* minimum size */ 61 | } 62 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 63 | *size = newsize; /* update only when everything else is OK */ 64 | return newblock; 65 | } 66 | 67 | 68 | l_noret luaM_toobig (lua_State *L) { 69 | luaG_runerror(L, "memory allocation error: block too big"); 70 | } 71 | 72 | 73 | 74 | /* 75 | ** generic allocation routine. 76 | */ 77 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 78 | void *newblock; 79 | global_State *g = G(L); 80 | size_t realosize = (block) ? osize : 0; 81 | lua_assert((realosize == 0) == (block == NULL)); 82 | #if defined(HARDMEMTESTS) 83 | if (nsize > realosize && g->gcrunning) 84 | luaC_fullgc(L, 1); /* force a GC whenever possible */ 85 | #endif 86 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); 87 | if (newblock == NULL && nsize > 0) { 88 | lua_assert(nsize > realosize); /* cannot fail when shrinking a block */ 89 | if (g->version) { /* is state fully built? */ 90 | luaC_fullgc(L, 1); /* try to free some memory... */ 91 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ 92 | } 93 | if (newblock == NULL) 94 | luaD_throw(L, LUA_ERRMEM); 95 | } 96 | lua_assert((nsize == 0) == (newblock == NULL)); 97 | g->GCdebt = (g->GCdebt + nsize) - realosize; 98 | return newblock; 99 | } 100 | 101 | -------------------------------------------------------------------------------- /golua/lua/lua51/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** See Copyright Notice in lua.h 4 | */ 5 | 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | 11 | #include "lopcodes.h" 12 | 13 | 14 | /* ORDER OP */ 15 | 16 | const char *const luaP_opnames[NUM_OPCODES+1] = { 17 | "MOVE", 18 | "LOADK", 19 | "LOADBOOL", 20 | "LOADNIL", 21 | "GETUPVAL", 22 | "GETGLOBAL", 23 | "GETTABLE", 24 | "SETGLOBAL", 25 | "SETUPVAL", 26 | "SETTABLE", 27 | "NEWTABLE", 28 | "SELF", 29 | "ADD", 30 | "SUB", 31 | "MUL", 32 | "DIV", 33 | "MOD", 34 | "POW", 35 | "UNM", 36 | "NOT", 37 | "LEN", 38 | "CONCAT", 39 | "JMP", 40 | "EQ", 41 | "LT", 42 | "LE", 43 | "TEST", 44 | "TESTSET", 45 | "CALL", 46 | "TAILCALL", 47 | "RETURN", 48 | "FORLOOP", 49 | "FORPREP", 50 | "TFORLOOP", 51 | "SETLIST", 52 | "CLOSE", 53 | "CLOSURE", 54 | "VARARG", 55 | NULL 56 | }; 57 | 58 | 59 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) 60 | 61 | const lu_byte luaP_opmodes[NUM_OPCODES] = { 62 | /* T A B C mode opcode */ 63 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 64 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 65 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 66 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ 67 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 68 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ 69 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 70 | ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ 71 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ 72 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ 73 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ 74 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ 75 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ 76 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ 77 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ 78 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ 79 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ 80 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ 81 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ 82 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ 83 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ 84 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ 85 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ 86 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ 87 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ 88 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ 89 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ 90 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ 91 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ 92 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ 93 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ 94 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ 95 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ 96 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ 97 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ 98 | ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ 99 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 100 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 101 | }; 102 | 103 | -------------------------------------------------------------------------------- /golua/lua/lua52/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.58.1.1 2013/04/12 18:48:47 roberto Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, 28 | OPR_CONCAT, 29 | OPR_EQ, OPR_LT, OPR_LE, 30 | OPR_NE, OPR_GT, OPR_GE, 31 | OPR_AND, OPR_OR, 32 | OPR_NOBINOPR 33 | } BinOpr; 34 | 35 | 36 | typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 37 | 38 | 39 | #define getcode(fs,e) ((fs)->f->code[(e)->u.info]) 40 | 41 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 42 | 43 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 44 | 45 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 46 | 47 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 48 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 49 | LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); 50 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 51 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 52 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 53 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 54 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 55 | LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); 56 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 57 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 58 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 59 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 60 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 61 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 62 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 63 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 64 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 65 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 66 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 67 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 68 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 69 | LUAI_FUNC int luaK_jump (FuncState *fs); 70 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 71 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 72 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 73 | LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level); 74 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 75 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 76 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 77 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 78 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 79 | expdesc *v2, int line); 80 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 81 | 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /golua/lua/lua54/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* 16 | * WARNING: if you change the order of this enumeration, 17 | * grep "ORDER TM" and "ORDER OP" 18 | */ 19 | typedef enum { 20 | TM_INDEX, 21 | TM_NEWINDEX, 22 | TM_GC, 23 | TM_MODE, 24 | TM_LEN, 25 | TM_EQ, /* last tag method with fast access */ 26 | TM_ADD, 27 | TM_SUB, 28 | TM_MUL, 29 | TM_MOD, 30 | TM_POW, 31 | TM_DIV, 32 | TM_IDIV, 33 | TM_BAND, 34 | TM_BOR, 35 | TM_BXOR, 36 | TM_SHL, 37 | TM_SHR, 38 | TM_UNM, 39 | TM_BNOT, 40 | TM_LT, 41 | TM_LE, 42 | TM_CONCAT, 43 | TM_CALL, 44 | TM_CLOSE, 45 | TM_N /* number of elements in the enum */ 46 | } TMS; 47 | 48 | 49 | /* 50 | ** Mask with 1 in all fast-access methods. A 1 in any of these bits 51 | ** in the flag of a (meta)table means the metatable does not have the 52 | ** corresponding metamethod field. (Bit 7 of the flag is used for 53 | ** 'isrealasize'.) 54 | */ 55 | #define maskflags (~(~0u << (TM_EQ + 1))) 56 | 57 | 58 | /* 59 | ** Test whether there is no tagmethod. 60 | ** (Because tagmethods use raw accesses, the result may be an "empty" nil.) 61 | */ 62 | #define notm(tm) ttisnil(tm) 63 | 64 | 65 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 66 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 67 | 68 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 69 | 70 | #define ttypename(x) luaT_typenames_[(x) + 1] 71 | 72 | LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];) 73 | 74 | 75 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 76 | 77 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 78 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 79 | TMS event); 80 | LUAI_FUNC void luaT_init (lua_State *L); 81 | 82 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 83 | const TValue *p2, const TValue *p3); 84 | LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f, 85 | const TValue *p1, const TValue *p2, StkId p3); 86 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 87 | StkId res, TMS event); 88 | LUAI_FUNC void luaT_tryconcatTM (lua_State *L); 89 | LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1, 90 | const TValue *p2, int inv, StkId res, TMS event); 91 | LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2, 92 | int inv, StkId res, TMS event); 93 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 94 | const TValue *p2, TMS event); 95 | LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, 96 | int inv, int isfloat, TMS event); 97 | 98 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams, 99 | CallInfo *ci, const Proto *p); 100 | LUAI_FUNC void luaT_getvarargs (lua_State *L, CallInfo *ci, 101 | StkId where, int wanted); 102 | 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /handler/69shuba.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "log" 7 | "regexp" 8 | "strings" 9 | "unicode/utf8" 10 | 11 | "github.com/PuerkitoBio/goquery" 12 | "github.com/missdeer/getnovel/config" 13 | "github.com/missdeer/golib/ic" 14 | ) 15 | 16 | func preprocess69xinshuChapterListURL(u string) string { 17 | reg := regexp.MustCompile(`https://www\.69shuba\.com/book/([0-9]+)\.htm`) 18 | if reg.MatchString(u) { 19 | ss := reg.FindAllStringSubmatch(u, -1) 20 | s := ss[0] 21 | return fmt.Sprintf("https://www.69shuba.com/book/%s/", s[1]) 22 | } 23 | return u 24 | } 25 | 26 | func extract69xinshuChapterList(u string, rawPageContent []byte) (title string, chapters []*config.NovelChapterInfo) { 27 | c := ic.Convert("gbk", "utf-8", rawPageContent) 28 | c = bytes.Replace(c, []byte("\r\n"), []byte(""), -1) 29 | c = bytes.Replace(c, []byte("\r"), []byte(""), -1) 30 | c = bytes.Replace(c, []byte("\n"), []byte(""), -1) 31 | 32 | doc, err := goquery.NewDocumentFromReader(bytes.NewReader(c)) 33 | if err != nil { 34 | log.Fatal(err) 35 | } 36 | doc.Find("div.bread a").Each(func(index int, item *goquery.Selection) { 37 | title = item.Text() 38 | }) 39 | if strings.HasSuffix(title, `章节列表`) { 40 | for i := 0; i < 4; i++ { 41 | _, size := utf8.DecodeLastRuneInString(title) 42 | title = title[:len(title)-size] 43 | } 44 | } 45 | doc.Find("#catalog li").Each(func(i int, s *goquery.Selection) { 46 | if a := s.Find("a"); a != nil { 47 | if href, exists := a.Attr("href"); exists { 48 | chapters = append(chapters, &config.NovelChapterInfo{ 49 | Index: i + 1, 50 | Title: a.Text(), 51 | URL: href, 52 | }) 53 | } 54 | } 55 | }) 56 | 57 | return 58 | } 59 | 60 | func extract69xinshuChapterContent(u string, rawPageContent []byte) (c []byte) { 61 | c = ic.Convert("gbk", "utf-8", rawPageContent) 62 | doc, err := goquery.NewDocumentFromReader(bytes.NewReader(c)) 63 | if err != nil { 64 | log.Fatal(err) 65 | } 66 | 67 | doc.Find("h1.hide720").Remove() 68 | doc.Find("div.txtinfo.hide720").Remove() 69 | doc.Find("div.contentadv").Remove() 70 | doc.Find("div.bottom-ad").Remove() 71 | doc.Find("div#txtright").Remove() 72 | 73 | html, err := doc.Find("div.txtnav").Html() 74 | if err != nil { 75 | log.Fatal(err) 76 | } 77 | c = bytes.Replace([]byte(html), []byte(` `), []byte(" "), -1) 78 | c = bytes.Replace(c, []byte("

"), []byte("
"), -1) 79 | c = bytes.Replace(c, []byte("

"), []byte("
"), -1) 80 | c = bytes.Replace(c, []byte("\xe2\x80\x83"), []byte(" "), -1) 81 | return 82 | } 83 | 84 | func init() { 85 | registerNovelSiteHandler(&config.NovelSiteHandler{ 86 | Sites: []config.NovelSite{ 87 | { 88 | Title: `69书吧`, 89 | Urls: []string{`https://www.69shuba.com/`}, 90 | }, 91 | }, 92 | CanHandle: func(u string) bool { 93 | patterns := []string{ 94 | `https://www\.69shuba\.com/book/[0-9]+/`, 95 | `^https://www\.69shuba\.com/book/[0-9]+\.html?$`, 96 | } 97 | for _, pattern := range patterns { 98 | reg := regexp.MustCompile(pattern) 99 | if reg.MatchString(u) { 100 | return true 101 | } 102 | } 103 | return false 104 | }, 105 | PreprocessChapterListURL: preprocess69xinshuChapterListURL, 106 | ExtractChapterList: extract69xinshuChapterList, 107 | ExtractChapterContent: extract69xinshuChapterContent, 108 | }) 109 | } 110 | --------------------------------------------------------------------------------