├── .gitignore ├── .gitmodules ├── LICENSE ├── Licenses.md ├── Lua └── Info.plist ├── Luade.xcodeproj ├── .gitignore ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── adrianlabbe.xcuserdatad │ │ └── IDEFindNavigatorScopes.plist ├── xcshareddata │ └── xcschemes │ │ ├── Luade.xcscheme │ │ └── Run Lua Script.xcscheme └── xcuserdata │ └── .gitignore ├── Luade.xcworkspace ├── contents.xcworkspacedata ├── xcshareddata │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── .gitignore ├── Luade ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Icon-App-20x20@1x.png │ │ ├── Icon-App-20x20@2x.png │ │ ├── Icon-App-20x20@3x.png │ │ ├── Icon-App-29x29@1x.png │ │ ├── Icon-App-29x29@2x.png │ │ ├── Icon-App-29x29@3x.png │ │ ├── Icon-App-40x40@1x.png │ │ ├── Icon-App-40x40@2x.png │ │ ├── Icon-App-40x40@3x.png │ │ ├── Icon-App-60x60@2x.png │ │ ├── Icon-App-60x60@3x.png │ │ ├── Icon-App-76x76@1x.png │ │ ├── Icon-App-76x76@2x.png │ │ ├── Icon-App-83.5x83.5@2x.png │ │ └── ItunesArtwork@2x.png │ ├── Contents.json │ ├── NewFolder_Normal.imageset │ │ ├── Contents.json │ │ ├── NewFolder_Normal@2x.png │ │ └── NewFolder_Normal@3x.png │ ├── back.imageset │ │ ├── Contents.json │ │ ├── back@1x.png │ │ ├── back@2x.png │ │ └── back@3x.png │ ├── fileIcon.imageset │ │ ├── Contents.json │ │ ├── fileIcon@1x.png │ │ └── fileIcon@2x.png │ ├── forward.imageset │ │ ├── Contents.json │ │ ├── forward@1x.png │ │ ├── forward@2x.png │ │ └── forward@3x.png │ └── play.imageset │ │ ├── Contents.json │ │ ├── play@1x.png │ │ └── play@2x.png ├── Base.lproj │ └── LaunchScreen.storyboard ├── Extensions │ ├── String.swift │ ├── UITextView+currentWord.swift │ └── UIWindow.swift ├── Help.lua ├── Info.plist ├── Localizable.strings ├── Luade-Bridging-Header.h ├── Luade.entitlements ├── Main.storyboard ├── Models │ ├── ConsolePanelLayout.swift │ ├── IO.swift │ ├── Localizable.swift │ ├── LuaDelegate.swift │ ├── LuaDocument.swift │ └── LuaLexer.swift ├── RelativePathForScript.swift ├── Samples │ ├── Device.lua │ ├── Hello World.lua │ ├── Pasteboard.lua │ ├── Search the Web.lua │ └── Share Sheet.lua ├── Share Sheet Example.lua ├── Share Sheet README.lua ├── Singletons │ ├── AppDelegate.swift │ ├── Lua.swift │ └── ReviewHelper.swift ├── Untitled Share Sheet.lua ├── Untitled.lua ├── View controllers │ ├── ConsoleViewController.swift │ ├── DocumentBrowserViewController.swift │ ├── DocumentationViewController.swift │ ├── EditorViewController.swift │ ├── REPLConsoleViewController.swift │ └── TemplatesViewController.swift ├── Views │ ├── ConsoleTextView.swift │ └── FileCollectionViewCell.swift ├── commandDictionary.plist ├── device library │ ├── device.h │ └── device.m ├── lua │ ├── ios_error.h │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.c │ ├── lbitlib.c │ ├── lcode.c │ ├── lcode.h │ ├── lcorolib.c │ ├── lctype.c │ ├── lctype.h │ ├── ldblib.c │ ├── ldebug.c │ ├── ldebug.h │ ├── ldo.c │ ├── ldo.h │ ├── ldump.c │ ├── lfunc.c │ ├── lfunc.h │ ├── lgc.c │ ├── lgc.h │ ├── linit.c │ ├── liolib.c │ ├── ljumptab.h │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmathlib.c │ ├── lmem.c │ ├── lmem.h │ ├── loadlib.c │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── loslib.c │ ├── lparser.c │ ├── lparser.h │ ├── lprefix.h │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── lstrlib.c │ ├── ltable.c │ ├── ltable.h │ ├── ltablib.c │ ├── ltests.c │ ├── ltests.h │ ├── ltm.c │ ├── ltm.h │ ├── lua.c │ ├── lua.h │ ├── lua.hpp │ ├── luac.c │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lutf8lib.c │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ └── lzio.h ├── lua_copyright.c ├── lua_copyright.h ├── openURL function │ ├── openURL.h │ └── openURL.m ├── pasteboard library │ ├── pasteboard.h │ └── pasteboard.m └── sharesheet library │ ├── lua_extensionContext.h │ ├── lua_extensionContext.m │ ├── lua_viewController.h │ ├── lua_viewController.m │ ├── sharesheet.h │ └── sharesheet.m ├── Podfile ├── Podfile.lock ├── README.md ├── Run Lua Script ├── Base.lproj │ └── MainInterface.storyboard ├── Info.plist └── Run Lua Script.entitlements ├── docs ├── Device.html ├── Licenses.md ├── Pasteboard.html ├── ShareSheet.html ├── index.html └── styles.css ├── mockup.png └── setup.sh /.gitignore: -------------------------------------------------------------------------------- 1 | Pods 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ios_system"] 2 | path = ios_system 3 | url = https://github.com/ColdGrub1384/ios_system -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Adrian Labbé 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Lua/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /Luade.xcodeproj/.gitignore: -------------------------------------------------------------------------------- 1 | *.xcuserdatad 2 | -------------------------------------------------------------------------------- /Luade.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Luade.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Luade.xcodeproj/project.xcworkspace/xcuserdata/adrianlabbe.xcuserdatad/IDEFindNavigatorScopes.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Luade.xcodeproj/xcshareddata/xcschemes/Luade.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Luade.xcodeproj/xcshareddata/xcschemes/Run Lua Script.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 6 | 9 | 10 | 16 | 22 | 23 | 24 | 30 | 36 | 37 | 38 | 39 | 40 | 45 | 46 | 47 | 48 | 54 | 55 | 56 | 57 | 58 | 59 | 70 | 72 | 78 | 79 | 80 | 81 | 82 | 83 | 90 | 92 | 98 | 99 | 100 | 101 | 103 | 104 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /Luade.xcodeproj/xcuserdata/.gitignore: -------------------------------------------------------------------------------- 1 | *.xcuserdatad 2 | -------------------------------------------------------------------------------- /Luade.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Luade.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Luade.xcworkspace/xcuserdata/.gitignore: -------------------------------------------------------------------------------- 1 | *.xcuserdatad 2 | -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "ItunesArtwork@2x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Luade/Assets.xcassets/NewFolder_Normal.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "NewFolder_Normal@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "NewFolder_Normal@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | }, 22 | "properties" : { 23 | "template-rendering-intent" : "template" 24 | } 25 | } -------------------------------------------------------------------------------- /Luade/Assets.xcassets/NewFolder_Normal.imageset/NewFolder_Normal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/NewFolder_Normal.imageset/NewFolder_Normal@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/NewFolder_Normal.imageset/NewFolder_Normal@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/NewFolder_Normal.imageset/NewFolder_Normal@3x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/back.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "back@1x.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "back@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "back@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | }, 23 | "properties" : { 24 | "template-rendering-intent" : "template" 25 | } 26 | } -------------------------------------------------------------------------------- /Luade/Assets.xcassets/back.imageset/back@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/back.imageset/back@1x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/back.imageset/back@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/back.imageset/back@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/back.imageset/back@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/back.imageset/back@3x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/fileIcon.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "fileIcon@1x.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "fileIcon@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /Luade/Assets.xcassets/fileIcon.imageset/fileIcon@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/fileIcon.imageset/fileIcon@1x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/fileIcon.imageset/fileIcon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/fileIcon.imageset/fileIcon@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/forward.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "forward@1x.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "forward@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "forward@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | }, 23 | "properties" : { 24 | "template-rendering-intent" : "template" 25 | } 26 | } -------------------------------------------------------------------------------- /Luade/Assets.xcassets/forward.imageset/forward@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/forward.imageset/forward@1x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/forward.imageset/forward@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/forward.imageset/forward@2x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/forward.imageset/forward@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/forward.imageset/forward@3x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/play.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "play@1x.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "play@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /Luade/Assets.xcassets/play.imageset/play@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/play.imageset/play@1x.png -------------------------------------------------------------------------------- /Luade/Assets.xcassets/play.imageset/play@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Assets.xcassets/play.imageset/play@2x.png -------------------------------------------------------------------------------- /Luade/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Luade/Extensions/String.swift: -------------------------------------------------------------------------------- 1 | // 2 | // String.swift 3 | // Pyto 4 | // 5 | // Created by Adrian Labbe on 9/9/18. 6 | // Copyright © 2018 Adrian Labbé. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | @objc extension NSString { 12 | 13 | /// Replaces the first occurrence of the given `String` with another `String`. 14 | /// 15 | /// - Parameters: 16 | /// - string: String to replace. 17 | /// - replacement: Replacement of `string`. 18 | /// 19 | /// - Returns: This string replacing the first occurrence of `string` with `replacement`. 20 | @objc func replacingFirstOccurrence(of string: String, with replacement: String) -> String { 21 | return (self as String).replacingFirstOccurrence(of: string, with: replacement) 22 | } 23 | } 24 | 25 | 26 | extension String { 27 | 28 | /// Replaces the first occurrence of the given `String` with another `String`. 29 | /// 30 | /// - Parameters: 31 | /// - string: String to replace. 32 | /// - replacement: Replacement of `string`. 33 | /// 34 | /// - Returns: This string replacing the first occurrence of `string` with `replacement`. 35 | func replacingFirstOccurrence(of string: String, with replacement: String) -> String { 36 | guard let range = self.range(of: string) else { return self } 37 | return replacingCharacters(in: range, with: replacement) 38 | } 39 | 40 | /// Returns a C pointer to pass this `String` to C functions. 41 | var cValue: UnsafeMutablePointer { 42 | guard let cString = cString(using: .utf8) else { 43 | let buffer = UnsafeMutablePointer.allocate(capacity: 1) 44 | buffer.pointee = 0 45 | return buffer 46 | } 47 | let buffer = UnsafeMutablePointer.allocate(capacity: cString.count) 48 | memcpy(buffer, cString, cString.count) 49 | 50 | return buffer 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Luade/Extensions/UITextView+currentWord.swift: -------------------------------------------------------------------------------- 1 | // Taken 2 | 3 | import UIKit 4 | 5 | extension UITextView { 6 | 7 | /// Returns the range of the selected word. 8 | var currentWordRange: UITextRange? { 9 | let beginning = beginningOfDocument 10 | 11 | if let start = position(from: beginning, offset: selectedRange.location), 12 | let end = position(from: start, offset: selectedRange.length) { 13 | 14 | let textRange = tokenizer.rangeEnclosingPosition(end, with: .word, inDirection: UITextDirection(rawValue: 1)) 15 | 16 | return textRange ?? selectedTextRange 17 | } 18 | return selectedTextRange 19 | } 20 | 21 | /// Returns the current typed word. 22 | var currentWord : String? { 23 | if let textRange = currentWordRange { 24 | return text(in: textRange) 25 | } else { 26 | return nil 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Luade/Extensions/UIWindow.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | extension UIWindow { 4 | 5 | /// Returns the top View controller of the window usable to present modally a View controller. 6 | var topViewController: UIViewController? { 7 | var top = self.rootViewController 8 | while true { 9 | if let presented = top?.presentedViewController { 10 | top = presented 11 | } else if let nav = top as? UINavigationController { 12 | top = nav.visibleViewController 13 | } else if let tab = top as? UITabBarController { 14 | top = tab.selectedViewController 15 | } else { 16 | break 17 | } 18 | } 19 | return top 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Luade/Help.lua: -------------------------------------------------------------------------------- 1 | -- Welcome to Luade! 2 | 3 | -- Luade is a Lua IDE. 4 | 5 | -- You can start by creating a script by tapping the "+" button on the main screen. You can then type your code and run it by tapping the Play button. 6 | 7 | -- You can also code inside the REPL (Main Screen > Tab bar > REPL) 8 | 9 | -- You can include all scripts in your current directory. 10 | 11 | -- You can use all libraries, like `os` for example: 12 | 13 | print(os.clock()) 14 | 15 | -- You can request for input: 16 | 17 | io.write("What's your name? ") 18 | name = io.read() 19 | print("Hello "..name.."!") 20 | -------------------------------------------------------------------------------- /Luade/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeIconFiles 11 | 12 | CFBundleTypeName 13 | Lua Scripts 14 | CFBundleTypeRole 15 | Editor 16 | LSHandlerRank 17 | Owner 18 | LSItemContentTypes 19 | 20 | ch.marcela.ada.Luade.lua 21 | 22 | 23 | 24 | CFBundleExecutable 25 | $(EXECUTABLE_NAME) 26 | CFBundleIdentifier 27 | $(PRODUCT_BUNDLE_IDENTIFIER) 28 | CFBundleInfoDictionaryVersion 29 | 6.0 30 | CFBundleName 31 | $(PRODUCT_NAME) 32 | CFBundlePackageType 33 | APPL 34 | CFBundleShortVersionString 35 | 3.0.2 36 | CFBundleVersion 37 | 2 38 | LSRequiresIPhoneOS 39 | 40 | NSUbiquitousContainers 41 | 42 | iCloud.ch.marcela.ada.Luade 43 | 44 | NSUbiquitousContainerIsDocumentScopePublic 45 | 46 | NSUbiquitousContainerName 47 | Luade 48 | NSUbiquitousContainerSupportedFolderLevels 49 | Any 50 | 51 | 52 | UILaunchStoryboardName 53 | LaunchScreen 54 | UIMainStoryboardFile 55 | Main 56 | UIRequiredDeviceCapabilities 57 | 58 | armv7 59 | 60 | UIStatusBarStyle 61 | UIStatusBarStyleLightContent 62 | UISupportedInterfaceOrientations 63 | 64 | UIInterfaceOrientationPortrait 65 | UIInterfaceOrientationLandscapeLeft 66 | UIInterfaceOrientationLandscapeRight 67 | 68 | UISupportedInterfaceOrientations~ipad 69 | 70 | UIInterfaceOrientationPortrait 71 | UIInterfaceOrientationPortraitUpsideDown 72 | UIInterfaceOrientationLandscapeLeft 73 | UIInterfaceOrientationLandscapeRight 74 | 75 | UISupportsDocumentBrowser 76 | 77 | UTExportedTypeDeclarations 78 | 79 | 80 | UTTypeConformsTo 81 | 82 | public.script 83 | 84 | UTTypeDescription 85 | Lua Script 86 | UTTypeIconFiles 87 | 88 | UTTypeIdentifier 89 | ch.marcela.ada.Luade.lua 90 | UTTypeTagSpecification 91 | 92 | public.filename-extension 93 | lua 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /Luade/Localizable.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/Luade/Localizable.strings -------------------------------------------------------------------------------- /Luade/Luade-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | #include "lua/lua.h" 6 | #include "lua_copyright.h" 7 | #import 8 | #import 9 | -------------------------------------------------------------------------------- /Luade/Luade.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.developer.icloud-container-identifiers 6 | 7 | iCloud.$(CFBundleIdentifier) 8 | 9 | com.apple.developer.icloud-services 10 | 11 | CloudDocuments 12 | 13 | com.apple.developer.ubiquity-container-identifiers 14 | 15 | iCloud.$(CFBundleIdentifier) 16 | 17 | com.apple.security.application-groups 18 | 19 | group.luade.sharing 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Luade/Models/ConsolePanelLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConsolePanelLayout.swift 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 11/27/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | import FloatingPanel 10 | 11 | /// The layout used for the console panel. 12 | class ConsolePanelLayout: FloatingPanelLayout { 13 | public var initialPosition: FloatingPanelPosition { 14 | return .tip 15 | } 16 | public var supportedPositions: Set { 17 | return [.full, .tip] 18 | } 19 | 20 | public func insetFor(position: FloatingPanelPosition) -> CGFloat? { 21 | switch position { 22 | case .full: return 16.0 23 | case .tip: return 69.0 24 | default: return nil 25 | } 26 | } 27 | 28 | public func prepareLayout(surfaceView: UIView, in view: UIView) -> [NSLayoutConstraint] { 29 | return [ 30 | surfaceView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 8.0), 31 | surfaceView.widthAnchor.constraint(equalToConstant: 291), 32 | ] 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Luade/Models/IO.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IO.swift 3 | // Pyto 4 | // 5 | // Created by Adrian Labbe on 9/24/18. 6 | // Copyright © 2018 Adrian Labbé. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension FileHandle { 12 | 13 | /// Writes given string to the file. 14 | /// 15 | /// - Parameters: 16 | /// - str: Text to print. 17 | func write(_ str: String) { 18 | if let data = str.data(using: .utf8) { 19 | write(data) 20 | } 21 | } 22 | } 23 | 24 | /// A class for managing input and output. 25 | class IO { 26 | 27 | /// Initialize for writting to the given terminal. 28 | /// 29 | /// - Parameters: 30 | /// - console: The terminal that receives output. 31 | init() { 32 | stdout = fdopen(outputPipe.fileHandleForWriting.fileDescriptor, "w") 33 | stderr = fdopen(errorPipe.fileHandleForWriting.fileDescriptor, "w") 34 | stdin = fdopen(inputPipe.fileHandleForReading.fileDescriptor, "r") 35 | outputPipe.fileHandleForReading.readabilityHandler = { handle in 36 | if let str = String(data: handle.availableData, encoding: .utf8) { 37 | print(str, terminator: "") 38 | DispatchQueue.main.async { 39 | self.console?.textView?.text.append(str) 40 | self.console?.textView?.scrollToBottom() 41 | self.console?.console += str 42 | } 43 | } 44 | } 45 | errorPipe.fileHandleForReading.readabilityHandler = outputPipe.fileHandleForReading.readabilityHandler 46 | setbuf(stdout!, nil) 47 | setbuf(stderr!, nil) 48 | } 49 | 50 | /// The shared instance. 51 | static let shared = IO() 52 | 53 | /// The Console view controller that receives. 54 | var console: ConsoleViewController? 55 | 56 | /// The stdin file. 57 | var stdin: UnsafeMutablePointer? 58 | 59 | /// The stdout file. 60 | var stdout: UnsafeMutablePointer? 61 | 62 | /// The stderr file. 63 | var stderr: UnsafeMutablePointer? 64 | 65 | /// The output pipe. 66 | var outputPipe = Pipe() 67 | 68 | /// The error pipe. 69 | var errorPipe = Pipe() 70 | 71 | /// The input pipe. 72 | var inputPipe = Pipe() 73 | 74 | /// Sends given input for current running `ios_system` command. 75 | /// 76 | /// - Parameters: 77 | /// - input: Input to send. 78 | func send(input: String) { 79 | if let data = input.data(using: .utf8) { 80 | inputPipe.fileHandleForWriting.write(data) 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Luade/Models/LuaDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LuaDelegate.swift 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 11/28/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /// The delegate for `Lua` singleton. 12 | /// 13 | /// All theses methods are called from the Lua queue, so you should return to the main thread to touch the UI. 14 | protocol LuaDelegate { 15 | 16 | /// Called when Lua will start a script. 17 | /// 18 | /// - Parameters: 19 | /// - lua: The Lua instance. 20 | /// - arguments: The arguments send to the main function. 21 | func lua(_ lua: Lua, willStartScriptWithArguments arguments: [String]) 22 | 23 | /// Called when Lua will start the REPL. 24 | /// 25 | /// - Parameters: 26 | /// - lua: The Lua instance. 27 | func luaWillStartREPL(_ lua: Lua) 28 | 29 | /// Called when Lua exited. 30 | /// 31 | /// - Parameters: 32 | /// - lua: The Lua instance. 33 | /// - code: The exit code returned by lua. 34 | func lua(_ lua: Lua, didExitWithCode code: Int32) 35 | } 36 | -------------------------------------------------------------------------------- /Luade/Models/LuaDocument.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PyDocument.swift 3 | // Pyto 4 | // 5 | // Created by Adrian Labbe on 9/8/18. 6 | // Copyright © 2018 Adrian Labbé. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /// Errors opening the document. 12 | enum LuaDocumentError: Error { 13 | case unableToParseText 14 | case unableToEncodeText 15 | } 16 | 17 | /// A document representing a Lua script. 18 | class LuaDocument: UIDocument { 19 | 20 | /// The text of the Lua script to save. 21 | var text = "" 22 | 23 | override func contents(forType typeName: String) throws -> Any { 24 | guard let data = text.data(using: .utf8) else { 25 | throw LuaDocumentError.unableToEncodeText 26 | } 27 | 28 | return data 29 | } 30 | 31 | override func load(fromContents contents: Any, ofType typeName: String?) throws { 32 | guard let data = contents as? Data else { 33 | // This would be a developer error. 34 | fatalError("*** \(contents) is not an instance of NSData.***") 35 | } 36 | 37 | guard let newText = String(data: data, encoding: .utf8) else { 38 | throw LuaDocumentError.unableToParseText 39 | } 40 | 41 | text = newText 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Luade/Models/LuaLexer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LuaLexer.swift 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 11/27/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | import SourceEditor 10 | import SavannaKit 11 | 12 | /// A lexer for Lua. 13 | class LuaLexer: SourceCodeRegexLexer { 14 | 15 | /// Lua keywords. 16 | let keywords = "and break do else elseif end false for function if in local nil not or repeat return then true until while".components(separatedBy: " ") 17 | 18 | lazy private var generators: [TokenGenerator] = { 19 | 20 | var generators = [TokenGenerator?]() 21 | // Functions 22 | generators.append(regexGenerator("(\\bprint(?=\\())|(\\brequire(?=\\())", tokenType: .identifier)) 23 | 24 | generators.append(regexGenerator("(?<=[^a-zA-Z])\\d+", tokenType: .number)) 25 | 26 | generators.append(regexGenerator("\\.\\w+", tokenType: .identifier)) 27 | 28 | generators.append(keywordGenerator(keywords, tokenType: .keyword)) 29 | 30 | // Line comment 31 | generators.append(regexGenerator("--(.*)", tokenType: .comment)) 32 | 33 | // Block comment or multi-line string literal 34 | generators.append(regexGenerator("--[[.*--]])", options: [.dotMatchesLineSeparators], tokenType: .comment)) 35 | 36 | // Single-line string literal 37 | generators.append(regexGenerator("('.*')|(\".*\")", tokenType: .string)) 38 | 39 | // Editor placeholder 40 | var editorPlaceholderPattern = "(<#)[^\"\\n]*" 41 | editorPlaceholderPattern += "(#>)" 42 | generators.append(regexGenerator(editorPlaceholderPattern, tokenType: .editorPlaceholder)) 43 | 44 | return generators.compactMap( { $0 }) 45 | }() 46 | 47 | public func generators(source: String) -> [TokenGenerator] { 48 | return generators 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Luade/RelativePathForScript.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RelativePathForScript.swift 3 | // Pyto 4 | // 5 | // Created by Adrian Labbe on 11/16/18. 6 | // Copyright © 2018 Adrian Labbé. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /// Get the path for the given script relative to the Documents directory. 12 | /// 13 | /// - Parameters: 14 | /// - url: The full script's URL. 15 | /// 16 | /// - Returns: 17 | /// - The relative path. 18 | func RelativePathForScript(_ url: URL) -> String { 19 | var filePath = url.path 20 | filePath = filePath.replacingFirstOccurrence(of: DocumentBrowserViewController.localContainerURL.path, with: "") 21 | if let iCloudPath = DocumentBrowserViewController.iCloudContainerURL?.path { 22 | filePath = filePath.replacingFirstOccurrence(of: iCloudPath, with: "iCloud/") 23 | } 24 | 25 | if filePath.hasPrefix("/private/") { 26 | filePath = filePath.replacingFirstOccurrence(of: "/private/", with: "") 27 | } 28 | 29 | if filePath.hasPrefix("/") { 30 | filePath.removeFirst() 31 | } 32 | 33 | return filePath 34 | } 35 | -------------------------------------------------------------------------------- /Luade/Samples/Device.lua: -------------------------------------------------------------------------------- 1 | -- This example shows how getting device information. 2 | 3 | print(device.name()) 4 | print(device.model()) 5 | print(device.systemName().." "..device.systemVersion()) 6 | 7 | print("\n") 8 | 9 | charging = "not charging" 10 | if device.isCharging() then 11 | charging = "charging" 12 | end 13 | 14 | print("Battery level: "..device.batteryLevel()..", "..charging) 15 | -------------------------------------------------------------------------------- /Luade/Samples/Hello World.lua: -------------------------------------------------------------------------------- 1 | -- This example shows how output and input works in Luade. 2 | 3 | io.write("What's your name? ") 4 | name = io.read() 5 | print("Hello "..name.."!") 6 | -------------------------------------------------------------------------------- /Luade/Samples/Pasteboard.lua: -------------------------------------------------------------------------------- 1 | -- This example shows how copy and pasting text. 2 | 3 | print("Copied text: "..pasteboard.string()) -- Paste text 4 | pasteboard.setString("Hello World!") -- Copy 'Hello World!' 5 | -------------------------------------------------------------------------------- /Luade/Samples/Search the Web.lua: -------------------------------------------------------------------------------- 1 | -- This example shows how opening an URL. 2 | 3 | io.write("Type to search on Google: ") 4 | query = io.read() 5 | 6 | function urlencode(str) -- Taken from https://gist.github.com/sysnajar/879e92b1ceab1b09dc65 7 | if (str) then 8 | str = string.gsub (str, "\n", "\r\n") 9 | str = string.gsub (str, "([^%w ])", 10 | function (c) return string.format ("%%%02X", string.byte(c)) end) 11 | str = string.gsub (str, " ", "+") 12 | end 13 | return str 14 | end 15 | 16 | googleURL = "https://www.google.com/search?q="..urlencode(query) 17 | 18 | openURL(googleURL) 19 | -------------------------------------------------------------------------------- /Luade/Samples/Share Sheet.lua: -------------------------------------------------------------------------------- 1 | -- This script shows an example of how passing data from the iOS share sheet to scripts. 2 | 3 | -- With Luade, you can share text, URLs and files with your scripts. 4 | 5 | -- For that, just create a script the the "Share Sheet" directory. Then, when you share a text, an URL or a file, you can select 'Run Lua Script' and select the script you created. 6 | 7 | -- You can test this example from the Share Sheet. 8 | 9 | str = sharesheet.string() -- Text 10 | url = sharesheet.url() -- URL 11 | filePath = sharesheet.filePath() -- File Path 12 | 13 | if str ~= nil then 14 | print("String: "..str) -- Text is found 15 | elseif url ~= nil then 16 | print("URL: "..url) -- URL is found 17 | elseif filePath ~= nil then 18 | print("File Path: "..filePath) -- File is found 19 | else 20 | print("No item found") -- No item found 21 | end 22 | -------------------------------------------------------------------------------- /Luade/Share Sheet Example.lua: -------------------------------------------------------------------------------- 1 | -- This script shows an example of how passing data from the iOS share sheet to scripts. 2 | 3 | -- With Luade, you can share text, URLs and files with your scripts. 4 | 5 | -- For that, just create a script IN THIS DIRECTORY. Then, when you share a text, an URL or a file, you can select 'Run Lua Script' and select the script you created. 6 | 7 | str = sharesheet.string() -- Text 8 | url = sharesheet.url() -- URL 9 | filePath = sharesheet.filePath() -- File Path 10 | 11 | if str ~= nil then 12 | print("String: "..str) -- Text is found 13 | elseif url ~= nil then 14 | print("URL: "..url) -- URL is found 15 | elseif filePath ~= nil then 16 | print("File Path: "..filePath) -- File is found 17 | else 18 | print("No item found") -- No item found 19 | end 20 | -------------------------------------------------------------------------------- /Luade/Share Sheet README.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | With Luade, you can share text, URLs and files with your scripts. 3 | 4 | For that, just create a script IN THIS DIRECTORY. Then, when you share a text, an URL or a file, you can select 'Run Lua Script' and select the script you created. 5 | --]] 6 | 7 | sharesheet.string() -- Retrieves text 8 | sharesheet.url() -- Retrieves an URL 9 | sharesheet.filePath() -- Retrieves the path of a file 10 | 11 | -- One of the previous functions should return something depending on what you shared. They will return `nil` if the script is ran from the app. 12 | 13 | -------------------------------------------------------------------------------- /Luade/Singletons/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 11/25/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ios_system 11 | 12 | /// The URL for shared scripts URL. 13 | let sharedScriptsURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.luade.sharing")?.appendingPathComponent("Documents/Share Sheet") ?? FileManager.default.urls(for: .documentDirectory, in: .allDomainsMask)[0] 14 | 15 | /// The app's delegate 16 | @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { 17 | 18 | var window: UIWindow? 19 | 20 | func applicationDidFinishLaunching(_ application: UIApplication) { 21 | 22 | UIMenuController.shared.menuItems = [ 23 | UIMenuItem(title: Localizable.MenuItems.open, action: #selector(FileCollectionViewCell.open(_:))), 24 | UIMenuItem(title: Localizable.MenuItems.run, action: #selector(FileCollectionViewCell.run(_:))), 25 | UIMenuItem(title: Localizable.MenuItems.rename, action: #selector(FileCollectionViewCell.rename(_:))), 26 | UIMenuItem(title: Localizable.MenuItems.remove, action: #selector(FileCollectionViewCell.remove(_:))), 27 | UIMenuItem(title: Localizable.MenuItems.copy, action: #selector(FileCollectionViewCell.copyFile(_:))), 28 | UIMenuItem(title: Localizable.MenuItems.move, action: #selector(FileCollectionViewCell.move(_:))) 29 | ] 30 | 31 | window?.accessibilityIgnoresInvertColors = true 32 | 33 | #if MAINAPP 34 | ReviewHelper.shared.launches += 1 35 | ReviewHelper.shared.requestReview() 36 | #endif 37 | 38 | if !FileManager.default.fileExists(atPath: sharedScriptsURL.path) { 39 | do { 40 | try FileManager.default.createDirectory(at: sharedScriptsURL, withIntermediateDirectories: true, attributes: nil) 41 | } catch { 42 | print(error.localizedDescription) 43 | } 44 | } 45 | 46 | if let shareSheetExampleURL = Bundle.main.url(forResource: "Share Sheet Example", withExtension: "lua") { 47 | 48 | let newShareSheetExampleURL = sharedScriptsURL.appendingPathComponent("Example.lua") 49 | 50 | do { 51 | if FileManager.default.fileExists(atPath: newShareSheetExampleURL.path), let defaultData = (try? Data(contentsOf: shareSheetExampleURL)), let data = (try? Data(contentsOf: newShareSheetExampleURL)), defaultData == data { 52 | try FileManager.default.removeItem(at: newShareSheetExampleURL) 53 | } 54 | 55 | // try FileManager.default.copyItem(at: shareSheetExampleURL, to: newShareSheetExampleURL) 56 | // Removed! 57 | } catch { 58 | print(error.localizedDescription) 59 | } 60 | } 61 | 62 | if let shareSheetREADMEURL = Bundle.main.url(forResource: "Share Sheet README", withExtension: "lua") { 63 | 64 | let newShareSheetREADMEURL = sharedScriptsURL.appendingPathComponent("README.lua") 65 | 66 | do { 67 | if FileManager.default.fileExists(atPath: newShareSheetREADMEURL.path), let defaultData = (try? Data(contentsOf: shareSheetREADMEURL)), let data = (try? Data(contentsOf: newShareSheetREADMEURL)), defaultData == data { 68 | try FileManager.default.removeItem(at: newShareSheetREADMEURL) 69 | } 70 | 71 | // try FileManager.default.copyItem(at: shareSheetREADMEURL, to: newShareSheetREADMEURL) 72 | // Removed! 73 | } catch { 74 | print(error.localizedDescription) 75 | } 76 | } 77 | 78 | let docs = DocumentBrowserViewController.localContainerURL 79 | let iCloudDriveContainer = DocumentBrowserViewController.iCloudContainerURL 80 | 81 | if let iCloudURL = iCloudDriveContainer { 82 | if !FileManager.default.fileExists(atPath: iCloudURL.path) { 83 | try? FileManager.default.createDirectory(at: iCloudURL, withIntermediateDirectories: true, attributes: nil) 84 | } 85 | 86 | for file in ((try? FileManager.default.contentsOfDirectory(at: docs, includingPropertiesForKeys: nil, options: .init(rawValue: 0))) ?? []) { 87 | 88 | try? FileManager.default.moveItem(at: file, to: iCloudURL.appendingPathComponent(file.lastPathComponent)) 89 | } 90 | } 91 | } 92 | 93 | func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool { 94 | return true 95 | } 96 | 97 | func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool { 98 | return true 99 | } 100 | 101 | func application(_ app: UIApplication, open inputURL: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { 102 | 103 | guard let documentBrowserViewController = DocumentBrowserViewController.visible else { 104 | window?.rootViewController?.dismiss(animated: true, completion: { 105 | _ = self.application(app, open: inputURL, options: options) 106 | }) 107 | return true 108 | } 109 | 110 | // Ensure the URL is a file URL 111 | guard inputURL.isFileURL else { 112 | return false 113 | } 114 | 115 | // Reveal / import the document at the URL 116 | 117 | documentBrowserViewController.openDocument(inputURL, run: false) 118 | 119 | return true 120 | } 121 | 122 | func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { 123 | 124 | let root = application.keyWindow?.rootViewController 125 | 126 | func runScript() { 127 | if let path = userActivity.userInfo?["filePath"] as? String { 128 | 129 | var url = URL(fileURLWithPath: RelativePathForScript(URL(fileURLWithPath: path)).replacingFirstOccurrence(of: "iCloud/", with: (DocumentBrowserViewController.iCloudContainerURL?.path ?? DocumentBrowserViewController.localContainerURL.path)+"/"), relativeTo: FileManager.default.urls(for: .documentDirectory, in: .allDomainsMask).first) 130 | 131 | while !FileManager.default.fileExists(atPath: url.path), url.pathComponents.contains("iCloud") { 132 | 133 | url = URL(fileURLWithPath: url.path.replacingFirstOccurrence(of: "iCloud/", with: "")) 134 | } 135 | 136 | if FileManager.default.fileExists(atPath: url.path) { 137 | DocumentBrowserViewController.visible?.openDocument(url, run: true) 138 | } else { 139 | let alert = UIAlertController(title: Localizable.Errors.errorReadingFile, message: nil, preferredStyle: .alert) 140 | alert.addAction(UIAlertAction(title: Localizable.ok, style: .cancel, handler: nil)) 141 | root?.present(alert, animated: true, completion: nil) 142 | } 143 | } else { 144 | print("Invalid shortcut!") 145 | } 146 | } 147 | 148 | if root?.presentedViewController != nil { 149 | root?.dismiss(animated: true, completion: { 150 | runScript() 151 | }) 152 | } else { 153 | runScript() 154 | } 155 | 156 | return true 157 | } 158 | } 159 | 160 | -------------------------------------------------------------------------------- /Luade/Singletons/Lua.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lua.swift 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 11/27/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | import ios_system 10 | 11 | /// A class representing Lua. 12 | class Lua { 13 | 14 | /// Returns the version and copyright of Lua. 15 | var version: String { 16 | return String(cString: lua_copyright()) 17 | } 18 | 19 | private func setupIOS_SYSTEM(io: IO) { 20 | if ios_kill() == 0 { 21 | delegate?.lua(self, didExitWithCode: 9) 22 | } 23 | io.inputPipe = Pipe() 24 | io.stdin = fdopen(io.inputPipe.fileHandleForReading.fileDescriptor, "r") 25 | stdin = io.stdin ?? stdin 26 | 27 | let handler = io.outputPipe.fileHandleForReading.readabilityHandler 28 | io.outputPipe = Pipe() 29 | io.errorPipe = Pipe() 30 | io.outputPipe.fileHandleForReading.readabilityHandler = handler 31 | io.errorPipe.fileHandleForReading.readabilityHandler = handler 32 | 33 | io.stdout = fdopen(io.outputPipe.fileHandleForWriting.fileDescriptor, "w") 34 | io.stderr = fdopen(io.errorPipe.fileHandleForWriting.fileDescriptor, "w") 35 | setbuf(io.stdout!, nil) 36 | setbuf(io.stderr!, nil) 37 | 38 | ios_switchSession(io.stdout) 39 | ios_setStreams(io.stdin, io.stdout, io.stderr) 40 | } 41 | 42 | /// The queue running Lua. 43 | let queue = DispatchQueue.global(qos: .userInteractive) 44 | 45 | /// Runs the given script. 46 | /// 47 | /// - Parameters: 48 | /// - script: The path of the script to run. 49 | /// - io: The I/O stream to use. 50 | func run(script: String, withIO io: IO) { 51 | queue.async { 52 | let directoryURL = URL(fileURLWithPath: script).deletingLastPathComponent() 53 | self.setupIOS_SYSTEM(io: io) 54 | putenv("LUA_PATH=\(directoryURL.path)/?.lua;".cValue) 55 | ios_setDirectoryURL(directoryURL) 56 | self.delegate?.lua(self, willStartScriptWithArguments: [script]) 57 | self.delegate?.lua(self, didExitWithCode: ios_system("lua '\(script)'")) 58 | } 59 | } 60 | 61 | /// Runs the REPL. 62 | /// 63 | /// - Parameters: 64 | /// - io: The I/O stream to use. 65 | func runREPL(withIO io: IO) { 66 | queue.async { 67 | self.setupIOS_SYSTEM(io: io) 68 | ios_setDirectoryURL(DocumentBrowserViewController.localContainerURL) 69 | if let iCloudDrive = DocumentBrowserViewController.iCloudContainerURL?.path { 70 | putenv("LUA_PATH=\(DocumentBrowserViewController.localContainerURL.path)/?.lua;\(iCloudDrive)/?.lua".cValue) 71 | } else { 72 | putenv("LUA_PATH=\(DocumentBrowserViewController.localContainerURL.path)/?.lua".cValue) 73 | } 74 | self.delegate?.luaWillStartREPL(self) 75 | self.delegate?.lua(self, didExitWithCode: ios_system("lua")) 76 | } 77 | } 78 | 79 | /// The delegate. 80 | var delegate: LuaDelegate? 81 | 82 | // MARK: - Singleton 83 | 84 | /// The shared and unique instance. 85 | static let shared = Lua() 86 | 87 | private init() {} 88 | } 89 | -------------------------------------------------------------------------------- /Luade/Singletons/ReviewHelper.swift: -------------------------------------------------------------------------------- 1 | // This source file is part of the https://github.com/ColdGrub1384/Pisth open source project 2 | // 3 | // Copyright (c) 2017 - 2018 Adrian Labbé 4 | // Licensed under Apache License v2.0 5 | // 6 | // See https://raw.githubusercontent.com/ColdGrub1384/Pisth/master/LICENSE for license information 7 | import Foundation 8 | import StoreKit 9 | 10 | /// Helper used to request app review based on app launches. 11 | class ReviewHelper { 12 | 13 | /// Request review, reset points and append current date to `reviewRequests`. 14 | func requestReview() { 15 | if launches >= minLaunches { 16 | launches = 0 17 | if #available(iOS 10.3, *) { 18 | SKStoreReviewController.requestReview() 19 | } 20 | } 21 | } 22 | 23 | // MARK: - Singleton 24 | 25 | /// Shared and unique instance. 26 | static let shared = ReviewHelper() 27 | private init() {} 28 | 29 | // MARK: - Launches tracking 30 | 31 | /// App launches incremented in `AppDelegate.application(_:, didFinishLaunchingWithOptions:)`. 32 | /// 33 | /// Launches are saved to `UserDefaults`. 34 | var launches: Int { 35 | 36 | get { 37 | return UserDefaults.standard.integer(forKey: "launches") 38 | } 39 | 40 | set { 41 | UserDefaults.standard.set(newValue, forKey: "launches") 42 | } 43 | } 44 | 45 | /// Minimum launches for asking for review. 46 | var minLaunches = 3 47 | } 48 | -------------------------------------------------------------------------------- /Luade/Untitled Share Sheet.lua: -------------------------------------------------------------------------------- 1 | 2 | str = sharesheet.string() -- Text 3 | url = sharesheet.url() -- URL 4 | filePath = sharesheet.filePath() -- File Path 5 | 6 | -- Process data here 7 | -------------------------------------------------------------------------------- /Luade/Untitled.lua: -------------------------------------------------------------------------------- 1 | 2 | -- Code here 3 | 4 | io.write("What's your name? ") 5 | name = io.read() 6 | print("Hello "..name.."!") 7 | -------------------------------------------------------------------------------- /Luade/View controllers/DocumentationViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DocumentationViewController.swift 3 | // Pyto 4 | // 5 | // Created by Adrian Labbe on 12/8/18. 6 | // Copyright © 2018 Adrian Labbé. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import WebKit 11 | 12 | /// A View controller showing offline documentation. 13 | class DocumentationViewController: UIViewController, WKNavigationDelegate { 14 | 15 | /// The button for going back. 16 | var goBackButton: UIBarButtonItem! 17 | 18 | /// The button for going forward. 19 | var goForwardButton: UIBarButtonItem! 20 | 21 | /// The Web view containing documentation. 22 | var webView: WKWebView! 23 | 24 | /// Goes back. 25 | @objc func goBack() { 26 | webView.goBack() 27 | } 28 | 29 | /// Goes forward 30 | @objc func goForward() { 31 | webView.goForward() 32 | } 33 | 34 | /// Closes this View controller. 35 | @objc func close() { 36 | dismiss(animated: true, completion: nil) 37 | } 38 | 39 | // MARK: - View controller 40 | 41 | override func viewDidLoad() { 42 | super.viewDidLoad() 43 | 44 | edgesForExtendedLayout = [] 45 | 46 | webView = WKWebView(frame: view.frame) 47 | webView.backgroundColor = .black 48 | webView.allowsBackForwardNavigationGestures = true 49 | webView.navigationDelegate = self 50 | webView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 51 | view.addSubview(webView) 52 | 53 | if let url = Bundle.main.url(forResource: "docs", withExtension: "") { 54 | webView.loadFileURL(url.appendingPathComponent("index.html"), allowingReadAccessTo: url) 55 | } 56 | 57 | goBackButton = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(goBack)) 58 | goForwardButton = UIBarButtonItem(image: UIImage(named: "forward"), style: .plain, target: self, action: #selector(goForward)) 59 | 60 | toolbarItems = [goBackButton, UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil), goForwardButton] 61 | 62 | navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(close)) 63 | } 64 | 65 | override func viewDidAppear(_ animated: Bool) { 66 | super.viewDidAppear(animated) 67 | 68 | navigationController?.setToolbarHidden(false, animated: true) 69 | } 70 | 71 | // MARK: - Navigation delegate 72 | 73 | func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { 74 | goBackButton.isEnabled = webView.canGoBack 75 | goForwardButton.isEnabled = webView.canGoForward 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /Luade/View controllers/REPLConsoleViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // REPLConsoleViewController.swift 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 11/25/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ios_system 11 | 12 | /// The View controller for interacting for the REPL. 13 | class REPLConsoleViewController: ConsoleViewController { 14 | 15 | // MARK: - Console view controller 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | 20 | edgesForExtendedLayout = [] 21 | 22 | title = "REPL" 23 | navigationItem.largeTitleDisplayMode = .always 24 | } 25 | 26 | override func viewDidAppear(_ animated: Bool) { 27 | super.viewDidAppear(animated) 28 | 29 | textView.text = "" 30 | console = "" 31 | prompt = "" 32 | isAskingForInput = false 33 | 34 | lua_viewController = self 35 | Lua.shared.delegate = self 36 | Lua.shared.runREPL(withIO: IO.shared) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Luade/View controllers/TemplatesViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TemplatesViewController.swift 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/9/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /// A View controller containing scripts templates. 12 | class TemplatesViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { 13 | 14 | /// All chossable templates. 15 | lazy var templates: [URL] = { 16 | guard let templatesURL = Bundle.main.url(forResource: "Samples", withExtension: nil), let files = (try? FileManager.default.contentsOfDirectory(at: templatesURL, includingPropertiesForKeys: nil, options: [])) else { 17 | return [] 18 | } 19 | 20 | var scripts = [URL]() 21 | for file in files { 22 | if file.pathExtension.lowercased() == "lua" { 23 | scripts.append(file) 24 | } 25 | } 26 | 27 | return scripts 28 | }() 29 | 30 | // MARK: - Collection view data source 31 | 32 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 33 | return templates.count 34 | } 35 | 36 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 37 | 38 | guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "file", for: indexPath) as? FileCollectionViewCell else { 39 | return UICollectionViewCell() 40 | } 41 | 42 | cell.file = templates[indexPath.row] 43 | 44 | return cell 45 | } 46 | 47 | // MARK: - Collection view delegate 48 | 49 | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 50 | guard let docBrowser = DocumentBrowserViewController.visible else { 51 | return 52 | } 53 | 54 | let templateURL = templates[indexPath.row] 55 | 56 | var newURL: URL 57 | if templateURL.lastPathComponent == "Share Sheet.lua" { 58 | newURL = sharedScriptsURL.appendingPathComponent("Example.lua") 59 | } else if let iCloudDrive = DocumentBrowserViewController.iCloudContainerURL { 60 | newURL = iCloudDrive.appendingPathComponent(templateURL.lastPathComponent) 61 | } else { 62 | newURL = DocumentBrowserViewController.localContainerURL.appendingPathComponent(templateURL.lastPathComponent) 63 | } 64 | 65 | var i = 2 66 | let name = newURL.deletingPathExtension().lastPathComponent 67 | while FileManager.default.fileExists(atPath: newURL.path) { 68 | newURL = newURL.deletingLastPathComponent().appendingPathComponent("\(name) \(i).lua") 69 | 70 | i += 1 71 | } 72 | 73 | do { 74 | try FileManager.default.copyItem(at: templateURL, to: newURL) 75 | _ = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { (_) in 76 | docBrowser.openDocument(newURL, run: false) 77 | }) 78 | } catch { 79 | let alert = UIAlertController(title: Localizable.Errors.errorCreatingFile, message: error.localizedDescription, preferredStyle: .alert) 80 | alert.addAction(UIAlertAction(title: Localizable.cancel, style: .default, handler: nil)) 81 | present(alert, animated: true, completion: nil) 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Luade/Views/ConsoleTextView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConsoleTextView.swift 3 | // Pyto 4 | // 5 | // Created by Adrian Labbe on 9/18/18. 6 | // Copyright © 2018 Adrian Labbé. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /// A text view containing the output of a Lua program. 12 | class ConsoleTextView: UITextView { 13 | 14 | private func setupView() { 15 | backgroundColor = .clear 16 | textColor = .white 17 | font = UIFont(name: "Courier", size: UIFont.systemFontSize) 18 | smartQuotesType = .no 19 | autocapitalizationType = .none 20 | autocorrectionType = .no 21 | keyboardAppearance = .dark 22 | } 23 | 24 | /// Scrolls to the bottom of the text view. 25 | func scrollToBottom() { 26 | let range = NSMakeRange((text as NSString).length - 1, 1) 27 | scrollRangeToVisible(range) 28 | } 29 | 30 | override func caretRect(for position: UITextPosition) -> CGRect { 31 | 32 | if position != endOfDocument { 33 | if selectedRange.length == 0 { 34 | return CGRect.zero 35 | } else { 36 | return super.caretRect(for: position) 37 | } 38 | } 39 | 40 | var rect = super.caretRect(for: position) 41 | rect.size.width = 10 42 | 43 | return rect 44 | } 45 | 46 | override init(frame: CGRect, textContainer: NSTextContainer?) { 47 | super.init(frame: frame, textContainer: textContainer) 48 | 49 | setupView() 50 | } 51 | 52 | required init?(coder aDecoder: NSCoder) { 53 | super.init(coder: aDecoder) 54 | 55 | setupView() 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Luade/commandDictionary.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | lua 6 | 7 | Lua.framework/Lua 8 | lua_main 9 | 10 | no 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Luade/device library/device.h: -------------------------------------------------------------------------------- 1 | // 2 | // device.h 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/5/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "../lua/lua.h" 10 | #include "../lua/lauxlib.h" 11 | 12 | /// Opens the 'device' module. 13 | int luaopen_device(lua_State *L); 14 | -------------------------------------------------------------------------------- /Luade/device library/device.m: -------------------------------------------------------------------------------- 1 | // 2 | // device.m 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/5/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "device.h" 10 | #import 11 | 12 | static int device_name(lua_State *L) { 13 | lua_pushstring(L, UIDevice.currentDevice.name.UTF8String); 14 | return 1; 15 | } 16 | 17 | static int device_systemName(lua_State *L) { 18 | lua_pushstring(L, UIDevice.currentDevice.systemName.UTF8String); 19 | return 1; 20 | } 21 | 22 | static int device_systemVersion(lua_State *L) { 23 | lua_pushstring(L, UIDevice.currentDevice.systemVersion.UTF8String); 24 | return 1; 25 | } 26 | 27 | static int device_model(lua_State *L) { 28 | lua_pushstring(L, UIDevice.currentDevice.model.UTF8String); 29 | return 1; 30 | } 31 | 32 | static int device_localizedModel(lua_State *L) { 33 | lua_pushstring(L, UIDevice.currentDevice.localizedModel.UTF8String); 34 | return 1; 35 | } 36 | 37 | static int device_isPortrait(lua_State *L) { 38 | lua_pushboolean(L, (UIDeviceOrientationIsPortrait(UIDevice.currentDevice.orientation))); 39 | return 1; 40 | } 41 | 42 | static int device_isLandscape(lua_State *L) { 43 | lua_pushboolean(L, (UIDeviceOrientationIsLandscape(UIDevice.currentDevice.orientation))); 44 | return 1; 45 | } 46 | 47 | static int device_batteryLevel(lua_State *L) { 48 | [UIDevice.currentDevice setBatteryMonitoringEnabled: YES]; 49 | lua_pushnumber(L, UIDevice.currentDevice.batteryLevel); 50 | [UIDevice.currentDevice setBatteryMonitoringEnabled: NO]; 51 | return 1; 52 | } 53 | 54 | static int device_isCharging(lua_State *L) { 55 | [UIDevice.currentDevice setBatteryMonitoringEnabled: YES]; 56 | lua_pushboolean(L, (UIDevice.currentDevice.batteryState == UIDeviceBatteryStateFull || UIDevice.currentDevice.batteryState == UIDeviceBatteryStateCharging)); 57 | [UIDevice.currentDevice setBatteryMonitoringEnabled: NO]; 58 | return 1; 59 | } 60 | 61 | static const struct luaL_Reg device_functions[] = { 62 | 63 | { "name", device_name }, 64 | { "systemName", device_systemName }, 65 | { "systemVersion", device_systemVersion }, 66 | { "model", device_model }, 67 | { "localizedModel", device_localizedModel }, 68 | { "isPortrait", device_isPortrait }, 69 | { "isLandscape", device_isLandscape }, 70 | { "batteryLevel", device_batteryLevel }, 71 | { "isCharging", device_isCharging }, 72 | { NULL, NULL } 73 | }; 74 | 75 | int luaopen_device(lua_State *L) { 76 | /* Create the metatable and put it on the stack. */ 77 | luaL_newmetatable(L, "device"); 78 | /* Duplicate the metatable on the stack (We know have 2). */ 79 | lua_pushvalue(L, -1); 80 | /* Pop the first metatable off the stack and assign it to __index 81 | * of the second one. We set the metatable for the table to itself. 82 | * This is equivalent to the following in lua: 83 | * metatable = {} 84 | * metatable.__index = metatable 85 | */ 86 | lua_setfield(L, -2, "__index"); 87 | 88 | /* Register the object.func functions into the table that is at the top of the 89 | * stack. */ 90 | luaL_newlib(L, device_functions); 91 | lua_setglobal(L, "device"); 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /Luade/lua/ios_error.h: -------------------------------------------------------------------------------- 1 | // 2 | // error.h 3 | // shell_cmds_ios 4 | // 5 | // Created by Nicolas Holzschuch on 16/06/2017. 6 | // Copyright © 2017 Nicolas Holzschuch. All rights reserved. 7 | // 8 | 9 | #ifndef ios_error_h 10 | #define ios_error_h 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #define errx compileError 21 | #define err compileError 22 | #define warn compileError 23 | #define warnx compileError 24 | #ifndef printf 25 | #define printf(...) fprintf (thread_stdout, ##__VA_ARGS__) 26 | #endif 27 | 28 | #define putchar(a) fputc(a, thread_stdout) 29 | #define getchar() fgetc(thread_stdin) 30 | #define getwchar() fgetwc(thread_stdin) 31 | // iswprint depends on the given locale, and setlocale() fails on iOS: 32 | #define iswprint(a) 1 33 | #define write ios_write 34 | #define fwrite ios_fwrite 35 | #define puts ios_puts 36 | #define fputs ios_fputs 37 | #define fputc ios_fputc 38 | #define putw ios_putw 39 | #define fflush ios_fflush 40 | 41 | 42 | // Thread-local input and output streams 43 | extern __thread FILE* thread_stdin; 44 | extern __thread FILE* thread_stdout; 45 | extern __thread FILE* thread_stderr; 46 | 47 | #define exit ios_exit 48 | #define abort() ios_exit(1) 49 | #define _exit ios_exit 50 | #define popen ios_popen 51 | #define pclose fclose 52 | #define system ios_system 53 | #define execv ios_execv 54 | #define execvp ios_execv 55 | #define execve ios_execve 56 | #define dup2 ios_dup2 57 | 58 | extern int ios_executable(const char* cmd); // is this command part of the "shell" commands? 59 | extern int ios_system(const char* inputCmd); // execute this command (executable file or builtin command) 60 | extern FILE *ios_popen(const char *command, const char *type); // Execute this command and pipe the result 61 | extern int ios_kill(void); // kill the current running command 62 | 63 | extern void ios_exit(int errorCode) __dead2; // set error code and exits from the thread. 64 | extern int ios_execv(const char *path, char* const argv[]); 65 | extern int ios_execve(const char *path, char* const argv[], char** envlist); 66 | extern int ios_dup2(int fd1, int fd2); 67 | extern int ios_isatty(int fd); 68 | extern const pthread_t ios_getLastThreadId(void); 69 | extern int ios_getCommandStatus(void); 70 | extern const char* ios_progname(void); 71 | 72 | extern ssize_t ios_write(int fildes, const void *buf, size_t nbyte); 73 | extern size_t ios_fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream); 74 | extern int ios_puts(const char *s); 75 | extern int ios_fputs(const char* s, FILE *stream); 76 | extern int ios_fputc(int c, FILE *stream); 77 | extern int ios_putw(int w, FILE *stream); 78 | extern int ios_fflush(FILE *stream); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | #endif /* ios_error_h */ 84 | -------------------------------------------------------------------------------- /Luade/lua/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 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 | -------------------------------------------------------------------------------- /Luade/lua/lbitlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lbitlib.c,v 1.30 2015/11/11 19:08:09 roberto Exp $ 3 | ** Standard library for bitwise operations 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lbitlib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lua.h" 14 | 15 | #include "lauxlib.h" 16 | #include "lualib.h" 17 | 18 | 19 | #if defined(LUA_COMPAT_BITLIB) /* { */ 20 | 21 | 22 | #define pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n)) 23 | #define checkunsigned(L,i) ((lua_Unsigned)luaL_checkinteger(L,i)) 24 | 25 | 26 | /* number of bits to consider in a number */ 27 | #if !defined(LUA_NBITS) 28 | #define LUA_NBITS 32 29 | #endif 30 | 31 | 32 | /* 33 | ** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must 34 | ** be made in two parts to avoid problems when LUA_NBITS is equal to the 35 | ** number of bits in a lua_Unsigned.) 36 | */ 37 | #define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) 38 | 39 | 40 | /* macro to trim extra bits */ 41 | #define trim(x) ((x) & ALLONES) 42 | 43 | 44 | /* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */ 45 | #define mask(n) (~((ALLONES << 1) << ((n) - 1))) 46 | 47 | 48 | 49 | static lua_Unsigned andaux (lua_State *L) { 50 | int i, n = lua_gettop(L); 51 | lua_Unsigned r = ~(lua_Unsigned)0; 52 | for (i = 1; i <= n; i++) 53 | r &= checkunsigned(L, i); 54 | return trim(r); 55 | } 56 | 57 | 58 | static int b_and (lua_State *L) { 59 | lua_Unsigned r = andaux(L); 60 | pushunsigned(L, r); 61 | return 1; 62 | } 63 | 64 | 65 | static int b_test (lua_State *L) { 66 | lua_Unsigned r = andaux(L); 67 | lua_pushboolean(L, r != 0); 68 | return 1; 69 | } 70 | 71 | 72 | static int b_or (lua_State *L) { 73 | int i, n = lua_gettop(L); 74 | lua_Unsigned r = 0; 75 | for (i = 1; i <= n; i++) 76 | r |= checkunsigned(L, i); 77 | pushunsigned(L, trim(r)); 78 | return 1; 79 | } 80 | 81 | 82 | static int b_xor (lua_State *L) { 83 | int i, n = lua_gettop(L); 84 | lua_Unsigned r = 0; 85 | for (i = 1; i <= n; i++) 86 | r ^= checkunsigned(L, i); 87 | pushunsigned(L, trim(r)); 88 | return 1; 89 | } 90 | 91 | 92 | static int b_not (lua_State *L) { 93 | lua_Unsigned r = ~checkunsigned(L, 1); 94 | pushunsigned(L, trim(r)); 95 | return 1; 96 | } 97 | 98 | 99 | static int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) { 100 | if (i < 0) { /* shift right? */ 101 | i = -i; 102 | r = trim(r); 103 | if (i >= LUA_NBITS) r = 0; 104 | else r >>= i; 105 | } 106 | else { /* shift left */ 107 | if (i >= LUA_NBITS) r = 0; 108 | else r <<= i; 109 | r = trim(r); 110 | } 111 | pushunsigned(L, r); 112 | return 1; 113 | } 114 | 115 | 116 | static int b_lshift (lua_State *L) { 117 | return b_shift(L, checkunsigned(L, 1), luaL_checkinteger(L, 2)); 118 | } 119 | 120 | 121 | static int b_rshift (lua_State *L) { 122 | return b_shift(L, checkunsigned(L, 1), -luaL_checkinteger(L, 2)); 123 | } 124 | 125 | 126 | static int b_arshift (lua_State *L) { 127 | lua_Unsigned r = checkunsigned(L, 1); 128 | lua_Integer i = luaL_checkinteger(L, 2); 129 | if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1)))) 130 | return b_shift(L, r, -i); 131 | else { /* arithmetic shift for 'negative' number */ 132 | if (i >= LUA_NBITS) r = ALLONES; 133 | else 134 | r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i)); /* add signal bit */ 135 | pushunsigned(L, r); 136 | return 1; 137 | } 138 | } 139 | 140 | 141 | static int b_rot (lua_State *L, lua_Integer d) { 142 | lua_Unsigned r = checkunsigned(L, 1); 143 | int i = d & (LUA_NBITS - 1); /* i = d % NBITS */ 144 | r = trim(r); 145 | if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */ 146 | r = (r << i) | (r >> (LUA_NBITS - i)); 147 | pushunsigned(L, trim(r)); 148 | return 1; 149 | } 150 | 151 | 152 | static int b_lrot (lua_State *L) { 153 | return b_rot(L, luaL_checkinteger(L, 2)); 154 | } 155 | 156 | 157 | static int b_rrot (lua_State *L) { 158 | return b_rot(L, -luaL_checkinteger(L, 2)); 159 | } 160 | 161 | 162 | /* 163 | ** get field and width arguments for field-manipulation functions, 164 | ** checking whether they are valid. 165 | ** ('luaL_error' called without 'return' to avoid later warnings about 166 | ** 'width' being used uninitialized.) 167 | */ 168 | static int fieldargs (lua_State *L, int farg, int *width) { 169 | lua_Integer f = luaL_checkinteger(L, farg); 170 | lua_Integer w = luaL_optinteger(L, farg + 1, 1); 171 | luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); 172 | luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); 173 | if (f + w > LUA_NBITS) 174 | luaL_error(L, "trying to access non-existent bits"); 175 | *width = (int)w; 176 | return (int)f; 177 | } 178 | 179 | 180 | static int b_extract (lua_State *L) { 181 | int w; 182 | lua_Unsigned r = trim(checkunsigned(L, 1)); 183 | int f = fieldargs(L, 2, &w); 184 | r = (r >> f) & mask(w); 185 | pushunsigned(L, r); 186 | return 1; 187 | } 188 | 189 | 190 | static int b_replace (lua_State *L) { 191 | int w; 192 | lua_Unsigned r = trim(checkunsigned(L, 1)); 193 | lua_Unsigned v = trim(checkunsigned(L, 2)); 194 | int f = fieldargs(L, 3, &w); 195 | lua_Unsigned m = mask(w); 196 | r = (r & ~(m << f)) | ((v & m) << f); 197 | pushunsigned(L, r); 198 | return 1; 199 | } 200 | 201 | 202 | static const luaL_Reg bitlib[] = { 203 | {"arshift", b_arshift}, 204 | {"band", b_and}, 205 | {"bnot", b_not}, 206 | {"bor", b_or}, 207 | {"bxor", b_xor}, 208 | {"btest", b_test}, 209 | {"extract", b_extract}, 210 | {"lrotate", b_lrot}, 211 | {"lshift", b_lshift}, 212 | {"replace", b_replace}, 213 | {"rrotate", b_rrot}, 214 | {"rshift", b_rshift}, 215 | {NULL, NULL} 216 | }; 217 | 218 | 219 | 220 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 221 | luaL_newlib(L, bitlib); 222 | return 1; 223 | } 224 | 225 | 226 | #else /* }{ */ 227 | 228 | 229 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 230 | return luaL_error(L, "library 'bit32' has been deprecated"); 231 | } 232 | 233 | #endif /* } */ 234 | -------------------------------------------------------------------------------- /Luade/lua/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.64 2016/01/05 16:22:37 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_MOD, OPR_POW, 28 | OPR_DIV, 29 | OPR_IDIV, 30 | OPR_BAND, OPR_BOR, OPR_BXOR, 31 | OPR_SHL, OPR_SHR, 32 | OPR_CONCAT, 33 | OPR_EQ, OPR_LT, OPR_LE, 34 | OPR_NE, OPR_GT, OPR_GE, 35 | OPR_AND, OPR_OR, 36 | OPR_NOBINOPR 37 | } BinOpr; 38 | 39 | 40 | typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 41 | 42 | 43 | /* get (pointer to) instruction of given 'expdesc' */ 44 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) 45 | 46 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 47 | 48 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 49 | 50 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 51 | 52 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 53 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 54 | LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); 55 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 56 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 57 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 58 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 59 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 60 | LUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n); 61 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 62 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 63 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 64 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 65 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 66 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 67 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 68 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 69 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 70 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 71 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 72 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 73 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 74 | LUAI_FUNC int luaK_jump (FuncState *fs); 75 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 76 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 77 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 78 | LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level); 79 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 80 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 81 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 82 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 83 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 84 | expdesc *v2, int line); 85 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 86 | 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /Luade/lua/lcorolib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcorolib.c,v 1.10 2016/04/11 19:19:55 roberto Exp $ 3 | ** Coroutine Library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lcorolib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lauxlib.h" 18 | #include "lualib.h" 19 | 20 | 21 | static lua_State *getco (lua_State *L) { 22 | lua_State *co = lua_tothread(L, 1); 23 | luaL_argcheck(L, co, 1, "thread expected"); 24 | return co; 25 | } 26 | 27 | 28 | static int auxresume (lua_State *L, lua_State *co, int narg) { 29 | int status; 30 | if (!lua_checkstack(co, narg)) { 31 | lua_pushliteral(L, "too many arguments to resume"); 32 | return -1; /* error flag */ 33 | } 34 | if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) { 35 | lua_pushliteral(L, "cannot resume dead coroutine"); 36 | return -1; /* error flag */ 37 | } 38 | lua_xmove(L, co, narg); 39 | status = lua_resume(co, L, narg); 40 | if (status == LUA_OK || status == LUA_YIELD) { 41 | int nres = lua_gettop(co); 42 | if (!lua_checkstack(L, nres + 1)) { 43 | lua_pop(co, nres); /* remove results anyway */ 44 | lua_pushliteral(L, "too many results to resume"); 45 | return -1; /* error flag */ 46 | } 47 | lua_xmove(co, L, nres); /* move yielded values */ 48 | return nres; 49 | } 50 | else { 51 | lua_xmove(co, L, 1); /* move error message */ 52 | return -1; /* error flag */ 53 | } 54 | } 55 | 56 | 57 | static int luaB_coresume (lua_State *L) { 58 | lua_State *co = getco(L); 59 | int r; 60 | r = auxresume(L, co, lua_gettop(L) - 1); 61 | if (r < 0) { 62 | lua_pushboolean(L, 0); 63 | lua_insert(L, -2); 64 | return 2; /* return false + error message */ 65 | } 66 | else { 67 | lua_pushboolean(L, 1); 68 | lua_insert(L, -(r + 1)); 69 | return r + 1; /* return true + 'resume' returns */ 70 | } 71 | } 72 | 73 | 74 | static int luaB_auxwrap (lua_State *L) { 75 | lua_State *co = lua_tothread(L, lua_upvalueindex(1)); 76 | int r = auxresume(L, co, lua_gettop(L)); 77 | if (r < 0) { 78 | if (lua_type(L, -1) == LUA_TSTRING) { /* error object is a string? */ 79 | luaL_where(L, 1); /* add extra info */ 80 | lua_insert(L, -2); 81 | lua_concat(L, 2); 82 | } 83 | return lua_error(L); /* propagate error */ 84 | } 85 | return r; 86 | } 87 | 88 | 89 | static int luaB_cocreate (lua_State *L) { 90 | lua_State *NL; 91 | luaL_checktype(L, 1, LUA_TFUNCTION); 92 | NL = lua_newthread(L); 93 | lua_pushvalue(L, 1); /* move function to top */ 94 | lua_xmove(L, NL, 1); /* move function from L to NL */ 95 | return 1; 96 | } 97 | 98 | 99 | static int luaB_cowrap (lua_State *L) { 100 | luaB_cocreate(L); 101 | lua_pushcclosure(L, luaB_auxwrap, 1); 102 | return 1; 103 | } 104 | 105 | 106 | static int luaB_yield (lua_State *L) { 107 | return lua_yield(L, lua_gettop(L)); 108 | } 109 | 110 | 111 | static int luaB_costatus (lua_State *L) { 112 | lua_State *co = getco(L); 113 | if (L == co) lua_pushliteral(L, "running"); 114 | else { 115 | switch (lua_status(co)) { 116 | case LUA_YIELD: 117 | lua_pushliteral(L, "suspended"); 118 | break; 119 | case LUA_OK: { 120 | lua_Debug ar; 121 | if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ 122 | lua_pushliteral(L, "normal"); /* it is running */ 123 | else if (lua_gettop(co) == 0) 124 | lua_pushliteral(L, "dead"); 125 | else 126 | lua_pushliteral(L, "suspended"); /* initial state */ 127 | break; 128 | } 129 | default: /* some error occurred */ 130 | lua_pushliteral(L, "dead"); 131 | break; 132 | } 133 | } 134 | return 1; 135 | } 136 | 137 | 138 | static int luaB_yieldable (lua_State *L) { 139 | lua_pushboolean(L, lua_isyieldable(L)); 140 | return 1; 141 | } 142 | 143 | 144 | static int luaB_corunning (lua_State *L) { 145 | int ismain = lua_pushthread(L); 146 | lua_pushboolean(L, ismain); 147 | return 2; 148 | } 149 | 150 | 151 | static const luaL_Reg co_funcs[] = { 152 | {"create", luaB_cocreate}, 153 | {"resume", luaB_coresume}, 154 | {"running", luaB_corunning}, 155 | {"status", luaB_costatus}, 156 | {"wrap", luaB_cowrap}, 157 | {"yield", luaB_yield}, 158 | {"isyieldable", luaB_yieldable}, 159 | {NULL, NULL} 160 | }; 161 | 162 | 163 | 164 | LUAMOD_API int luaopen_coroutine (lua_State *L) { 165 | luaL_newlib(L, co_funcs); 166 | return 1; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /Luade/lua/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 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 | -------------------------------------------------------------------------------- /Luade/lua/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 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 | -------------------------------------------------------------------------------- /Luade/lua/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 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 | -------------------------------------------------------------------------------- /Luade/lua/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 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 | -------------------------------------------------------------------------------- /Luade/lua/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c,v 2.37 2015/10/08 15:53:49 roberto Exp $ 3 | ** save precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ldump_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lobject.h" 18 | #include "lstate.h" 19 | #include "lundump.h" 20 | 21 | 22 | typedef struct { 23 | lua_State *L; 24 | lua_Writer writer; 25 | void *data; 26 | int strip; 27 | int status; 28 | } DumpState; 29 | 30 | 31 | /* 32 | ** All high-level dumps go through DumpVector; you can change it to 33 | ** change the endianness of the result 34 | */ 35 | #define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D) 36 | 37 | #define DumpLiteral(s,D) DumpBlock(s, sizeof(s) - sizeof(char), D) 38 | 39 | 40 | static void DumpBlock (const void *b, size_t size, DumpState *D) { 41 | if (D->status == 0 && size > 0) { 42 | lua_unlock(D->L); 43 | D->status = (*D->writer)(D->L, b, size, D->data); 44 | lua_lock(D->L); 45 | } 46 | } 47 | 48 | 49 | #define DumpVar(x,D) DumpVector(&x,1,D) 50 | 51 | 52 | static void DumpByte (int y, DumpState *D) { 53 | lu_byte x = (lu_byte)y; 54 | DumpVar(x, D); 55 | } 56 | 57 | 58 | static void DumpInt (int x, DumpState *D) { 59 | DumpVar(x, D); 60 | } 61 | 62 | 63 | static void DumpNumber (lua_Number x, DumpState *D) { 64 | DumpVar(x, D); 65 | } 66 | 67 | 68 | static void DumpInteger (lua_Integer x, DumpState *D) { 69 | DumpVar(x, D); 70 | } 71 | 72 | 73 | static void DumpString (const TString *s, DumpState *D) { 74 | if (s == NULL) 75 | DumpByte(0, D); 76 | else { 77 | size_t size = tsslen(s) + 1; /* include trailing '\0' */ 78 | const char *str = getstr(s); 79 | if (size < 0xFF) 80 | DumpByte(cast_int(size), D); 81 | else { 82 | DumpByte(0xFF, D); 83 | DumpVar(size, D); 84 | } 85 | DumpVector(str, size - 1, D); /* no need to save '\0' */ 86 | } 87 | } 88 | 89 | 90 | static void DumpCode (const Proto *f, DumpState *D) { 91 | DumpInt(f->sizecode, D); 92 | DumpVector(f->code, f->sizecode, D); 93 | } 94 | 95 | 96 | static void DumpFunction(const Proto *f, TString *psource, DumpState *D); 97 | 98 | static void DumpConstants (const Proto *f, DumpState *D) { 99 | int i; 100 | int n = f->sizek; 101 | DumpInt(n, D); 102 | for (i = 0; i < n; i++) { 103 | const TValue *o = &f->k[i]; 104 | DumpByte(ttype(o), D); 105 | switch (ttype(o)) { 106 | case LUA_TNIL: 107 | break; 108 | case LUA_TBOOLEAN: 109 | DumpByte(bvalue(o), D); 110 | break; 111 | case LUA_TNUMFLT: 112 | DumpNumber(fltvalue(o), D); 113 | break; 114 | case LUA_TNUMINT: 115 | DumpInteger(ivalue(o), D); 116 | break; 117 | case LUA_TSHRSTR: 118 | case LUA_TLNGSTR: 119 | DumpString(tsvalue(o), D); 120 | break; 121 | default: 122 | lua_assert(0); 123 | } 124 | } 125 | } 126 | 127 | 128 | static void DumpProtos (const Proto *f, DumpState *D) { 129 | int i; 130 | int n = f->sizep; 131 | DumpInt(n, D); 132 | for (i = 0; i < n; i++) 133 | DumpFunction(f->p[i], f->source, D); 134 | } 135 | 136 | 137 | static void DumpUpvalues (const Proto *f, DumpState *D) { 138 | int i, n = f->sizeupvalues; 139 | DumpInt(n, D); 140 | for (i = 0; i < n; i++) { 141 | DumpByte(f->upvalues[i].instack, D); 142 | DumpByte(f->upvalues[i].idx, D); 143 | } 144 | } 145 | 146 | 147 | static void DumpDebug (const Proto *f, DumpState *D) { 148 | int i, n; 149 | n = (D->strip) ? 0 : f->sizelineinfo; 150 | DumpInt(n, D); 151 | DumpVector(f->lineinfo, n, D); 152 | n = (D->strip) ? 0 : f->sizelocvars; 153 | DumpInt(n, D); 154 | for (i = 0; i < n; i++) { 155 | DumpString(f->locvars[i].varname, D); 156 | DumpInt(f->locvars[i].startpc, D); 157 | DumpInt(f->locvars[i].endpc, D); 158 | } 159 | n = (D->strip) ? 0 : f->sizeupvalues; 160 | DumpInt(n, D); 161 | for (i = 0; i < n; i++) 162 | DumpString(f->upvalues[i].name, D); 163 | } 164 | 165 | 166 | static void DumpFunction (const Proto *f, TString *psource, DumpState *D) { 167 | if (D->strip || f->source == psource) 168 | DumpString(NULL, D); /* no debug info or same source as its parent */ 169 | else 170 | DumpString(f->source, D); 171 | DumpInt(f->linedefined, D); 172 | DumpInt(f->lastlinedefined, D); 173 | DumpByte(f->numparams, D); 174 | DumpByte(f->is_vararg, D); 175 | DumpByte(f->maxstacksize, D); 176 | DumpCode(f, D); 177 | DumpConstants(f, D); 178 | DumpUpvalues(f, D); 179 | DumpProtos(f, D); 180 | DumpDebug(f, D); 181 | } 182 | 183 | 184 | static void DumpHeader (DumpState *D) { 185 | DumpLiteral(LUA_SIGNATURE, D); 186 | DumpByte(LUAC_VERSION, D); 187 | DumpByte(LUAC_FORMAT, D); 188 | DumpLiteral(LUAC_DATA, D); 189 | DumpByte(sizeof(int), D); 190 | DumpByte(sizeof(size_t), D); 191 | DumpByte(sizeof(Instruction), D); 192 | DumpByte(sizeof(lua_Integer), D); 193 | DumpByte(sizeof(lua_Number), D); 194 | DumpInteger(LUAC_INT, D); 195 | DumpNumber(LUAC_NUM, D); 196 | } 197 | 198 | 199 | /* 200 | ** dump Lua function as precompiled chunk 201 | */ 202 | int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, 203 | int strip) { 204 | DumpState D; 205 | D.L = L; 206 | D.writer = w; 207 | D.data = data; 208 | D.strip = strip; 209 | D.status = 0; 210 | DumpHeader(&D); 211 | DumpByte(f->sizeupvalues, &D); 212 | DumpFunction(f, NULL, &D); 213 | return D.status; 214 | } 215 | 216 | -------------------------------------------------------------------------------- /Luade/lua/lfunc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.c,v 2.45 2014/11/02 19:19:04 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lfunc_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lfunc.h" 18 | #include "lgc.h" 19 | #include "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | 23 | 24 | 25 | CClosure *luaF_newCclosure (lua_State *L, int n) { 26 | GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n)); 27 | CClosure *c = gco2ccl(o); 28 | c->nupvalues = cast_byte(n); 29 | return c; 30 | } 31 | 32 | 33 | LClosure *luaF_newLclosure (lua_State *L, int n) { 34 | GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n)); 35 | LClosure *c = gco2lcl(o); 36 | c->p = NULL; 37 | c->nupvalues = cast_byte(n); 38 | while (n--) c->upvals[n] = NULL; 39 | return c; 40 | } 41 | 42 | /* 43 | ** fill a closure with new closed upvalues 44 | */ 45 | void luaF_initupvals (lua_State *L, LClosure *cl) { 46 | int i; 47 | for (i = 0; i < cl->nupvalues; i++) { 48 | UpVal *uv = luaM_new(L, UpVal); 49 | uv->refcount = 1; 50 | uv->v = &uv->u.value; /* make it closed */ 51 | setnilvalue(uv->v); 52 | cl->upvals[i] = uv; 53 | } 54 | } 55 | 56 | 57 | UpVal *luaF_findupval (lua_State *L, StkId level) { 58 | UpVal **pp = &L->openupval; 59 | UpVal *p; 60 | UpVal *uv; 61 | lua_assert(isintwups(L) || L->openupval == NULL); 62 | while (*pp != NULL && (p = *pp)->v >= level) { 63 | lua_assert(upisopen(p)); 64 | if (p->v == level) /* found a corresponding upvalue? */ 65 | return p; /* return it */ 66 | pp = &p->u.open.next; 67 | } 68 | /* not found: create a new upvalue */ 69 | uv = luaM_new(L, UpVal); 70 | uv->refcount = 0; 71 | uv->u.open.next = *pp; /* link it to list of open upvalues */ 72 | uv->u.open.touched = 1; 73 | *pp = uv; 74 | uv->v = level; /* current value lives in the stack */ 75 | if (!isintwups(L)) { /* thread not in list of threads with upvalues? */ 76 | L->twups = G(L)->twups; /* link it to the list */ 77 | G(L)->twups = L; 78 | } 79 | return uv; 80 | } 81 | 82 | 83 | void luaF_close (lua_State *L, StkId level) { 84 | UpVal *uv; 85 | while (L->openupval != NULL && (uv = L->openupval)->v >= level) { 86 | lua_assert(upisopen(uv)); 87 | L->openupval = uv->u.open.next; /* remove from 'open' list */ 88 | if (uv->refcount == 0) /* no references? */ 89 | luaM_free(L, uv); /* free upvalue */ 90 | else { 91 | setobj(L, &uv->u.value, uv->v); /* move value to upvalue slot */ 92 | uv->v = &uv->u.value; /* now current value lives here */ 93 | luaC_upvalbarrier(L, uv); 94 | } 95 | } 96 | } 97 | 98 | 99 | Proto *luaF_newproto (lua_State *L) { 100 | GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto)); 101 | Proto *f = gco2p(o); 102 | f->k = NULL; 103 | f->sizek = 0; 104 | f->p = NULL; 105 | f->sizep = 0; 106 | f->code = NULL; 107 | f->cache = NULL; 108 | f->sizecode = 0; 109 | f->lineinfo = NULL; 110 | f->sizelineinfo = 0; 111 | f->upvalues = NULL; 112 | f->sizeupvalues = 0; 113 | f->numparams = 0; 114 | f->is_vararg = 0; 115 | f->maxstacksize = 0; 116 | f->locvars = NULL; 117 | f->sizelocvars = 0; 118 | f->linedefined = 0; 119 | f->lastlinedefined = 0; 120 | f->source = NULL; 121 | return f; 122 | } 123 | 124 | 125 | void luaF_freeproto (lua_State *L, Proto *f) { 126 | luaM_freearray(L, f->code, f->sizecode); 127 | luaM_freearray(L, f->p, f->sizep); 128 | luaM_freearray(L, f->k, f->sizek); 129 | luaM_freearray(L, f->lineinfo, f->sizelineinfo); 130 | luaM_freearray(L, f->locvars, f->sizelocvars); 131 | luaM_freearray(L, f->upvalues, f->sizeupvalues); 132 | luaM_free(L, f); 133 | } 134 | 135 | 136 | /* 137 | ** Look for n-th local variable at line 'line' in function 'func'. 138 | ** Returns NULL if not found. 139 | */ 140 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { 141 | int i; 142 | for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { 143 | if (pc < f->locvars[i].endpc) { /* is variable active? */ 144 | local_number--; 145 | if (local_number == 0) 146 | return getstr(f->locvars[i].varname); 147 | } 148 | } 149 | return NULL; /* not found */ 150 | } 151 | 152 | -------------------------------------------------------------------------------- /Luade/lua/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 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 | -------------------------------------------------------------------------------- /Luade/lua/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 2.91 2015/12/21 13:02:14 roberto Exp $ 3 | ** Garbage Collector 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lgc_h 8 | #define lgc_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | /* 15 | ** Collectable objects may have one of three colors: white, which 16 | ** means the object is not marked; gray, which means the 17 | ** object is marked, but its references may be not marked; and 18 | ** black, which means that the object and all its references are marked. 19 | ** The main invariant of the garbage collector, while marking objects, 20 | ** is that a black object can never point to a white one. Moreover, 21 | ** any gray object must be in a "gray list" (gray, grayagain, weak, 22 | ** allweak, ephemeron) so that it can be visited again before finishing 23 | ** the collection cycle. These lists have no meaning when the invariant 24 | ** is not being enforced (e.g., sweep phase). 25 | */ 26 | 27 | 28 | 29 | /* how much to allocate before next GC step */ 30 | #if !defined(GCSTEPSIZE) 31 | /* ~100 small strings */ 32 | #define GCSTEPSIZE (cast_int(100 * sizeof(TString))) 33 | #endif 34 | 35 | 36 | /* 37 | ** Possible states of the Garbage Collector 38 | */ 39 | #define GCSpropagate 0 40 | #define GCSatomic 1 41 | #define GCSswpallgc 2 42 | #define GCSswpfinobj 3 43 | #define GCSswptobefnz 4 44 | #define GCSswpend 5 45 | #define GCScallfin 6 46 | #define GCSpause 7 47 | 48 | 49 | #define issweepphase(g) \ 50 | (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend) 51 | 52 | 53 | /* 54 | ** macro to tell when main invariant (white objects cannot point to black 55 | ** ones) must be kept. During a collection, the sweep 56 | ** phase may break the invariant, as objects turned white may point to 57 | ** still-black objects. The invariant is restored when sweep ends and 58 | ** all objects are white again. 59 | */ 60 | 61 | #define keepinvariant(g) ((g)->gcstate <= GCSatomic) 62 | 63 | 64 | /* 65 | ** some useful bit tricks 66 | */ 67 | #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) 68 | #define setbits(x,m) ((x) |= (m)) 69 | #define testbits(x,m) ((x) & (m)) 70 | #define bitmask(b) (1<<(b)) 71 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 72 | #define l_setbit(x,b) setbits(x, bitmask(b)) 73 | #define resetbit(x,b) resetbits(x, bitmask(b)) 74 | #define testbit(x,b) testbits(x, bitmask(b)) 75 | 76 | 77 | /* Layout for bit use in 'marked' field: */ 78 | #define WHITE0BIT 0 /* object is white (type 0) */ 79 | #define WHITE1BIT 1 /* object is white (type 1) */ 80 | #define BLACKBIT 2 /* object is black */ 81 | #define FINALIZEDBIT 3 /* object has been marked for finalization */ 82 | /* bit 7 is currently used by tests (luaL_checkmemory) */ 83 | 84 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 85 | 86 | 87 | #define iswhite(x) testbits((x)->marked, WHITEBITS) 88 | #define isblack(x) testbit((x)->marked, BLACKBIT) 89 | #define isgray(x) /* neither white nor black */ \ 90 | (!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT))) 91 | 92 | #define tofinalize(x) testbit((x)->marked, FINALIZEDBIT) 93 | 94 | #define otherwhite(g) ((g)->currentwhite ^ WHITEBITS) 95 | #define isdeadm(ow,m) (!(((m) ^ WHITEBITS) & (ow))) 96 | #define isdead(g,v) isdeadm(otherwhite(g), (v)->marked) 97 | 98 | #define changewhite(x) ((x)->marked ^= WHITEBITS) 99 | #define gray2black(x) l_setbit((x)->marked, BLACKBIT) 100 | 101 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) 102 | 103 | 104 | /* 105 | ** Does one step of collection when debt becomes positive. 'pre'/'pos' 106 | ** allows some adjustments to be done only when needed. macro 107 | ** 'condchangemem' is used only for heavy tests (forcing a full 108 | ** GC cycle on every opportunity) 109 | */ 110 | #define luaC_condGC(L,pre,pos) \ 111 | { if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \ 112 | condchangemem(L,pre,pos); } 113 | 114 | /* more often than not, 'pre'/'pos' are empty */ 115 | #define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0) 116 | 117 | 118 | #define luaC_barrier(L,p,v) ( \ 119 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 120 | luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0)) 121 | 122 | #define luaC_barrierback(L,p,v) ( \ 123 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 124 | luaC_barrierback_(L,p) : cast_void(0)) 125 | 126 | #define luaC_objbarrier(L,p,o) ( \ 127 | (isblack(p) && iswhite(o)) ? \ 128 | luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0)) 129 | 130 | #define luaC_upvalbarrier(L,uv) ( \ 131 | (iscollectable((uv)->v) && !upisopen(uv)) ? \ 132 | luaC_upvalbarrier_(L,uv) : cast_void(0)) 133 | 134 | LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); 135 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); 136 | LUAI_FUNC void luaC_step (lua_State *L); 137 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); 138 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 139 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 140 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); 141 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o); 142 | LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv); 143 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); 144 | LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv); 145 | 146 | 147 | #endif 148 | -------------------------------------------------------------------------------- /Luade/lua/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.39 2016/12/04 20:17:24 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 | -------------------------------------------------------------------------------- /Luade/lua/ljumptab.h: -------------------------------------------------------------------------------- 1 | #undef vmdispatch 2 | #undef vmcase 3 | #undef vmbreak 4 | 5 | #define vmdispatch(x) goto *disptab[x]; 6 | 7 | #define vmcase(l) L_##l: 8 | 9 | #define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i)); 10 | 11 | 12 | static void *disptab[] = { 13 | 14 | #if 0 15 | ** you can update the following list with this command: 16 | ** 17 | ** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h 18 | ** 19 | #endif 20 | 21 | &&L_OP_MOVE, 22 | &&L_OP_LOADI, 23 | &&L_OP_LOADF, 24 | &&L_OP_LOADK, 25 | &&L_OP_LOADKX, 26 | &&L_OP_LOADBOOL, 27 | &&L_OP_LOADNIL, 28 | &&L_OP_GETUPVAL, 29 | &&L_OP_SETUPVAL, 30 | &&L_OP_GETTABUP, 31 | &&L_OP_GETTABLE, 32 | &&L_OP_GETI, 33 | &&L_OP_GETFIELD, 34 | &&L_OP_SETTABUP, 35 | &&L_OP_SETTABLE, 36 | &&L_OP_SETI, 37 | &&L_OP_SETFIELD, 38 | &&L_OP_NEWTABLE, 39 | &&L_OP_SELF, 40 | &&L_OP_ADDI, 41 | &&L_OP_SUBI, 42 | &&L_OP_MULI, 43 | &&L_OP_MODI, 44 | &&L_OP_POWI, 45 | &&L_OP_DIVI, 46 | &&L_OP_IDIVI, 47 | &&L_OP_BANDK, 48 | &&L_OP_BORK, 49 | &&L_OP_BXORK, 50 | &&L_OP_SHRI, 51 | &&L_OP_SHLI, 52 | &&L_OP_ADD, 53 | &&L_OP_SUB, 54 | &&L_OP_MUL, 55 | &&L_OP_MOD, 56 | &&L_OP_POW, 57 | &&L_OP_DIV, 58 | &&L_OP_IDIV, 59 | &&L_OP_BAND, 60 | &&L_OP_BOR, 61 | &&L_OP_BXOR, 62 | &&L_OP_SHL, 63 | &&L_OP_SHR, 64 | &&L_OP_UNM, 65 | &&L_OP_BNOT, 66 | &&L_OP_NOT, 67 | &&L_OP_LEN, 68 | &&L_OP_CONCAT, 69 | &&L_OP_CLOSE, 70 | &&L_OP_JMP, 71 | &&L_OP_EQ, 72 | &&L_OP_LT, 73 | &&L_OP_LE, 74 | &&L_OP_EQK, 75 | &&L_OP_EQI, 76 | &&L_OP_LTI, 77 | &&L_OP_LEI, 78 | &&L_OP_GTI, 79 | &&L_OP_GEI, 80 | &&L_OP_TEST, 81 | &&L_OP_TESTSET, 82 | &&L_OP_CALL, 83 | &&L_OP_TAILCALL, 84 | &&L_OP_RETURN, 85 | &&L_OP_RETURN0, 86 | &&L_OP_RETURN1, 87 | &&L_OP_FORLOOP1, 88 | &&L_OP_FORPREP1, 89 | &&L_OP_FORLOOP, 90 | &&L_OP_FORPREP, 91 | &&L_OP_TFORCALL, 92 | &&L_OP_TFORLOOP, 93 | &&L_OP_SETLIST, 94 | &&L_OP_CLOSURE, 95 | &&L_OP_VARARG, 96 | &&L_OP_PREPVARARG, 97 | &&L_OP_EXTRAARG 98 | 99 | }; 100 | -------------------------------------------------------------------------------- /Luade/lua/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.79 2016/05/02 14:02:12 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 | -------------------------------------------------------------------------------- /Luade/lua/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.91 2015/03/06 19:45:54 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 | -------------------------------------------------------------------------------- /Luade/lua/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 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 | -------------------------------------------------------------------------------- /Luade/lua/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $ 3 | ** Opcodes for Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lopcodes.h" 16 | 17 | 18 | /* ORDER OP */ 19 | 20 | LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { 21 | "MOVE", 22 | "LOADK", 23 | "LOADKX", 24 | "LOADBOOL", 25 | "LOADNIL", 26 | "GETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "SETTABUP", 30 | "SETUPVAL", 31 | "SETTABLE", 32 | "NEWTABLE", 33 | "SELF", 34 | "ADD", 35 | "SUB", 36 | "MUL", 37 | "MOD", 38 | "POW", 39 | "DIV", 40 | "IDIV", 41 | "BAND", 42 | "BOR", 43 | "BXOR", 44 | "SHL", 45 | "SHR", 46 | "UNM", 47 | "BNOT", 48 | "NOT", 49 | "LEN", 50 | "CONCAT", 51 | "JMP", 52 | "EQ", 53 | "LT", 54 | "LE", 55 | "TEST", 56 | "TESTSET", 57 | "CALL", 58 | "TAILCALL", 59 | "RETURN", 60 | "FORLOOP", 61 | "FORPREP", 62 | "TFORCALL", 63 | "TFORLOOP", 64 | "SETLIST", 65 | "CLOSURE", 66 | "VARARG", 67 | "EXTRAARG", 68 | NULL 69 | }; 70 | 71 | 72 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) 73 | 74 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { 75 | /* T A B C mode opcode */ 76 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 77 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 78 | ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ 79 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 80 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */ 81 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 82 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ 83 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 84 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */ 85 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ 86 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ 87 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ 88 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ 89 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ 90 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ 91 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ 92 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ 93 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ 94 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ 95 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_IDIV */ 96 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BAND */ 97 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BOR */ 98 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BXOR */ 99 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SHL */ 100 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SHR */ 101 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ 102 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_BNOT */ 103 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ 104 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ 105 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ 106 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ 107 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ 108 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ 109 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ 110 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TEST */ 111 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ 112 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ 113 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ 114 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ 115 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ 116 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ 117 | ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */ 118 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */ 119 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ 120 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 121 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 122 | ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */ 123 | }; 124 | 125 | -------------------------------------------------------------------------------- /Luade/lua/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.76 2015/12/30 18:16:13 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 and variable descriptor. 17 | ** Code generation for variables and expressions can be delayed to allow 18 | ** optimizations; An 'expdesc' structure describes a potentially-delayed 19 | ** variable/expression. It has a description of its "main" value plus a 20 | ** list of conditional jumps that can also produce its value (generated 21 | ** by short-circuit operators 'and'/'or'). 22 | */ 23 | 24 | /* kinds of variables/expressions */ 25 | typedef enum { 26 | VVOID, /* when 'expdesc' describes the last expression a list, 27 | this kind means an empty list (so, no expression) */ 28 | VNIL, /* constant nil */ 29 | VTRUE, /* constant true */ 30 | VFALSE, /* constant false */ 31 | VK, /* constant in 'k'; info = index of constant in 'k' */ 32 | VKFLT, /* floating constant; nval = numerical float value */ 33 | VKINT, /* integer constant; nval = numerical integer value */ 34 | VNONRELOC, /* expression has its value in a fixed register; 35 | info = result register */ 36 | VLOCAL, /* local variable; info = local register */ 37 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ 38 | VINDEXED, /* indexed variable; 39 | ind.vt = whether 't' is register or upvalue; 40 | ind.t = table register or upvalue; 41 | ind.idx = key's R/K index */ 42 | VJMP, /* expression is a test/comparison; 43 | info = pc of corresponding jump instruction */ 44 | VRELOCABLE, /* expression can put result in any register; 45 | info = instruction pc */ 46 | VCALL, /* expression is a function call; info = instruction pc */ 47 | VVARARG /* vararg expression; info = instruction pc */ 48 | } expkind; 49 | 50 | 51 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED) 52 | #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) 53 | 54 | typedef struct expdesc { 55 | expkind k; 56 | union { 57 | lua_Integer ival; /* for VKINT */ 58 | lua_Number nval; /* for VKFLT */ 59 | int info; /* for generic use */ 60 | struct { /* for indexed variables (VINDEXED) */ 61 | short idx; /* index (R/K) */ 62 | lu_byte t; /* table (register or upvalue) */ 63 | lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */ 64 | } ind; 65 | } u; 66 | int t; /* patch list of 'exit when true' */ 67 | int f; /* patch list of 'exit when false' */ 68 | } expdesc; 69 | 70 | 71 | /* description of active local variable */ 72 | typedef struct Vardesc { 73 | short idx; /* variable index in stack */ 74 | } Vardesc; 75 | 76 | 77 | /* description of pending goto statements and label statements */ 78 | typedef struct Labeldesc { 79 | TString *name; /* label identifier */ 80 | int pc; /* position in code */ 81 | int line; /* line where it appeared */ 82 | lu_byte nactvar; /* local level where it appears in current block */ 83 | } Labeldesc; 84 | 85 | 86 | /* list of labels or gotos */ 87 | typedef struct Labellist { 88 | Labeldesc *arr; /* array */ 89 | int n; /* number of entries in use */ 90 | int size; /* array size */ 91 | } Labellist; 92 | 93 | 94 | /* dynamic structures used by the parser */ 95 | typedef struct Dyndata { 96 | struct { /* list of active local variables */ 97 | Vardesc *arr; 98 | int n; 99 | int size; 100 | } actvar; 101 | Labellist gt; /* list of pending gotos */ 102 | Labellist label; /* list of active labels */ 103 | } Dyndata; 104 | 105 | 106 | /* control of blocks */ 107 | struct BlockCnt; /* defined in lparser.c */ 108 | 109 | 110 | /* state needed to generate code for a given function */ 111 | typedef struct FuncState { 112 | Proto *f; /* current function header */ 113 | struct FuncState *prev; /* enclosing function */ 114 | struct LexState *ls; /* lexical state */ 115 | struct BlockCnt *bl; /* chain of current blocks */ 116 | int pc; /* next position to code (equivalent to 'ncode') */ 117 | int lasttarget; /* 'label' of last 'jump label' */ 118 | int jpc; /* list of pending jumps to 'pc' */ 119 | int nk; /* number of elements in 'k' */ 120 | int np; /* number of elements in 'p' */ 121 | int firstlocal; /* index of first local var (in Dyndata array) */ 122 | short nlocvars; /* number of elements in 'f->locvars' */ 123 | lu_byte nactvar; /* number of active local variables */ 124 | lu_byte nups; /* number of upvalues */ 125 | lu_byte freereg; /* first free register */ 126 | } FuncState; 127 | 128 | 129 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 130 | Dyndata *dyd, const char *name, int firstchar); 131 | 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /Luade/lua/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 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 | -------------------------------------------------------------------------------- /Luade/lua/lstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 roberto Exp $ 3 | ** String table (keeps all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lstring_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 "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | #include "lstring.h" 23 | 24 | 25 | #define MEMERRMSG "not enough memory" 26 | 27 | 28 | /* 29 | ** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to 30 | ** compute its hash 31 | */ 32 | #if !defined(LUAI_HASHLIMIT) 33 | #define LUAI_HASHLIMIT 5 34 | #endif 35 | 36 | 37 | /* 38 | ** equality for long strings 39 | */ 40 | int luaS_eqlngstr (TString *a, TString *b) { 41 | size_t len = a->u.lnglen; 42 | lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR); 43 | return (a == b) || /* same instance or... */ 44 | ((len == b->u.lnglen) && /* equal length and ... */ 45 | (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */ 46 | } 47 | 48 | 49 | unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) { 50 | unsigned int h = seed ^ cast(unsigned int, l); 51 | size_t step = (l >> LUAI_HASHLIMIT) + 1; 52 | for (; l >= step; l -= step) 53 | h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1])); 54 | return h; 55 | } 56 | 57 | 58 | unsigned int luaS_hashlongstr (TString *ts) { 59 | lua_assert(ts->tt == LUA_TLNGSTR); 60 | if (ts->extra == 0) { /* no hash? */ 61 | ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash); 62 | ts->extra = 1; /* now it has its hash */ 63 | } 64 | return ts->hash; 65 | } 66 | 67 | 68 | /* 69 | ** resizes the string table 70 | */ 71 | void luaS_resize (lua_State *L, int newsize) { 72 | int i; 73 | stringtable *tb = &G(L)->strt; 74 | if (newsize > tb->size) { /* grow table if needed */ 75 | luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *); 76 | for (i = tb->size; i < newsize; i++) 77 | tb->hash[i] = NULL; 78 | } 79 | for (i = 0; i < tb->size; i++) { /* rehash */ 80 | TString *p = tb->hash[i]; 81 | tb->hash[i] = NULL; 82 | while (p) { /* for each node in the list */ 83 | TString *hnext = p->u.hnext; /* save next */ 84 | unsigned int h = lmod(p->hash, newsize); /* new position */ 85 | p->u.hnext = tb->hash[h]; /* chain it */ 86 | tb->hash[h] = p; 87 | p = hnext; 88 | } 89 | } 90 | if (newsize < tb->size) { /* shrink table if needed */ 91 | /* vanishing slice should be empty */ 92 | lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL); 93 | luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *); 94 | } 95 | tb->size = newsize; 96 | } 97 | 98 | 99 | /* 100 | ** Clear API string cache. (Entries cannot be empty, so fill them with 101 | ** a non-collectable string.) 102 | */ 103 | void luaS_clearcache (global_State *g) { 104 | int i, j; 105 | for (i = 0; i < STRCACHE_N; i++) 106 | for (j = 0; j < STRCACHE_M; j++) { 107 | if (iswhite(g->strcache[i][j])) /* will entry be collected? */ 108 | g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */ 109 | } 110 | } 111 | 112 | 113 | /* 114 | ** Initialize the string table and the string cache 115 | */ 116 | void luaS_init (lua_State *L) { 117 | global_State *g = G(L); 118 | int i, j; 119 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ 120 | /* pre-create memory-error message */ 121 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); 122 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ 123 | for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */ 124 | for (j = 0; j < STRCACHE_M; j++) 125 | g->strcache[i][j] = g->memerrmsg; 126 | } 127 | 128 | 129 | 130 | /* 131 | ** creates a new string object 132 | */ 133 | static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) { 134 | TString *ts; 135 | GCObject *o; 136 | size_t totalsize; /* total size of TString object */ 137 | totalsize = sizelstring(l); 138 | o = luaC_newobj(L, tag, totalsize); 139 | ts = gco2ts(o); 140 | ts->hash = h; 141 | ts->extra = 0; 142 | getstr(ts)[l] = '\0'; /* ending 0 */ 143 | return ts; 144 | } 145 | 146 | 147 | TString *luaS_createlngstrobj (lua_State *L, size_t l) { 148 | TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed); 149 | ts->u.lnglen = l; 150 | return ts; 151 | } 152 | 153 | 154 | void luaS_remove (lua_State *L, TString *ts) { 155 | stringtable *tb = &G(L)->strt; 156 | TString **p = &tb->hash[lmod(ts->hash, tb->size)]; 157 | while (*p != ts) /* find previous element */ 158 | p = &(*p)->u.hnext; 159 | *p = (*p)->u.hnext; /* remove element from its list */ 160 | tb->nuse--; 161 | } 162 | 163 | 164 | /* 165 | ** checks whether short string exists and reuses it or creates a new one 166 | */ 167 | static TString *internshrstr (lua_State *L, const char *str, size_t l) { 168 | TString *ts; 169 | global_State *g = G(L); 170 | unsigned int h = luaS_hash(str, l, g->seed); 171 | TString **list = &g->strt.hash[lmod(h, g->strt.size)]; 172 | lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */ 173 | for (ts = *list; ts != NULL; ts = ts->u.hnext) { 174 | if (l == ts->shrlen && 175 | (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { 176 | /* found! */ 177 | if (isdead(g, ts)) /* dead (but not collected yet)? */ 178 | changewhite(ts); /* resurrect it */ 179 | return ts; 180 | } 181 | } 182 | if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) { 183 | luaS_resize(L, g->strt.size * 2); 184 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ 185 | } 186 | ts = createstrobj(L, l, LUA_TSHRSTR, h); 187 | memcpy(getstr(ts), str, l * sizeof(char)); 188 | ts->shrlen = cast_byte(l); 189 | ts->u.hnext = *list; 190 | *list = ts; 191 | g->strt.nuse++; 192 | return ts; 193 | } 194 | 195 | 196 | /* 197 | ** new string (with explicit length) 198 | */ 199 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 200 | if (l <= LUAI_MAXSHORTLEN) /* short string? */ 201 | return internshrstr(L, str, l); 202 | else { 203 | TString *ts; 204 | if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char)) 205 | luaM_toobig(L); 206 | ts = luaS_createlngstrobj(L, l); 207 | memcpy(getstr(ts), str, l * sizeof(char)); 208 | return ts; 209 | } 210 | } 211 | 212 | 213 | /* 214 | ** Create or reuse a zero-terminated string, first checking in the 215 | ** cache (using the string address as a key). The cache can contain 216 | ** only zero-terminated strings, so it is safe to use 'strcmp' to 217 | ** check hits. 218 | */ 219 | TString *luaS_new (lua_State *L, const char *str) { 220 | unsigned int i = point2uint(str) % STRCACHE_N; /* hash */ 221 | int j; 222 | TString **p = G(L)->strcache[i]; 223 | for (j = 0; j < STRCACHE_M; j++) { 224 | if (strcmp(str, getstr(p[j])) == 0) /* hit? */ 225 | return p[j]; /* that is it */ 226 | } 227 | /* normal route */ 228 | for (j = STRCACHE_M - 1; j > 0; j--) 229 | p[j] = p[j - 1]; /* move out last element */ 230 | /* new element is first in the list */ 231 | p[0] = luaS_newlstr(L, str, strlen(str)); 232 | return p[0]; 233 | } 234 | 235 | 236 | Udata *luaS_newudata (lua_State *L, size_t s) { 237 | Udata *u; 238 | GCObject *o; 239 | if (s > MAX_SIZE - sizeof(Udata)) 240 | luaM_toobig(L); 241 | o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s)); 242 | u = gco2u(o); 243 | u->len = s; 244 | u->metatable = NULL; 245 | setuservalue(L, u, luaO_nilobject); 246 | return u; 247 | } 248 | 249 | -------------------------------------------------------------------------------- /Luade/lua/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 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 | -------------------------------------------------------------------------------- /Luade/lua/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.23 2016/12/22 13:08:50 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 int 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 | -------------------------------------------------------------------------------- /Luade/lua/ltests.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltests.h,v 2.58 2018/04/19 15:42:41 roberto Exp roberto $ 3 | ** Internal Header for Debugging of the Lua Implementation 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltests_h 8 | #define ltests_h 9 | 10 | 11 | #include 12 | #include 13 | 14 | /* test Lua with compatibility code */ 15 | #define LUA_COMPAT_MATHLIB 16 | 17 | 18 | #define LUA_DEBUG 19 | 20 | 21 | /* turn on assertions */ 22 | #undef NDEBUG 23 | #include 24 | #define lua_assert(c) assert(c) 25 | 26 | 27 | /* include opcode names */ 28 | #define LUAI_DEFOPNAMES 29 | 30 | 31 | /* compiled with -O0, Lua uses a lot of C stack space... */ 32 | #undef LUAI_MAXCCALLS 33 | #define LUAI_MAXCCALLS 200 34 | 35 | /* to avoid warnings, and to make sure value is really unused */ 36 | #define UNUSED(x) (x=0, (void)(x)) 37 | 38 | 39 | /* test for sizes in 'l_sprintf' (make sure whole buffer is available) */ 40 | #undef l_sprintf 41 | #if !defined(LUA_USE_C89) 42 | #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), snprintf(s,sz,f,i)) 43 | #else 44 | #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), sprintf(s,f,i)) 45 | #endif 46 | 47 | 48 | /* get a chance to test code without jump tables */ 49 | #define LUA_USE_JUMPTABLE 0 50 | 51 | 52 | /* use 32-bit integers in random generator */ 53 | #define LUA_RAND32 54 | 55 | 56 | /* memory-allocator control variables */ 57 | typedef struct Memcontrol { 58 | unsigned long numblocks; 59 | unsigned long total; 60 | unsigned long maxmem; 61 | unsigned long memlimit; 62 | unsigned long countlimit; 63 | unsigned long objcount[LUA_NUMTAGS]; 64 | } Memcontrol; 65 | 66 | LUA_API Memcontrol l_memcontrol; 67 | 68 | 69 | /* 70 | ** generic variable for debug tricks 71 | */ 72 | extern void *l_Trick; 73 | 74 | 75 | 76 | /* 77 | ** Function to traverse and check all memory used by Lua 78 | */ 79 | int lua_checkmemory (lua_State *L); 80 | 81 | 82 | /* test for lock/unlock */ 83 | 84 | struct L_EXTRA { int lock; int *plock; }; 85 | #undef LUA_EXTRASPACE 86 | #define LUA_EXTRASPACE sizeof(struct L_EXTRA) 87 | #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l)) 88 | #define luai_userstateopen(l) \ 89 | (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock)) 90 | #define luai_userstateclose(l) \ 91 | lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock)) 92 | #define luai_userstatethread(l,l1) \ 93 | lua_assert(getlock(l1)->plock == getlock(l)->plock) 94 | #define luai_userstatefree(l,l1) \ 95 | lua_assert(getlock(l)->plock == getlock(l1)->plock) 96 | #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0) 97 | #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0) 98 | 99 | 100 | 101 | LUA_API int luaB_opentests (lua_State *L); 102 | 103 | LUA_API void *debug_realloc (void *ud, void *block, 104 | size_t osize, size_t nsize); 105 | 106 | #if defined(lua_c) 107 | #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol) 108 | #define luaL_openlibs(L) \ 109 | { (luaL_openlibs)(L); \ 110 | luaL_requiref(L, "T", luaB_opentests, 1); \ 111 | lua_pop(L, 1); } 112 | #endif 113 | 114 | 115 | 116 | /* change some sizes to give some bugs a chance */ 117 | 118 | #undef LUAL_BUFFERSIZE 119 | #define LUAL_BUFFERSIZE 23 120 | #define MINSTRTABSIZE 2 121 | #define MAXINDEXRK 1 122 | #define MAXIWTHABS 3 123 | 124 | 125 | /* make stack-overflow tests run faster */ 126 | #undef LUAI_MAXSTACK 127 | #define LUAI_MAXSTACK 50000 128 | 129 | 130 | #undef LUAI_USER_ALIGNMENT_T 131 | #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; } 132 | 133 | 134 | #define STRCACHE_N 23 135 | #define STRCACHE_M 5 136 | 137 | #endif 138 | 139 | -------------------------------------------------------------------------------- /Luade/lua/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.38 2016/12/22 13:08:50 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ltm_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 "lobject.h" 20 | #include "lstate.h" 21 | #include "lstring.h" 22 | #include "ltable.h" 23 | #include "ltm.h" 24 | #include "lvm.h" 25 | 26 | 27 | static const char udatatypename[] = "userdata"; 28 | 29 | LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = { 30 | "no value", 31 | "nil", "boolean", udatatypename, "number", 32 | "string", "table", "function", udatatypename, "thread", 33 | "proto" /* this last case is used for tests only */ 34 | }; 35 | 36 | 37 | void luaT_init (lua_State *L) { 38 | static const char *const luaT_eventname[] = { /* ORDER TM */ 39 | "__index", "__newindex", 40 | "__gc", "__mode", "__len", "__eq", 41 | "__add", "__sub", "__mul", "__mod", "__pow", 42 | "__div", "__idiv", 43 | "__band", "__bor", "__bxor", "__shl", "__shr", 44 | "__unm", "__bnot", "__lt", "__le", 45 | "__concat", "__call" 46 | }; 47 | int i; 48 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 50 | luaC_fix(L, obj2gco(G(L)->tmname[i])); /* never collect these names */ 51 | } 52 | } 53 | 54 | 55 | /* 56 | ** function to be used with macro "fasttm": optimized for absence of 57 | ** tag methods 58 | */ 59 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 60 | const TValue *tm = luaH_getshortstr(events, ename); 61 | lua_assert(event <= TM_EQ); 62 | if (ttisnil(tm)) { /* no tag method? */ 63 | events->flags |= cast_byte(1u<metatable; 75 | break; 76 | case LUA_TUSERDATA: 77 | mt = uvalue(o)->metatable; 78 | break; 79 | default: 80 | mt = G(L)->mt[ttnov(o)]; 81 | } 82 | return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject); 83 | } 84 | 85 | 86 | /* 87 | ** Return the name of the type of an object. For tables and userdata 88 | ** with metatable, use their '__name' metafield, if present. 89 | */ 90 | const char *luaT_objtypename (lua_State *L, const TValue *o) { 91 | Table *mt; 92 | if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) || 93 | (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) { 94 | const TValue *name = luaH_getshortstr(mt, luaS_new(L, "__name")); 95 | if (ttisstring(name)) /* is '__name' a string? */ 96 | return getstr(tsvalue(name)); /* use it as type name */ 97 | } 98 | return ttypename(ttnov(o)); /* else use standard type name */ 99 | } 100 | 101 | 102 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 103 | const TValue *p2, TValue *p3, int hasres) { 104 | ptrdiff_t result = savestack(L, p3); 105 | StkId func = L->top; 106 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ 107 | setobj2s(L, func + 1, p1); /* 1st argument */ 108 | setobj2s(L, func + 2, p2); /* 2nd argument */ 109 | L->top += 3; 110 | if (!hasres) /* no result? 'p3' is third argument */ 111 | setobj2s(L, L->top++, p3); /* 3rd argument */ 112 | /* metamethod may yield only when called from Lua code */ 113 | if (isLua(L->ci)) 114 | luaD_call(L, func, hasres); 115 | else 116 | luaD_callnoyield(L, func, hasres); 117 | if (hasres) { /* if has result, move it to its place */ 118 | p3 = restorestack(L, result); 119 | setobjs2s(L, p3, --L->top); 120 | } 121 | } 122 | 123 | 124 | int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 125 | StkId res, TMS event) { 126 | const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ 127 | if (ttisnil(tm)) 128 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ 129 | if (ttisnil(tm)) return 0; 130 | luaT_callTM(L, tm, p1, p2, res, 1); 131 | return 1; 132 | } 133 | 134 | 135 | void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 136 | StkId res, TMS event) { 137 | if (!luaT_callbinTM(L, p1, p2, res, event)) { 138 | switch (event) { 139 | case TM_CONCAT: 140 | luaG_concaterror(L, p1, p2); 141 | /* call never returns, but to avoid warnings: *//* FALLTHROUGH */ 142 | case TM_BAND: case TM_BOR: case TM_BXOR: 143 | case TM_SHL: case TM_SHR: case TM_BNOT: { 144 | lua_Number dummy; 145 | if (tonumber(p1, &dummy) && tonumber(p2, &dummy)) 146 | luaG_tointerror(L, p1, p2); 147 | else 148 | luaG_opinterror(L, p1, p2, "perform bitwise operation on"); 149 | } 150 | /* calls never return, but to avoid warnings: *//* FALLTHROUGH */ 151 | default: 152 | luaG_opinterror(L, p1, p2, "perform arithmetic on"); 153 | } 154 | } 155 | } 156 | 157 | 158 | int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, 159 | TMS event) { 160 | if (!luaT_callbinTM(L, p1, p2, L->top, event)) 161 | return -1; /* no metamethod */ 162 | else 163 | return !l_isfalse(L->top); 164 | } 165 | 166 | -------------------------------------------------------------------------------- /Luade/lua/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 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 | -------------------------------------------------------------------------------- /Luade/lua/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 | -------------------------------------------------------------------------------- /Luade/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.45 2017/01/12 17:14:26 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 | -------------------------------------------------------------------------------- /Luade/lua/lundump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.c,v 2.44 2015/11/02 16:09:30 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lundump_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 "lfunc.h" 20 | #include "lmem.h" 21 | #include "lobject.h" 22 | #include "lstring.h" 23 | #include "lundump.h" 24 | #include "lzio.h" 25 | 26 | 27 | #if !defined(luai_verifycode) 28 | #define luai_verifycode(L,b,f) /* empty */ 29 | #endif 30 | 31 | 32 | typedef struct { 33 | lua_State *L; 34 | ZIO *Z; 35 | const char *name; 36 | } LoadState; 37 | 38 | 39 | static l_noret error(LoadState *S, const char *why) { 40 | luaO_pushfstring(S->L, "%s: %s precompiled chunk", S->name, why); 41 | luaD_throw(S->L, LUA_ERRSYNTAX); 42 | } 43 | 44 | 45 | /* 46 | ** All high-level loads go through LoadVector; you can change it to 47 | ** adapt to the endianness of the input 48 | */ 49 | #define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0])) 50 | 51 | static void LoadBlock (LoadState *S, void *b, size_t size) { 52 | if (luaZ_read(S->Z, b, size) != 0) 53 | error(S, "truncated"); 54 | } 55 | 56 | 57 | #define LoadVar(S,x) LoadVector(S,&x,1) 58 | 59 | 60 | static lu_byte LoadByte (LoadState *S) { 61 | lu_byte x; 62 | LoadVar(S, x); 63 | return x; 64 | } 65 | 66 | 67 | static int LoadInt (LoadState *S) { 68 | int x; 69 | LoadVar(S, x); 70 | return x; 71 | } 72 | 73 | 74 | static lua_Number LoadNumber (LoadState *S) { 75 | lua_Number x; 76 | LoadVar(S, x); 77 | return x; 78 | } 79 | 80 | 81 | static lua_Integer LoadInteger (LoadState *S) { 82 | lua_Integer x; 83 | LoadVar(S, x); 84 | return x; 85 | } 86 | 87 | 88 | static TString *LoadString (LoadState *S) { 89 | size_t size = LoadByte(S); 90 | if (size == 0xFF) 91 | LoadVar(S, size); 92 | if (size == 0) 93 | return NULL; 94 | else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */ 95 | char buff[LUAI_MAXSHORTLEN]; 96 | LoadVector(S, buff, size); 97 | return luaS_newlstr(S->L, buff, size); 98 | } 99 | else { /* long string */ 100 | TString *ts = luaS_createlngstrobj(S->L, size); 101 | LoadVector(S, getstr(ts), size); /* load directly in final place */ 102 | return ts; 103 | } 104 | } 105 | 106 | 107 | static void LoadCode (LoadState *S, Proto *f) { 108 | int n = LoadInt(S); 109 | f->code = luaM_newvector(S->L, n, Instruction); 110 | f->sizecode = n; 111 | LoadVector(S, f->code, n); 112 | } 113 | 114 | 115 | static void LoadFunction(LoadState *S, Proto *f, TString *psource); 116 | 117 | 118 | static void LoadConstants (LoadState *S, Proto *f) { 119 | int i; 120 | int n = LoadInt(S); 121 | f->k = luaM_newvector(S->L, n, TValue); 122 | f->sizek = n; 123 | for (i = 0; i < n; i++) 124 | setnilvalue(&f->k[i]); 125 | for (i = 0; i < n; i++) { 126 | TValue *o = &f->k[i]; 127 | int t = LoadByte(S); 128 | switch (t) { 129 | case LUA_TNIL: 130 | setnilvalue(o); 131 | break; 132 | case LUA_TBOOLEAN: 133 | setbvalue(o, LoadByte(S)); 134 | break; 135 | case LUA_TNUMFLT: 136 | setfltvalue(o, LoadNumber(S)); 137 | break; 138 | case LUA_TNUMINT: 139 | setivalue(o, LoadInteger(S)); 140 | break; 141 | case LUA_TSHRSTR: 142 | case LUA_TLNGSTR: 143 | setsvalue2n(S->L, o, LoadString(S)); 144 | break; 145 | default: 146 | lua_assert(0); 147 | } 148 | } 149 | } 150 | 151 | 152 | static void LoadProtos (LoadState *S, Proto *f) { 153 | int i; 154 | int n = LoadInt(S); 155 | f->p = luaM_newvector(S->L, n, Proto *); 156 | f->sizep = n; 157 | for (i = 0; i < n; i++) 158 | f->p[i] = NULL; 159 | for (i = 0; i < n; i++) { 160 | f->p[i] = luaF_newproto(S->L); 161 | LoadFunction(S, f->p[i], f->source); 162 | } 163 | } 164 | 165 | 166 | static void LoadUpvalues (LoadState *S, Proto *f) { 167 | int i, n; 168 | n = LoadInt(S); 169 | f->upvalues = luaM_newvector(S->L, n, Upvaldesc); 170 | f->sizeupvalues = n; 171 | for (i = 0; i < n; i++) 172 | f->upvalues[i].name = NULL; 173 | for (i = 0; i < n; i++) { 174 | f->upvalues[i].instack = LoadByte(S); 175 | f->upvalues[i].idx = LoadByte(S); 176 | } 177 | } 178 | 179 | 180 | static void LoadDebug (LoadState *S, Proto *f) { 181 | int i, n; 182 | n = LoadInt(S); 183 | f->lineinfo = luaM_newvector(S->L, n, int); 184 | f->sizelineinfo = n; 185 | LoadVector(S, f->lineinfo, n); 186 | n = LoadInt(S); 187 | f->locvars = luaM_newvector(S->L, n, LocVar); 188 | f->sizelocvars = n; 189 | for (i = 0; i < n; i++) 190 | f->locvars[i].varname = NULL; 191 | for (i = 0; i < n; i++) { 192 | f->locvars[i].varname = LoadString(S); 193 | f->locvars[i].startpc = LoadInt(S); 194 | f->locvars[i].endpc = LoadInt(S); 195 | } 196 | n = LoadInt(S); 197 | for (i = 0; i < n; i++) 198 | f->upvalues[i].name = LoadString(S); 199 | } 200 | 201 | 202 | static void LoadFunction (LoadState *S, Proto *f, TString *psource) { 203 | f->source = LoadString(S); 204 | if (f->source == NULL) /* no source in dump? */ 205 | f->source = psource; /* reuse parent's source */ 206 | f->linedefined = LoadInt(S); 207 | f->lastlinedefined = LoadInt(S); 208 | f->numparams = LoadByte(S); 209 | f->is_vararg = LoadByte(S); 210 | f->maxstacksize = LoadByte(S); 211 | LoadCode(S, f); 212 | LoadConstants(S, f); 213 | LoadUpvalues(S, f); 214 | LoadProtos(S, f); 215 | LoadDebug(S, f); 216 | } 217 | 218 | 219 | static void checkliteral (LoadState *S, const char *s, const char *msg) { 220 | char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */ 221 | size_t len = strlen(s); 222 | LoadVector(S, buff, len); 223 | if (memcmp(s, buff, len) != 0) 224 | error(S, msg); 225 | } 226 | 227 | 228 | static void fchecksize (LoadState *S, size_t size, const char *tname) { 229 | if (LoadByte(S) != size) 230 | error(S, luaO_pushfstring(S->L, "%s size mismatch in", tname)); 231 | } 232 | 233 | 234 | #define checksize(S,t) fchecksize(S,sizeof(t),#t) 235 | 236 | static void checkHeader (LoadState *S) { 237 | checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */ 238 | if (LoadByte(S) != LUAC_VERSION) 239 | error(S, "version mismatch in"); 240 | if (LoadByte(S) != LUAC_FORMAT) 241 | error(S, "format mismatch in"); 242 | checkliteral(S, LUAC_DATA, "corrupted"); 243 | checksize(S, int); 244 | checksize(S, size_t); 245 | checksize(S, Instruction); 246 | checksize(S, lua_Integer); 247 | checksize(S, lua_Number); 248 | if (LoadInteger(S) != LUAC_INT) 249 | error(S, "endianness mismatch in"); 250 | if (LoadNumber(S) != LUAC_NUM) 251 | error(S, "float format mismatch in"); 252 | } 253 | 254 | 255 | /* 256 | ** load precompiled chunk 257 | */ 258 | LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) { 259 | LoadState S; 260 | LClosure *cl; 261 | if (*name == '@' || *name == '=') 262 | S.name = name + 1; 263 | else if (*name == LUA_SIGNATURE[0]) 264 | S.name = "binary string"; 265 | else 266 | S.name = name; 267 | S.L = L; 268 | S.Z = Z; 269 | checkHeader(&S); 270 | cl = luaF_newLclosure(L, LoadByte(&S)); 271 | setclLvalue(L, L->top, cl); 272 | luaD_inctop(L); 273 | cl->p = luaF_newproto(L); 274 | LoadFunction(&S, cl->p, NULL); 275 | lua_assert(cl->nupvalues == cl->p->sizeupvalues); 276 | luai_verifycode(L, buff, cl->p); 277 | return cl; 278 | } 279 | 280 | -------------------------------------------------------------------------------- /Luade/lua/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 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 | -------------------------------------------------------------------------------- /Luade/lua/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.41 2016/12/22 13:08:50 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 | #if !defined(LUA_NOCVTN2S) 17 | #define cvt2str(o) ttisnumber(o) 18 | #else 19 | #define cvt2str(o) 0 /* no conversion from numbers to strings */ 20 | #endif 21 | 22 | 23 | #if !defined(LUA_NOCVTS2N) 24 | #define cvt2num(o) ttisstring(o) 25 | #else 26 | #define cvt2num(o) 0 /* no conversion from strings to numbers */ 27 | #endif 28 | 29 | 30 | /* 31 | ** You can define LUA_FLOORN2I if you want to convert floats to integers 32 | ** by flooring them (instead of raising an error if they are not 33 | ** integral values) 34 | */ 35 | #if !defined(LUA_FLOORN2I) 36 | #define LUA_FLOORN2I 0 37 | #endif 38 | 39 | 40 | #define tonumber(o,n) \ 41 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 42 | 43 | #define tointeger(o,i) \ 44 | (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I)) 45 | 46 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 47 | 48 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 49 | 50 | 51 | /* 52 | ** fast track for 'gettable': if 't' is a table and 't[k]' is not nil, 53 | ** return 1 with 'slot' pointing to 't[k]' (final result). Otherwise, 54 | ** return 0 (meaning it will have to check metamethod) with 'slot' 55 | ** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise). 56 | ** 'f' is the raw get function to use. 57 | */ 58 | #define luaV_fastget(L,t,k,slot,f) \ 59 | (!ttistable(t) \ 60 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 61 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ 62 | !ttisnil(slot))) /* result not nil? */ 63 | 64 | /* 65 | ** standard implementation for 'gettable' 66 | */ 67 | #define luaV_gettable(L,t,k,v) { const TValue *slot; \ 68 | if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \ 69 | else luaV_finishget(L,t,k,v,slot); } 70 | 71 | 72 | /* 73 | ** Fast track for set table. If 't' is a table and 't[k]' is not nil, 74 | ** call GC barrier, do a raw 't[k]=v', and return true; otherwise, 75 | ** return false with 'slot' equal to NULL (if 't' is not a table) or 76 | ** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro 77 | ** returns true, there is no need to 'invalidateTMcache', because the 78 | ** call is not creating a new entry. 79 | */ 80 | #define luaV_fastset(L,t,k,slot,f,v) \ 81 | (!ttistable(t) \ 82 | ? (slot = NULL, 0) \ 83 | : (slot = f(hvalue(t), k), \ 84 | ttisnil(slot) ? 0 \ 85 | : (luaC_barrierback(L, hvalue(t), v), \ 86 | setobj2t(L, cast(TValue *,slot), v), \ 87 | 1))) 88 | 89 | 90 | #define luaV_settable(L,t,k,v) { const TValue *slot; \ 91 | if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \ 92 | luaV_finishset(L,t,k,v,slot); } 93 | 94 | 95 | 96 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 97 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 98 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 99 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 100 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); 101 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, 102 | StkId val, const TValue *slot); 103 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 104 | StkId val, const TValue *slot); 105 | LUAI_FUNC void luaV_finishOp (lua_State *L); 106 | LUAI_FUNC void luaV_execute (lua_State *L); 107 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 108 | LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); 109 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 110 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 111 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /Luade/lua/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 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 | -------------------------------------------------------------------------------- /Luade/lua/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 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 | -------------------------------------------------------------------------------- /Luade/lua_copyright.c: -------------------------------------------------------------------------------- 1 | // 2 | // lua_copyright.c 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 11/27/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "lua_copyright.h" 10 | #include "lua/lua.h" 11 | 12 | const char* lua_copyright() { 13 | return LUA_COPYRIGHT; 14 | } 15 | -------------------------------------------------------------------------------- /Luade/lua_copyright.h: -------------------------------------------------------------------------------- 1 | // 2 | // lua_copyright.h 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 11/27/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #ifndef lua_copyright_h 10 | #define lua_copyright_h 11 | 12 | /// Returns the Lua copyright string. 13 | const char* lua_copyright(void); 14 | 15 | #endif /* lua_copyright_h */ 16 | -------------------------------------------------------------------------------- /Luade/openURL function/openURL.h: -------------------------------------------------------------------------------- 1 | // 2 | // openURL.h 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/9/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "../lua/lua.h" 10 | #include "../lua/lauxlib.h" 11 | 12 | void luaopen_openURL(lua_State *L); 13 | -------------------------------------------------------------------------------- /Luade/openURL function/openURL.m: -------------------------------------------------------------------------------- 1 | // 2 | // openURL.m 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/9/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "openURL.h" 10 | #import 11 | 12 | int openURL(lua_State *L) { 13 | if (lua_gettop(L) != 1 || !lua_isstring(L, 1)) { 14 | return luaL_error(L, "Expected a string as parameter."); 15 | } 16 | 17 | NSURL *url = [NSURL URLWithString:[NSString stringWithUTF8String:lua_tostring(L, 1)]]; 18 | 19 | if (!url) { 20 | return luaL_error(L, "Invalid URL."); 21 | } 22 | 23 | dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); 24 | 25 | dispatch_async(dispatch_get_main_queue(), ^{ 26 | [UIApplication.sharedApplication openURL:url options:[NSDictionary dictionary] completionHandler:^(BOOL success) { 27 | 28 | dispatch_semaphore_signal(semaphore); 29 | lua_pushboolean(L, success); 30 | }]; 31 | }); 32 | 33 | dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); 34 | 35 | return 1; 36 | } 37 | 38 | void luaopen_openURL(lua_State *L) { 39 | lua_register(L, "openURL", openURL); 40 | } 41 | -------------------------------------------------------------------------------- /Luade/pasteboard library/pasteboard.h: -------------------------------------------------------------------------------- 1 | // 2 | // device.h 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/5/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "../lua/lua.h" 10 | #include "../lua/lauxlib.h" 11 | 12 | /// Opens the 'device' module. 13 | int luaopen_pasteboard(lua_State *L); 14 | -------------------------------------------------------------------------------- /Luade/pasteboard library/pasteboard.m: -------------------------------------------------------------------------------- 1 | // 2 | // device.m 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/5/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "pasteboard.h" 10 | #import 11 | 12 | static int pasteboard_string(lua_State *L) { 13 | lua_pushstring(L, UIPasteboard.generalPasteboard.string.UTF8String); 14 | return 1; 15 | } 16 | 17 | static int pasteboard_setString(lua_State *L) { 18 | 19 | const char* expected = "Expected a string as argument."; 20 | 21 | if (lua_gettop(L) != 1) { 22 | return luaL_error(L, expected); 23 | } else if (!lua_isstring(L, 1)) { 24 | return luaL_error(L, expected); 25 | } 26 | 27 | [UIPasteboard.generalPasteboard setString: [NSString stringWithUTF8String:lua_tostring(L, 1)]]; 28 | 29 | return 0; 30 | } 31 | 32 | static int pasteboard_strings(lua_State *L) { 33 | 34 | int i; 35 | 36 | NSArray *strings = UIPasteboard.generalPasteboard.strings; 37 | const char* arr[strings.count]; 38 | 39 | for (i=0; i *strings = [NSMutableArray array]; 55 | 56 | int argc = lua_gettop(L); 57 | for (int i = 1; i <= argc; i++) { 58 | [strings addObject:[NSString stringWithUTF8String: lua_tostring(L, i)]]; 59 | } 60 | 61 | [UIPasteboard.generalPasteboard setStrings:strings]; 62 | 63 | return 0; 64 | } 65 | 66 | static const struct luaL_Reg pasteboard_functions[] = { 67 | 68 | { "string", pasteboard_string }, 69 | { "setString", pasteboard_setString }, 70 | { "strings", pasteboard_strings }, 71 | { "setStrings", pasteboard_setStrings }, 72 | { NULL, NULL } 73 | }; 74 | 75 | int luaopen_pasteboard(lua_State *L) { 76 | /* Create the metatable and put it on the stack. */ 77 | luaL_newmetatable(L, "pasteboard"); 78 | /* Duplicate the metatable on the stack (We know have 2). */ 79 | lua_pushvalue(L, -1); 80 | /* Pop the first metatable off the stack and assign it to __index 81 | * of the second one. We set the metatable for the table to itself. 82 | * This is equivalent to the following in lua: 83 | * metatable = {} 84 | * metatable.__index = metatable 85 | */ 86 | lua_setfield(L, -2, "__index"); 87 | 88 | /* Register the object.func functions into the table that is at the top of the 89 | * stack. */ 90 | luaL_newlib(L, pasteboard_functions); 91 | lua_setglobal(L, "pasteboard"); 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /Luade/sharesheet library/lua_extensionContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // lua_extensionContext.h 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/5/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #ifndef lua_extensionContext_H 12 | #define lua_extensionContext_H 13 | 14 | /// The extension context passed from a share extension to Lua. 15 | extern NSExtensionContext * _Nullable lua_extensionContext; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Luade/sharesheet library/lua_extensionContext.m: -------------------------------------------------------------------------------- 1 | // 2 | // lua_extensionContext.m 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/5/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "lua_extensionContext.h" 10 | 11 | NSExtensionContext * _Nullable lua_extensionContext; 12 | -------------------------------------------------------------------------------- /Luade/sharesheet library/lua_viewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // lua_viewController.h 3 | // 4 | // 5 | // Created by Adrian Labbe on 12/6/18. 6 | // 7 | 8 | #import 9 | 10 | #ifndef lua_viewController_h 11 | #define lua_viewController_h 12 | 13 | /// A View controller for presenting other ones from Lua. 14 | extern UIViewController * _Nullable lua_viewController; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /Luade/sharesheet library/lua_viewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // lua_viewController.m 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/6/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "lua_viewController.h" 10 | 11 | UIViewController * _Nullable lua_viewController; 12 | -------------------------------------------------------------------------------- /Luade/sharesheet library/sharesheet.h: -------------------------------------------------------------------------------- 1 | // 2 | // sharesheet.h 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/5/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "../lua/lua.h" 10 | #include "../lua/lauxlib.h" 11 | 12 | /// Opens the 'sharesheet' module. 13 | int luaopen_sharesheet(lua_State *L); 14 | -------------------------------------------------------------------------------- /Luade/sharesheet library/sharesheet.m: -------------------------------------------------------------------------------- 1 | // 2 | // sharesheet.m 3 | // Luade 4 | // 5 | // Created by Adrian Labbe on 12/5/18. 6 | // Copyright © 2018 Adrian Labbe. All rights reserved. 7 | // 8 | 9 | #include "sharesheet.h" 10 | #include "lua_extensionContext.h" 11 | #include "lua_viewController.h" 12 | #import 13 | 14 | static int sharesheet_string(lua_State *L) { 15 | 16 | dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); 17 | 18 | NSExtensionItem *item = lua_extensionContext.inputItems[0]; 19 | NSItemProvider *attachment = item.attachments[0]; 20 | 21 | [attachment loadItemForTypeIdentifier:@"public.plain-text" options:nil completionHandler:^(id _Nullable item, NSError * _Null_unspecified error) { 22 | 23 | NSString * _Nullable str = (NSString *)item; 24 | if ([str isKindOfClass: NSString.class]) { 25 | lua_pushstring(L, [str UTF8String]); 26 | } else { 27 | lua_pushnil(L); 28 | } 29 | 30 | dispatch_semaphore_signal(semaphore); 31 | }]; 32 | 33 | if (lua_extensionContext) { 34 | dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); 35 | } else { 36 | lua_pushnil(L); 37 | } 38 | 39 | return 1; 40 | } 41 | 42 | static int sharesheet_url(lua_State *L) { 43 | 44 | dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); 45 | 46 | NSExtensionItem *item = lua_extensionContext.inputItems[0]; 47 | NSItemProvider *attachment = item.attachments[0]; 48 | 49 | [attachment loadItemForTypeIdentifier:@"public.url" options:nil completionHandler:^(id _Nullable item, NSError * _Null_unspecified error) { 50 | 51 | NSURL * _Nullable url = (NSURL *)item; 52 | 53 | if ([url isKindOfClass: NSURL.class]) { 54 | lua_pushstring(L, [[url absoluteString] UTF8String]); 55 | } else { 56 | lua_pushnil(L); 57 | } 58 | 59 | dispatch_semaphore_signal(semaphore); 60 | }]; 61 | 62 | if (lua_extensionContext) { 63 | dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); 64 | } else { 65 | lua_pushnil(L); 66 | } 67 | 68 | return 1; 69 | } 70 | 71 | static int sharesheet_filePath(lua_State *L) { 72 | 73 | dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); 74 | 75 | NSExtensionItem *item = lua_extensionContext.inputItems[0]; 76 | NSItemProvider *attachment = item.attachments[0]; 77 | 78 | [attachment loadInPlaceFileRepresentationForTypeIdentifier:@"public.content" completionHandler:^(NSURL * _Nullable url, BOOL isInPlace, NSError * _Nullable error) { 79 | 80 | NSString *path = url.path; 81 | 82 | [url startAccessingSecurityScopedResource]; 83 | lua_pushstring(L, path.UTF8String); 84 | 85 | dispatch_semaphore_signal(semaphore); 86 | }]; 87 | 88 | if (lua_extensionContext) { 89 | dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); 90 | } else { 91 | lua_pushnil(L); 92 | } 93 | 94 | return 1; 95 | } 96 | 97 | static int sharesheet_shareItems(lua_State *L) { 98 | 99 | //#if MAINAPP 100 | NSMutableArray *items = [[NSMutableArray alloc] init]; 101 | 102 | int argc = lua_gettop(L); 103 | for (int i = 1; i <= argc; i++) { 104 | NSString *str = [NSString stringWithUTF8String: lua_tostring(L, i)]; 105 | 106 | NSURL *url; 107 | 108 | if ([[NSFileManager defaultManager] fileExistsAtPath:str isDirectory: nil]) { 109 | url = [NSURL fileURLWithPath: str]; 110 | } else { 111 | url = [NSURL URLWithString:str]; 112 | } 113 | 114 | if (url && url.scheme != nil && ![url.scheme isEqual: @""]) { 115 | [items addObject: url]; 116 | } else { 117 | [items addObject: str]; 118 | } 119 | } 120 | 121 | dispatch_async(dispatch_get_main_queue(), ^{ 122 | UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil]; 123 | 124 | if (lua_viewController) { 125 | vc.popoverPresentationController.sourceRect = lua_viewController.view.bounds; 126 | vc.popoverPresentationController.sourceView = lua_viewController.view; 127 | 128 | [lua_viewController presentViewController:vc animated:YES completion:nil]; 129 | } 130 | }); 131 | 132 | return 0; 133 | /*#else 134 | return luaL_error(L, "'shareItems' should be only called from the app."); 135 | #endif*/ 136 | } 137 | 138 | static const struct luaL_Reg sharesheet_functions[] = { 139 | 140 | { "string", sharesheet_string }, 141 | { "url", sharesheet_url }, 142 | { "filePath", sharesheet_filePath }, 143 | { "shareItems", sharesheet_shareItems }, 144 | { NULL, NULL } 145 | }; 146 | 147 | int luaopen_sharesheet(lua_State *L) { 148 | /* Create the metatable and put it on the stack. */ 149 | luaL_newmetatable(L, "sharesheet"); 150 | /* Duplicate the metatable on the stack (We know have 2). */ 151 | lua_pushvalue(L, -1); 152 | /* Pop the first metatable off the stack and assign it to __index 153 | * of the second one. We set the metatable for the table to itself. 154 | * This is equivalent to the following in lua: 155 | * metatable = {} 156 | * metatable.__index = metatable 157 | */ 158 | lua_setfield(L, -2, "__index"); 159 | 160 | /* Register the object.func functions into the table that is at the top of the 161 | * stack. */ 162 | luaL_newlib(L, sharesheet_functions); 163 | lua_setglobal(L, "sharesheet"); 164 | 165 | return 0; 166 | } 167 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | target 'Luade' do 5 | # Comment the next line if you're not using Swift and don't want to use dynamic frameworks 6 | use_frameworks! 7 | 8 | # Pods for Luade 9 | 10 | pod 'SourceEditor', :git => 'https://github.com/ronaldmannak/source-editor.git' 11 | pod 'FloatingPanel' 12 | pod 'InputAssistant' 13 | end 14 | 15 | target 'Run Lua Script' do 16 | # Comment the next line if you're not using Swift and don't want to use dynamic frameworks 17 | use_frameworks! 18 | 19 | # Pods for Run Lua Script 20 | 21 | pod 'SourceEditor', :git => 'https://github.com/ronaldmannak/source-editor.git' 22 | pod 'FloatingPanel' 23 | pod 'InputAssistant' 24 | end 25 | 26 | # post install 27 | post_install do |installer| 28 | # Build settings 29 | installer.pods_project.targets.each do |target| 30 | target.build_configurations.each do |config| 31 | config.build_settings = config.build_settings.dup 32 | if config.build_settings['PRODUCT_MODULE_NAME'] == 'SavannaKit' || config.build_settings['PRODUCT_MODULE_NAME'] == 'SourceEditor' 33 | puts "Set Swift version" 34 | config.build_settings['SWIFT_VERSION'] = '4.0' 35 | end 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - FloatingPanel (1.2.0) 3 | - InputAssistant (1.0.2) 4 | - SavannaKit (0.9.0) 5 | - SourceEditor (1.0.1): 6 | - SavannaKit (~> 0.9) 7 | 8 | DEPENDENCIES: 9 | - FloatingPanel 10 | - InputAssistant 11 | - SourceEditor (from `https://github.com/ronaldmannak/source-editor.git`) 12 | 13 | SPEC REPOS: 14 | https://github.com/cocoapods/specs.git: 15 | - FloatingPanel 16 | - InputAssistant 17 | - SavannaKit 18 | 19 | EXTERNAL SOURCES: 20 | SourceEditor: 21 | :git: https://github.com/ronaldmannak/source-editor.git 22 | 23 | CHECKOUT OPTIONS: 24 | SourceEditor: 25 | :commit: 49c0a432c156ab7867d52e209971db4df3806b02 26 | :git: https://github.com/ronaldmannak/source-editor.git 27 | 28 | SPEC CHECKSUMS: 29 | FloatingPanel: b6c56634780f25a4b5146025714f3ad5eeb5afb9 30 | InputAssistant: b0b70cd0d69ef7013ecb2a1fa350b7a2786e2e01 31 | SavannaKit: 920c240bde011900df8156200a960dad3ee5edfd 32 | SourceEditor: 4d590385d642c812d08a91941a4bfc90eccf20af 33 | 34 | PODFILE CHECKSUM: ecfbdea7ab0ccf9c5e9569c9dc0d6ad7de994775 35 | 36 | COCOAPODS: 1.5.3 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Pisth • 3 | Edidown • 4 | Pyto • 5 | Luade 6 |

7 | 8 | ![Mockup](mockup.png) 9 | 10 | ![Icon](https://raw.githubusercontent.com/ColdGrub1384/Luade/master/Luade/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5%402x.png) 11 | 12 | # Luade 13 | 14 | ``` 15 | Luade is a Lua IDE for iPhone and iPad. You can run code directly on your device and offline. 16 | 17 | Features: 18 | 19 | - Lua with all default libraries like "io" 20 | - Full REPL 21 | - Preinstalled modules to access device information and clipboard 22 | - Run scripts from the share sheet 23 | - Store scripts in iCloud Drive 24 | ``` 25 | 26 | ## Building 27 | 28 | `$ ./setup.sh` and then open Luade.xcworkspace. 29 | -------------------------------------------------------------------------------- /Run Lua Script/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Run Lua Script 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | XPC! 19 | CFBundleShortVersionString 20 | 3.0.2 21 | CFBundleVersion 22 | 2 23 | NSExtension 24 | 25 | NSExtensionAttributes 26 | 27 | NSExtensionActivationRule 28 | 29 | NSExtensionActivationSupportsFileWithMaxCount 30 | 1 31 | NSExtensionActivationSupportsText 32 | 33 | NSExtensionActivationSupportsWebURLWithMaxCount 34 | 1 35 | 36 | 37 | NSExtensionMainStoryboard 38 | MainInterface 39 | NSExtensionPointIdentifier 40 | com.apple.share-services 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Run Lua Script/Run Lua Script.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.developer.icloud-container-identifiers 6 | 7 | iCloud.$(CFBundleIdentifier) 8 | 9 | com.apple.developer.icloud-services 10 | 11 | CloudDocuments 12 | 13 | com.apple.developer.ubiquity-container-identifiers 14 | 15 | iCloud.$(CFBundleIdentifier) 16 | 17 | com.apple.security.application-groups 18 | 19 | group.luade.sharing 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/Device.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

device

8 | 9 |

This module wraps UIDevice and gives you access to the device information.

10 | 11 |

name

12 | 13 |

device.name()

14 | 15 |

Returns the device's name.

16 | 17 |

systemName

18 | 19 |

device.systemName()

20 | 21 |

Returns the device's system name.

22 | 23 |

systemVersion

24 | 25 |

device.systemVersion()

26 | 27 |

Returns the device's system version.

28 | 29 |

model

30 | 31 |

device.model()

32 | 33 |

Returns the device's model.

34 | 35 |

localizedModel

36 | 37 |

device.localizedModel()

38 | 39 |

Returns the device's localized model.

40 | 41 |

isPortrait

42 | 43 |

device.isPortrait()

44 | 45 |

Returns true if the device orientation is portrait.

46 | 47 |

isLandscape

48 | 49 |

device.isLandscape()

50 | 51 |

Returns true if the device orientation is landscape.

52 | 53 |

batteryLevel

54 | 55 |

device.batteryLevel()

56 | 57 |

Returns the battery level of the device.

58 | 59 |

isCharging

60 | 61 |

device.isCharging()

62 | 63 |

Returns true if the device is charging.

64 | 65 | -------------------------------------------------------------------------------- /docs/Licenses.md: -------------------------------------------------------------------------------- 1 | # Acknowledgments 2 | 3 | ## FloatingPanel 4 | 5 | ``` 6 | MIT License 7 | 8 | Copyright (c) 2018 Shin Yamamoto 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | ``` 28 | 29 | ## InputAssistant 30 | 31 | ``` 32 | MIT License 33 | 34 | Copyright (c) 2017 Ian McDowell 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 40 | copies of the Software, and to permit persons to whom the Software is 41 | furnished to do so, subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all 44 | copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 49 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 52 | SOFTWARE. 53 | ``` 54 | 55 | ## Lua 56 | 57 | ``` 58 | Copyright © 1994–2018 Lua.org, PUC-Rio. 59 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 60 | 61 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 62 | 63 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 64 | ``` 65 | 66 | ## SavannaKit 67 | 68 | ``` 69 | MIT License 70 | 71 | Copyright (c) 2018 Louis D'hauwe 72 | 73 | Permission is hereby granted, free of charge, to any person obtaining a copy 74 | of this software and associated documentation files (the "Software"), to deal 75 | in the Software without restriction, including without limitation the rights 76 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 77 | copies of the Software, and to permit persons to whom the Software is 78 | furnished to do so, subject to the following conditions: 79 | 80 | The above copyright notice and this permission notice shall be included in all 81 | copies or substantial portions of the Software. 82 | 83 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 84 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 85 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 86 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 87 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 88 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 89 | SOFTWARE. 90 | ``` 91 | 92 | ## SourceEditor 93 | 94 | ``` 95 | MIT License 96 | 97 | Copyright (c) 2018 Louis D'hauwe 98 | 99 | Permission is hereby granted, free of charge, to any person obtaining a copy 100 | of this software and associated documentation files (the "Software"), to deal 101 | in the Software without restriction, including without limitation the rights 102 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 103 | copies of the Software, and to permit persons to whom the Software is 104 | furnished to do so, subject to the following conditions: 105 | 106 | The above copyright notice and this permission notice shall be included in all 107 | copies or substantial portions of the Software. 108 | 109 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 110 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 111 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 112 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 113 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 114 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 115 | SOFTWARE. 116 | ``` 117 | 118 | Generated by CocoaPods - https://cocoapods.org 119 | -------------------------------------------------------------------------------- /docs/Pasteboard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

pasteboard

8 | 9 |

This module is used for copy and pasting data.

10 | 11 |

Retrieving text

12 | 13 |

string

14 | 15 |

pasteboard.string()

16 | 17 |

Returns the copied text.

18 | 19 |

strings

20 | 21 |

pasteboard.strings()

22 | 23 |

Returns the copied texts.

24 | 25 |

Setting text

26 | 27 |

setString

28 | 29 |

pasteboard.setString(string)

30 | 31 |

Copies the given string.

32 | 33 |

setStrings

34 | 35 |

pasteboard.setStrings(strings...)

36 | 37 |

Copies the given strings.

38 | 39 |

Each parameter passed will be copied. Example:

40 | 41 |
pasteboard.setStrings("Hello World!", "Bye!")
42 |     
43 | 44 | 45 | -------------------------------------------------------------------------------- /docs/ShareSheet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

sharesheet

8 | 9 |

This module is used for acessing data trough the iOS share sheet and for sharing items. Place a script in the 'Share Sheet' folder to show it on the share sheet. With your scripts, you can share text, URLs and files.

10 | 11 |

Retrieving passed data

12 | 13 |

string

14 | 15 |

sharesheet.string()

16 | 17 |

Returns a string passed to the script.

18 | 19 |

url

20 | 21 |

sharesheet.url()

22 | 23 |

Returns an URL passed to the script. (As a String)

24 | 25 |

filePath

26 | 27 |

sharesheet.filePath()

28 | 29 |

Returns the path of a file passed to the script.

30 | 31 |

Sharing data

32 | 33 |

shareItems

34 | 35 |

sharesheet.shareItems(items...)

36 | 37 |

Opens the share sheet for sharing the given items. 38 | Each parameter passed will be a shared items. Example:

39 | 40 |
sharesheet.shareItems("Hello World!", "https://develobile.com")
41 |     
42 | 43 | 44 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Documentation

8 | 9 |

Luade has some modules made just for the app.

10 | 11 |

You can import another script that is on the same directory than the script you are editing with require "scriptName".

12 | 13 |

Libraries

14 | 21 | 22 |

Functions

23 |
    24 |
  • openURL(string) 25 | Opens the given URL. 26 | 27 | Returns: true if the URL was opened successfully. 28 |
  • 29 |
30 | 31 | -------------------------------------------------------------------------------- /docs/styles.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | color: white; 4 | font-family: Helvetica; 5 | background-color: #212121; 6 | } 7 | 8 | a { 9 | color: rgb(0, 122, 255); 10 | text-decoration: none; 11 | } 12 | -------------------------------------------------------------------------------- /mockup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColdGrub1384/Luade/cab270248a6b744d745fbb157b9f8c441d977993/mockup.png -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 4 | cd "$DIR" 5 | 6 | pod install 7 | 8 | git submodule init 9 | git submodule update 10 | --------------------------------------------------------------------------------