├── .gitignore ├── LICENSE ├── Original.png ├── Patched.png ├── README.md ├── WaxPatch ├── WaxPatch.xcodeproj │ └── project.pbxproj └── WaxPatch │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── MainViewController.h │ ├── MainViewController.m │ ├── ProtocolLoader.h │ ├── WaxPatch-Info.plist │ ├── WaxPatch-Prefix.pch │ ├── ZipArchive.h │ ├── ZipArchive.mm │ ├── en.lproj │ └── InfoPlist.strings │ ├── main.m │ ├── minizip │ ├── crypt.h │ ├── ioapi.c │ ├── ioapi.h │ ├── mztools.c │ ├── mztools.h │ ├── unzip.c │ ├── unzip.h │ ├── zip.c │ └── zip.h │ └── wax │ ├── extensions │ ├── CGAffine │ │ ├── wax_CGTransform.h │ │ └── wax_CGTransform.m │ ├── CGContext │ │ ├── wax_CGContext.h │ │ └── wax_CGContext.m │ ├── HTTP │ │ ├── wax_http.h │ │ ├── wax_http.m │ │ ├── wax_http_connection.h │ │ └── wax_http_connection.m │ ├── filesystem │ │ ├── wax_filesystem.h │ │ └── wax_filesystem.m │ └── json │ │ ├── Rakefile │ │ ├── wax_json.c │ │ ├── wax_json.h │ │ ├── yajl-1.0.9.tar.gz │ │ └── yajl │ │ ├── api │ │ ├── yajl_common.h │ │ ├── yajl_gen.h │ │ └── yajl_parse.h │ │ ├── yajl.c │ │ ├── yajl_alloc.c │ │ ├── yajl_alloc.h │ │ ├── yajl_buf.c │ │ ├── yajl_buf.h │ │ ├── yajl_bytestack.h │ │ ├── yajl_common.h │ │ ├── yajl_encode.c │ │ ├── yajl_encode.h │ │ ├── yajl_gen.c │ │ ├── yajl_gen.h │ │ ├── yajl_lex.c │ │ ├── yajl_lex.h │ │ ├── yajl_parse.h │ │ ├── yajl_parser.c │ │ └── yajl_parser.h │ ├── lua │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.c │ ├── lcode.c │ ├── lcode.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 │ ├── 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 │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── lstrlib.c │ ├── ltable.c │ ├── ltable.h │ ├── ltablib.c │ ├── ltm.c │ ├── ltm.h │ ├── lua.h │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ ├── lzio.h │ └── print.c │ ├── wax.h │ ├── wax.m │ ├── wax_class.h │ ├── wax_class.m │ ├── wax_gc.h │ ├── wax_gc.m │ ├── wax_helpers.h │ ├── wax_helpers.m │ ├── wax_instance.h │ ├── wax_instance.m │ ├── wax_server.h │ ├── wax_server.m │ ├── wax_stdlib.h │ ├── wax_struct.h │ └── wax_struct.m └── patch ├── MainViewController.lua ├── patch.lua └── patch.zip /.gitignore: -------------------------------------------------------------------------------- 1 | # xcode noise 2 | build/* 3 | *.perspective 4 | *.perspectivev3 5 | *.pbxuser 6 | *.xcworkspace 7 | *.mode1 8 | *.mode2v3 9 | *.mode1v3 10 | xcuserdata 11 | Snapshots 12 | 13 | # osx noise 14 | .DS_Store 15 | 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 Corey Johnson 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmin18/WaxPatch/ab9187d0d13013d280aa81c8029c1a116d1cca0c/Original.png -------------------------------------------------------------------------------- /Patched.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmin18/WaxPatch/ab9187d0d13013d280aa81c8029c1a116d1cca0c/Patched.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Wax Loader 2 | Mutated version of Wax (https://github.com/probablycorey/wax/) 3 | 4 | Support method override and direct method call from Obj-C code, which gives you the ability to dynamically change the behavior of a running iOS application. 5 | 6 | It has been proved stable on more than 5,000,000 devices. 7 | ### Tutorial 8 | The patch is a zip file contains patch.lua and other lua codes. The sample code can be found at /patch folder. 9 | 10 | The sample iOS project loads the patch from a url (which you probably want to change in AppDelegate.m) before launch. 11 | 12 | ##### The original version in obj-c: 13 | 14 | ![Original](https://raw.github.com/mmin18/Create-a-More-Flexible-App/master/WaxOriginal.png) 15 | 16 | @implementation MainViewController 17 | 18 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 19 | return 10; 20 | } 21 | 22 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 23 | UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]; 24 | cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row + 1]; 25 | return cell; 26 | } 27 | 28 | @end 29 | 30 | ##### The pacthed version with lua: 31 | 32 | ![Patched](https://raw.github.com/mmin18/Create-a-More-Flexible-App/master/WaxPatched.png) 33 | 34 | waxClass{"MainViewController", UITableViewController} 35 | 36 | function tableView_cellForRowAtIndexPath(self, tableView, indexPath) 37 | local cell = self:ORIGtableView_cellForRowAtIndexPath(tableView, indexPath) -- The original method is retained with 'ORIG' prefix 38 | cell:textLabel():setText("" .. (10 - indexPath:row())) 39 | cell:detailTextLabel():setText("http://github.com/mmin18") 40 | cell:textLabel():setTextColor(UIColor:redColor()) 41 | return cell 42 | end 43 | 44 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WaxPatch 4 | // 5 | // Created by Yimin Tu on 12-8-4. 6 | // Copyright (c) 2012年 dianping.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WaxPatch 4 | // 5 | // Created by Yimin Tu on 12-8-4. 6 | // Copyright (c) 2012年 dianping.com. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "lauxlib.h" 11 | #import "wax.h" 12 | #import "ZipArchive.h" 13 | #import "MainViewController.h" 14 | 15 | #define WAX_PATCH_URL @"http://raw.github.com/mmin18/WaxPatch/master/patch/patch.zip" 16 | 17 | @implementation AppDelegate 18 | 19 | @synthesize window = _window; 20 | 21 | - (id)init { 22 | if(self = [super init]) { 23 | NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 24 | 25 | NSString *dir = [doc stringByAppendingPathComponent:@"lua"]; 26 | [[NSFileManager defaultManager] removeItemAtPath:dir error:NULL]; 27 | [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:NULL]; 28 | 29 | NSString *pp = [[NSString alloc ] initWithFormat:@"%@/?.lua;%@/?/init.lua;", dir, dir]; 30 | setenv(LUA_PATH, [pp UTF8String], 1); 31 | } 32 | return self; 33 | } 34 | 35 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 36 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 37 | // Override point for customization after application launch. 38 | self.window.backgroundColor = [UIColor whiteColor]; 39 | self.window.rootViewController = [[MainViewController alloc] init]; 40 | [self.window makeKeyAndVisible]; 41 | 42 | [[[UIAlertView alloc] initWithTitle:@"WaxPatch" message:@"This is the obj-c impl of a simple table view. Press [Load] button to load the wax patch and run from lua." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Load", nil] show]; 43 | 44 | return YES; 45 | } 46 | 47 | - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 48 | if(buttonIndex == [alertView firstOtherButtonIndex]) { 49 | // you probably want to change this url before run 50 | NSURL *patchUrl = [NSURL URLWithString:WAX_PATCH_URL]; 51 | NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:patchUrl] returningResponse:NULL error:NULL]; 52 | if(data) { 53 | NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 54 | 55 | NSString *patchZip = [doc stringByAppendingPathComponent:@"patch.zip"]; 56 | [data writeToFile:patchZip atomically:YES]; 57 | 58 | NSString *dir = [doc stringByAppendingPathComponent:@"lua"]; 59 | [[NSFileManager defaultManager] removeItemAtPath:dir error:NULL]; 60 | [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:NULL]; 61 | 62 | ZipArchive *zip = [[ZipArchive alloc] init]; 63 | [zip UnzipOpenFile:patchZip]; 64 | [zip UnzipFileTo:dir overWrite:YES]; 65 | 66 | NSString *pp = [[NSString alloc ] initWithFormat:@"%@/?.lua;%@/?/init.lua;", dir, dir]; 67 | setenv(LUA_PATH, [pp UTF8String], 1); 68 | wax_start("patch", nil); 69 | 70 | // reinit MainViewController again 71 | self.window.rootViewController = [[MainViewController alloc] init]; 72 | [self.window makeKeyAndVisible]; 73 | } else { 74 | [[[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"Fail to download wax patch from %@", patchUrl] delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil] show]; 75 | } 76 | } 77 | } 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/MainViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.h 3 | // WaxPatch 4 | // 5 | // Created by Yimin Tu on 12-8-10. 6 | // Copyright (c) 2012年 dianping.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MainViewController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/MainViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.m 3 | // WaxPatch 4 | // 5 | // Created by Yimin Tu on 12-8-10. 6 | // Copyright (c) 2012年 dianping.com. All rights reserved. 7 | // 8 | 9 | #import "MainViewController.h" 10 | 11 | @interface MainViewController () 12 | 13 | @end 14 | 15 | @implementation MainViewController 16 | 17 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 18 | return 10; 19 | } 20 | 21 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 22 | UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]; 23 | cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row + 1]; 24 | return cell; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/ProtocolLoader.h: -------------------------------------------------------------------------------- 1 | // Many protocols will work from wax out of the box. But some need to be preloaded. 2 | // If the protocol you are using isn't found, just add the protocol to this object 3 | // 4 | // This seems to be a bug, or there is a runtime method I'm unaware of 5 | 6 | #import 7 | 8 | @interface ProtocolLoader : NSObject {} 9 | @end 10 | 11 | @implementation ProtocolLoader 12 | @end 13 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/WaxPatch-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.dianping.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/WaxPatch-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'WaxPatch' target in the 'WaxPatch' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iOS SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/ZipArchive.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZipArchive.h 3 | // 4 | // 5 | // Created by aish on 08-9-11. 6 | // acsolu@gmail.com 7 | // Copyright 2008 Inc. All rights reserved. 8 | // 9 | // History: 10 | // 09-11-2008 version 1.0 release 11 | // 10-18-2009 version 1.1 support password protected zip files 12 | // 10-21-2009 version 1.2 fix date bug 13 | 14 | #import 15 | 16 | #include "minizip/zip.h" 17 | #include "minizip/unzip.h" 18 | 19 | 20 | @protocol ZipArchiveDelegate 21 | @optional 22 | -(void) ErrorMessage:(NSString*) msg; 23 | -(BOOL) OverWriteOperation:(NSString*) file; 24 | 25 | @end 26 | 27 | 28 | @interface ZipArchive : NSObject { 29 | @private 30 | zipFile _zipFile; 31 | unzFile _unzFile; 32 | 33 | NSString* _password; 34 | id _delegate; 35 | } 36 | 37 | @property (nonatomic, retain) id delegate; 38 | 39 | -(BOOL) CreateZipFile2:(NSString*) zipFile; 40 | -(BOOL) CreateZipFile2:(NSString*) zipFile Password:(NSString*) password; 41 | -(BOOL) addFileToZip:(NSString*) file newname:(NSString*) newname; 42 | -(BOOL) CloseZipFile2; 43 | 44 | -(BOOL) UnzipOpenFile:(NSString*) zipFile; 45 | -(BOOL) UnzipOpenFile:(NSString*) zipFile Password:(NSString*) password; 46 | -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite; 47 | -(BOOL) UnzipCloseFile; 48 | @end 49 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WaxPatch 4 | // 5 | // Created by Yimin Tu on 12-8-4. 6 | // Copyright (c) 2012年 dianping.com. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "wax.h" 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | 17 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/minizip/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for crypt/uncrypt ZIPfile 2 | 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | 8 | This code is a modified version of crypting code in Infozip distribution 9 | 10 | The encryption/decryption parts of this source code (as opposed to the 11 | non-echoing password parts) were originally written in Europe. The 12 | whole source package can be freely distributed, including from the USA. 13 | (Prior to January 2000, re-export from the US was a violation of US law.) 14 | 15 | This encryption code is a direct transcription of the algorithm from 16 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 17 | file (appnote.txt) is distributed with the PKZIP program (even in the 18 | version without encryption capabilities). 19 | 20 | If you don't need crypting in your application, just define symbols 21 | NOCRYPT and NOUNCRYPT. 22 | 23 | This code support the "Traditional PKWARE Encryption". 24 | 25 | The new AES encryption added on Zip format by Winzip (see the page 26 | http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong 27 | Encryption is not supported. 28 | */ 29 | 30 | #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 31 | 32 | /*********************************************************************** 33 | * Return the next byte in the pseudo-random sequence 34 | */ 35 | static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) 36 | { 37 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 38 | * unpredictable manner on 16-bit systems; not a problem 39 | * with any known compiler so far, though */ 40 | 41 | temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 42 | return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 43 | } 44 | 45 | /*********************************************************************** 46 | * Update the encryption keys with the next byte of plain text 47 | */ 48 | static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) 49 | { 50 | (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 51 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 52 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 53 | { 54 | register int keyshift = (int)((*(pkeys+1)) >> 24); 55 | (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 56 | } 57 | return c; 58 | } 59 | 60 | 61 | /*********************************************************************** 62 | * Initialize the encryption keys and the random header according to 63 | * the given password. 64 | */ 65 | static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) 66 | { 67 | *(pkeys+0) = 305419896L; 68 | *(pkeys+1) = 591751049L; 69 | *(pkeys+2) = 878082192L; 70 | while (*passwd != '\0') { 71 | update_keys(pkeys,pcrc_32_tab,(int)*passwd); 72 | passwd++; 73 | } 74 | } 75 | 76 | #define zdecode(pkeys,pcrc_32_tab,c) \ 77 | (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 78 | 79 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 80 | (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 81 | 82 | #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 83 | 84 | #define RAND_HEAD_LEN 12 85 | /* "last resort" source for second part of crypt seed pattern */ 86 | # ifndef ZCR_SEED2 87 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 88 | # endif 89 | 90 | static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) 91 | const char *passwd; /* password string */ 92 | unsigned char *buf; /* where to write header */ 93 | int bufSize; 94 | unsigned long* pkeys; 95 | const unsigned long* pcrc_32_tab; 96 | unsigned long crcForCrypting; 97 | { 98 | int n; /* index in random header */ 99 | int t; /* temporary */ 100 | int c; /* random byte */ 101 | unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 102 | static unsigned calls = 0; /* ensure different random header each time */ 103 | 104 | if (bufSize> 7) & 0xff; 119 | header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 120 | } 121 | /* Encrypt random header (last two bytes is high word of crc) */ 122 | init_keys(passwd, pkeys, pcrc_32_tab); 123 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 124 | { 125 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 126 | } 127 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 128 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 129 | return n; 130 | } 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/minizip/ioapi.c: -------------------------------------------------------------------------------- 1 | /* ioapi.c -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "zlib.h" 14 | #include "ioapi.h" 15 | 16 | 17 | 18 | /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 19 | 20 | #ifndef SEEK_CUR 21 | #define SEEK_CUR 1 22 | #endif 23 | 24 | #ifndef SEEK_END 25 | #define SEEK_END 2 26 | #endif 27 | 28 | #ifndef SEEK_SET 29 | #define SEEK_SET 0 30 | #endif 31 | 32 | voidpf ZCALLBACK fopen_file_func OF(( 33 | voidpf opaque, 34 | const char* filename, 35 | int mode)); 36 | 37 | uLong ZCALLBACK fread_file_func OF(( 38 | voidpf opaque, 39 | voidpf stream, 40 | void* buf, 41 | uLong size)); 42 | 43 | uLong ZCALLBACK fwrite_file_func OF(( 44 | voidpf opaque, 45 | voidpf stream, 46 | const void* buf, 47 | uLong size)); 48 | 49 | long ZCALLBACK ftell_file_func OF(( 50 | voidpf opaque, 51 | voidpf stream)); 52 | 53 | long ZCALLBACK fseek_file_func OF(( 54 | voidpf opaque, 55 | voidpf stream, 56 | uLong offset, 57 | int origin)); 58 | 59 | int ZCALLBACK fclose_file_func OF(( 60 | voidpf opaque, 61 | voidpf stream)); 62 | 63 | int ZCALLBACK ferror_file_func OF(( 64 | voidpf opaque, 65 | voidpf stream)); 66 | 67 | 68 | voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) 69 | voidpf opaque; 70 | const char* filename; 71 | int mode; 72 | { 73 | FILE* file = NULL; 74 | const char* mode_fopen = NULL; 75 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 76 | mode_fopen = "rb"; 77 | else 78 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 79 | mode_fopen = "r+b"; 80 | else 81 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 82 | mode_fopen = "wb"; 83 | 84 | if ((filename!=NULL) && (mode_fopen != NULL)) 85 | file = fopen(filename, mode_fopen); 86 | return file; 87 | } 88 | 89 | 90 | uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) 91 | voidpf opaque; 92 | voidpf stream; 93 | void* buf; 94 | uLong size; 95 | { 96 | uLong ret; 97 | ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); 98 | return ret; 99 | } 100 | 101 | 102 | uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) 103 | voidpf opaque; 104 | voidpf stream; 105 | const void* buf; 106 | uLong size; 107 | { 108 | uLong ret; 109 | ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); 110 | return ret; 111 | } 112 | 113 | long ZCALLBACK ftell_file_func (opaque, stream) 114 | voidpf opaque; 115 | voidpf stream; 116 | { 117 | long ret; 118 | ret = ftell((FILE *)stream); 119 | return ret; 120 | } 121 | 122 | long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) 123 | voidpf opaque; 124 | voidpf stream; 125 | uLong offset; 126 | int origin; 127 | { 128 | int fseek_origin=0; 129 | long ret; 130 | switch (origin) 131 | { 132 | case ZLIB_FILEFUNC_SEEK_CUR : 133 | fseek_origin = SEEK_CUR; 134 | break; 135 | case ZLIB_FILEFUNC_SEEK_END : 136 | fseek_origin = SEEK_END; 137 | break; 138 | case ZLIB_FILEFUNC_SEEK_SET : 139 | fseek_origin = SEEK_SET; 140 | break; 141 | default: return -1; 142 | } 143 | ret = 0; 144 | fseek((FILE *)stream, offset, fseek_origin); 145 | return ret; 146 | } 147 | 148 | int ZCALLBACK fclose_file_func (opaque, stream) 149 | voidpf opaque; 150 | voidpf stream; 151 | { 152 | int ret; 153 | ret = fclose((FILE *)stream); 154 | return ret; 155 | } 156 | 157 | int ZCALLBACK ferror_file_func (opaque, stream) 158 | voidpf opaque; 159 | voidpf stream; 160 | { 161 | int ret; 162 | ret = ferror((FILE *)stream); 163 | return ret; 164 | } 165 | 166 | void fill_fopen_filefunc (pzlib_filefunc_def) 167 | zlib_filefunc_def* pzlib_filefunc_def; 168 | { 169 | pzlib_filefunc_def->zopen_file = fopen_file_func; 170 | pzlib_filefunc_def->zread_file = fread_file_func; 171 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 172 | pzlib_filefunc_def->ztell_file = ftell_file_func; 173 | pzlib_filefunc_def->zseek_file = fseek_file_func; 174 | pzlib_filefunc_def->zclose_file = fclose_file_func; 175 | pzlib_filefunc_def->zerror_file = ferror_file_func; 176 | pzlib_filefunc_def->opaque = NULL; 177 | } 178 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/minizip/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | */ 8 | 9 | #ifndef _ZLIBIOAPI_H 10 | #define _ZLIBIOAPI_H 11 | 12 | 13 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 14 | #define ZLIB_FILEFUNC_SEEK_END (2) 15 | #define ZLIB_FILEFUNC_SEEK_SET (0) 16 | 17 | #define ZLIB_FILEFUNC_MODE_READ (1) 18 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 19 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 20 | 21 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 22 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 23 | 24 | 25 | #ifndef ZCALLBACK 26 | 27 | #if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 28 | #define ZCALLBACK CALLBACK 29 | #else 30 | #define ZCALLBACK 31 | #endif 32 | #endif 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 39 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 40 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 41 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 42 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 43 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 44 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 45 | 46 | typedef struct zlib_filefunc_def_s 47 | { 48 | open_file_func zopen_file; 49 | read_file_func zread_file; 50 | write_file_func zwrite_file; 51 | tell_file_func ztell_file; 52 | seek_file_func zseek_file; 53 | close_file_func zclose_file; 54 | testerror_file_func zerror_file; 55 | voidpf opaque; 56 | } zlib_filefunc_def; 57 | 58 | 59 | 60 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 61 | 62 | #define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) 63 | #define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) 64 | #define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) 65 | #define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) 66 | #define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) 67 | #define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) 68 | 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif 75 | 76 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/minizip/mztools.h: -------------------------------------------------------------------------------- 1 | /* 2 | Additional tools for Minizip 3 | Code: Xavier Roche '2004 4 | License: Same as ZLIB (www.gzip.org) 5 | */ 6 | 7 | #ifndef _zip_tools_H 8 | #define _zip_tools_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #ifndef _ZLIB_H 15 | #include "zlib.h" 16 | #endif 17 | 18 | #include "unzip.h" 19 | 20 | /* Repair a ZIP file (missing central directory) 21 | file: file to recover 22 | fileOut: output file after recovery 23 | fileOutTmp: temporary file name used for recovery 24 | */ 25 | extern int ZEXPORT unzRepair(const char* file, 26 | const char* fileOut, 27 | const char* fileOutTmp, 28 | uLong* nRecovered, 29 | uLong* bytesRecovered); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/CGAffine/wax_CGTransform.h: -------------------------------------------------------------------------------- 1 | // 2 | // wax_CGAffine.h 3 | // EmpireState 4 | // 5 | // Created by Corey Johnson on 10/6/09. 6 | // Copyright 2009 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "lua.h" 11 | 12 | int luaopen_wax_CGTransform(lua_State *L); -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/CGAffine/wax_CGTransform.m: -------------------------------------------------------------------------------- 1 | // 2 | // wax_CGAffine.m 3 | // EmpireState 4 | // 5 | // Created by Corey Johnson on 10/6/09. 6 | // Copyright 2009 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import "wax_CGTransform.h" 10 | 11 | #import "wax_instance.h" 12 | #import "wax_helpers.h" 13 | 14 | #import "lua.h" 15 | #import "lauxlib.h" 16 | 17 | #define METATABLE_NAME "wax.CGTransform" 18 | 19 | static int identity(lua_State *L) { 20 | CGAffineTransform identity = CGAffineTransformIdentity; 21 | wax_fromObjc(L, @encode(CGAffineTransform), &identity); 22 | 23 | return 1; 24 | } 25 | 26 | 27 | // wax.CGTransform.scale(transform, 2, 2) -- Returns new transform 28 | static int scale(lua_State *L) { 29 | void *value = wax_copyToObjc(L, @encode(CGAffineTransform), 1, nil); 30 | CGAffineTransform transform = *(CGAffineTransform *)value; 31 | free(value); 32 | transform = CGAffineTransformScale(transform, luaL_checknumber(L, 2), luaL_checknumber(L, 3)); 33 | wax_fromObjc(L, @encode(CGAffineTransform), &transform); 34 | 35 | return 1; 36 | } 37 | 38 | // wax.CGTransform.translate(transform, 2, 2) -- Returns new transform 39 | static int translate(lua_State *L) { 40 | void *value = wax_copyToObjc(L, @encode(CGAffineTransform), 1, nil); 41 | CGAffineTransform transform = *(CGAffineTransform *)value; 42 | free(value); 43 | transform = CGAffineTransformTranslate(transform, luaL_checknumber(L, 2), luaL_checknumber(L, 3)); 44 | wax_fromObjc(L, @encode(CGAffineTransform), &transform); 45 | 46 | return 1; 47 | } 48 | 49 | // wax.CGTransform.rotate(transform, angle) -- Returns new transform 50 | static int rotate(lua_State *L) { 51 | void *value = wax_copyToObjc(L, @encode(CGAffineTransform), 1, nil); 52 | CGAffineTransform transform = *(CGAffineTransform *)value; 53 | free(value); 54 | transform = CGAffineTransformRotate(transform, luaL_checknumber(L, 2)); 55 | wax_fromObjc(L, @encode(CGAffineTransform), &transform); 56 | 57 | 58 | 59 | return 1; 60 | } 61 | 62 | static const struct luaL_Reg metaFunctions[] = { 63 | {NULL, NULL} 64 | }; 65 | 66 | static const struct luaL_Reg functions[] = { 67 | {"identity", identity}, 68 | {"scale", scale}, 69 | {"translate", translate}, 70 | {"rotate", rotate}, 71 | 72 | {NULL, NULL} 73 | }; 74 | 75 | int luaopen_wax_CGTransform(lua_State *L) { 76 | BEGIN_STACK_MODIFY(L); 77 | 78 | luaL_newmetatable(L, METATABLE_NAME); 79 | luaL_register(L, NULL, metaFunctions); 80 | luaL_register(L, METATABLE_NAME, functions); 81 | 82 | END_STACK_MODIFY(L, 0) 83 | 84 | return 1; 85 | } 86 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/CGContext/wax_CGContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // WaxCGContext.h 3 | // EmpireState 4 | // 5 | // Created by Corey Johnson on 10/5/09. 6 | // Copyright 2009 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "lua.h" 11 | 12 | int luaopen_wax_CGContext(lua_State *L); -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/HTTP/wax_http.h: -------------------------------------------------------------------------------- 1 | // 2 | // wax_http.h 3 | // Rentals 4 | // 5 | // Created by ProbablyInteractive on 7/13/09. 6 | // Copyright 2009 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "lua.h" 11 | 12 | #define WAX_HTTP_METATABLE_NAME "wax.http" 13 | 14 | int luaopen_wax_http(lua_State *L); -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/HTTP/wax_http_connection.h: -------------------------------------------------------------------------------- 1 | // 2 | // wax_http_connection.h 3 | // RentList 4 | // 5 | // Created by Corey Johnson on 8/9/09. 6 | // Copyright 2009 ProbablyInteractive. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "lua.h" 11 | 12 | enum { 13 | WAX_HTTP_UNKNOWN, 14 | WAX_HTTP_TEXT, 15 | WAX_HTTP_BINARY, // Like an image or something 16 | WAX_HTTP_JSON, 17 | WAX_HTTP_XML 18 | }; 19 | 20 | #define WAX_HTTP_CALLBACK_FUNCTION_NAME "callback" 21 | #define WAX_HTTP_PROGRESS_CALLBACK_FUNCTION_NAME "progressCallback" 22 | #define WAX_HTTP_AUTH_CALLBACK_FUNCTION_NAME "authCallback" 23 | #define WAX_HTTP_REDIRECT_CALLBACK_FUNCTION_NAME "redirectCallback" 24 | 25 | @interface wax_http_connection : NSURLConnection { 26 | lua_State *L; 27 | NSMutableData *_data; 28 | NSHTTPURLResponse *_response; 29 | NSURLRequest *_request; 30 | NSTimer *_timeoutTimer; 31 | NSError *_error; 32 | 33 | NSTimeInterval _timeout; 34 | int _format; 35 | bool _finished; 36 | bool _canceled; 37 | } 38 | 39 | @property (nonatomic, assign) NSHTTPURLResponse *response; 40 | 41 | @property (nonatomic, assign) int format; 42 | @property (nonatomic, readonly, getter=isFinished) bool finished; 43 | 44 | - (id)initWithRequest:(NSURLRequest *)urlRequest timeout:(NSTimeInterval)timeout luaState:(lua_State *)luaState; 45 | - (void)callRedirectCallback:(NSURLResponse *)redirectResponse; 46 | - (BOOL)callLuaAuthCallback:(NSURLAuthenticationChallenge *)challenge; 47 | - (void)callLuaProgressCallback; 48 | - (void)callLuaCallback; 49 | 50 | // HSHTTPURLResponse Delegate Methods 51 | - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error; 52 | 53 | @end 54 | 55 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/filesystem/wax_filesystem.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Corey Johnson on 10/5/09. 3 | // Copyright 2009 Probably Interactive. All rights reserved. 4 | // 5 | 6 | #import 7 | #import "lua.h" 8 | 9 | int luaopen_wax_filesystem(lua_State *L); 10 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/Rakefile: -------------------------------------------------------------------------------- 1 | task :default do 2 | sh 'tar zxvf yajl-1.0.9.tar.gz -- yajl-1.0.9/src/*.{c,h}' 3 | rm_rf 'yajl' 4 | mv 'yajl-1.0.9/src', 'yajl' 5 | sh %[sed -i '' -e 's,include ,include "yajl_common.h",g' yajl/api/yajl_{parse,gen}.h] 6 | ln_sf 'api/yajl_parse.h', 'yajl/' 7 | ln_sf 'api/yajl_gen.h', 'yajl/' 8 | ln_sf 'api/yajl_common.h', 'yajl/' 9 | rm_rf 'yajl-1.0.9' 10 | end 11 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/wax_json.h: -------------------------------------------------------------------------------- 1 | #ifndef json_h 2 | #define json_h 3 | 4 | #import "lua.h" 5 | 6 | #define JSON_METATABLE_NAME "wax.json" 7 | 8 | int luaopen_wax_json(lua_State *L); 9 | void json_parseString(lua_State *L, const char *input); 10 | 11 | #endif -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl-1.0.9.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmin18/WaxPatch/ab9187d0d13013d280aa81c8029c1a116d1cca0c/WaxPatch/WaxPatch/wax/extensions/json/yajl-1.0.9.tar.gz -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/api/yajl_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __YAJL_COMMON_H__ 34 | #define __YAJL_COMMON_H__ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #define YAJL_MAX_DEPTH 128 41 | 42 | /* msft dll export gunk. To build a DLL on windows, you 43 | * must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared 44 | * DLL, you must define YAJL_SHARED and WIN32 */ 45 | #if defined(WIN32) && defined(YAJL_SHARED) 46 | # ifdef YAJL_BUILD 47 | # define YAJL_API __declspec(dllexport) 48 | # else 49 | # define YAJL_API __declspec(dllimport) 50 | # endif 51 | #else 52 | # define YAJL_API 53 | #endif 54 | 55 | /** pointer to a malloc function, supporting client overriding memory 56 | * allocation routines */ 57 | typedef void * (*yajl_malloc_func)(void *ctx, unsigned int sz); 58 | 59 | /** pointer to a free function, supporting client overriding memory 60 | * allocation routines */ 61 | typedef void (*yajl_free_func)(void *ctx, void * ptr); 62 | 63 | /** pointer to a realloc function which can resize an allocation. */ 64 | typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, unsigned int sz); 65 | 66 | /** A structure which can be passed to yajl_*_alloc routines to allow the 67 | * client to specify memory allocation functions to be used. */ 68 | typedef struct 69 | { 70 | /** pointer to a function that can allocate uninitialized memory */ 71 | yajl_malloc_func malloc; 72 | /** pointer to a function that can resize memory allocations */ 73 | yajl_realloc_func realloc; 74 | /** pointer to a function that can free memory allocated using 75 | * reallocFunction or mallocFunction */ 76 | yajl_free_func free; 77 | /** a context pointer that will be passed to above allocation routines */ 78 | void * ctx; 79 | } yajl_alloc_funcs; 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/api/yajl_gen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | * \file yajl_gen.h 35 | * Interface to YAJL's JSON generation facilities. 36 | */ 37 | 38 | #include "yajl_common.h" 39 | 40 | #ifndef __YAJL_GEN_H__ 41 | #define __YAJL_GEN_H__ 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | /** generator status codes */ 47 | typedef enum { 48 | /** no error */ 49 | yajl_gen_status_ok = 0, 50 | /** at a point where a map key is generated, a function other than 51 | * yajl_gen_string was called */ 52 | yajl_gen_keys_must_be_strings, 53 | /** YAJL's maximum generation depth was exceeded. see 54 | * YAJL_MAX_DEPTH */ 55 | yajl_max_depth_exceeded, 56 | /** A generator function (yajl_gen_XXX) was called while in an error 57 | * state */ 58 | yajl_gen_in_error_state, 59 | /** A complete JSON document has been generated */ 60 | yajl_gen_generation_complete, 61 | /** yajl_gen_double was passed an invalid floating point value 62 | * (infinity or NaN). */ 63 | yajl_gen_invalid_number, 64 | /** A print callback was passed in, so there is no internal 65 | * buffer to get from */ 66 | yajl_gen_no_buf 67 | } yajl_gen_status; 68 | 69 | /** an opaque handle to a generator */ 70 | typedef struct yajl_gen_t * yajl_gen; 71 | 72 | /** a callback used for "printing" the results. */ 73 | typedef void (*yajl_print_t)(void * ctx, 74 | const char * str, 75 | unsigned int len); 76 | 77 | /** configuration structure for the generator */ 78 | typedef struct { 79 | /** generate indented (beautiful) output */ 80 | unsigned int beautify; 81 | /** an opportunity to define an indent string. such as \\t or 82 | * some number of spaces. default is four spaces ' '. This 83 | * member is only relevant when beautify is true */ 84 | const char * indentString; 85 | } yajl_gen_config; 86 | 87 | /** allocate a generator handle 88 | * \param config a pointer to a structure containing parameters which 89 | * configure the behavior of the json generator 90 | * \param allocFuncs an optional pointer to a structure which allows 91 | * the client to overide the memory allocation 92 | * used by yajl. May be NULL, in which case 93 | * malloc/free/realloc will be used. 94 | * 95 | * \returns an allocated handle on success, NULL on failure (bad params) 96 | */ 97 | YAJL_API yajl_gen yajl_gen_alloc(const yajl_gen_config * config, 98 | const yajl_alloc_funcs * allocFuncs); 99 | 100 | /** allocate a generator handle that will print to the specified 101 | * callback rather than storing the results in an internal buffer. 102 | * \param callback a pointer to a printer function. May be NULL 103 | * in which case, the results will be store in an 104 | * internal buffer. 105 | * \param config a pointer to a structure containing parameters 106 | * which configure the behavior of the json 107 | * generator. 108 | * \param allocFuncs an optional pointer to a structure which allows 109 | * the client to overide the memory allocation 110 | * used by yajl. May be NULL, in which case 111 | * malloc/free/realloc will be used. 112 | * \param ctx a context pointer that will be passed to the 113 | * printer callback. 114 | * 115 | * \returns an allocated handle on success, NULL on failure (bad params) 116 | */ 117 | YAJL_API yajl_gen yajl_gen_alloc2(const yajl_print_t callback, 118 | const yajl_gen_config * config, 119 | const yajl_alloc_funcs * allocFuncs, 120 | void * ctx); 121 | 122 | /** free a generator handle */ 123 | YAJL_API void yajl_gen_free(yajl_gen handle); 124 | 125 | YAJL_API yajl_gen_status yajl_gen_integer(yajl_gen hand, long int number); 126 | /** generate a floating point number. number may not be infinity or 127 | * NaN, as these have no representation in JSON. In these cases the 128 | * generator will return 'yajl_gen_invalid_number' */ 129 | YAJL_API yajl_gen_status yajl_gen_double(yajl_gen hand, double number); 130 | YAJL_API yajl_gen_status yajl_gen_number(yajl_gen hand, 131 | const char * num, 132 | unsigned int len); 133 | YAJL_API yajl_gen_status yajl_gen_string(yajl_gen hand, 134 | const unsigned char * str, 135 | unsigned int len); 136 | YAJL_API yajl_gen_status yajl_gen_null(yajl_gen hand); 137 | YAJL_API yajl_gen_status yajl_gen_bool(yajl_gen hand, int boolean); 138 | YAJL_API yajl_gen_status yajl_gen_map_open(yajl_gen hand); 139 | YAJL_API yajl_gen_status yajl_gen_map_close(yajl_gen hand); 140 | YAJL_API yajl_gen_status yajl_gen_array_open(yajl_gen hand); 141 | YAJL_API yajl_gen_status yajl_gen_array_close(yajl_gen hand); 142 | 143 | /** access the null terminated generator buffer. If incrementally 144 | * outputing JSON, one should call yajl_gen_clear to clear the 145 | * buffer. This allows stream generation. */ 146 | YAJL_API yajl_gen_status yajl_gen_get_buf(yajl_gen hand, 147 | const unsigned char ** buf, 148 | unsigned int * len); 149 | 150 | /** clear yajl's output buffer, but maintain all internal generation 151 | * state. This function will not "reset" the generator state, and is 152 | * intended to enable incremental JSON outputing. */ 153 | YAJL_API void yajl_gen_clear(yajl_gen hand); 154 | 155 | #ifdef __cplusplus 156 | } 157 | #endif 158 | 159 | #endif 160 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include "api/yajl_parse.h" 34 | #include "yajl_lex.h" 35 | #include "yajl_parser.h" 36 | #include "yajl_alloc.h" 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | const char * 43 | yajl_status_to_string(yajl_status stat) 44 | { 45 | const char * statStr = "unknown"; 46 | switch (stat) { 47 | case yajl_status_ok: 48 | statStr = "ok, no error"; 49 | break; 50 | case yajl_status_client_canceled: 51 | statStr = "client canceled parse"; 52 | break; 53 | case yajl_status_insufficient_data: 54 | statStr = "eof was met before the parse could complete"; 55 | break; 56 | case yajl_status_error: 57 | statStr = "parse error"; 58 | break; 59 | } 60 | return statStr; 61 | } 62 | 63 | yajl_handle 64 | yajl_alloc(const yajl_callbacks * callbacks, 65 | const yajl_parser_config * config, 66 | const yajl_alloc_funcs * afs, 67 | void * ctx) 68 | { 69 | unsigned int allowComments = 0; 70 | unsigned int validateUTF8 = 0; 71 | yajl_handle hand = NULL; 72 | yajl_alloc_funcs afsBuffer; 73 | 74 | /* first order of business is to set up memory allocation routines */ 75 | if (afs != NULL) { 76 | if (afs->malloc == NULL || afs->realloc == NULL || afs->free == NULL) 77 | { 78 | return NULL; 79 | } 80 | } else { 81 | yajl_set_default_alloc_funcs(&afsBuffer); 82 | afs = &afsBuffer; 83 | } 84 | 85 | hand = (yajl_handle) YA_MALLOC(afs, sizeof(struct yajl_handle_t)); 86 | 87 | /* copy in pointers to allocation routines */ 88 | memcpy((void *) &(hand->alloc), (void *) afs, sizeof(yajl_alloc_funcs)); 89 | 90 | if (config != NULL) { 91 | allowComments = config->allowComments; 92 | validateUTF8 = config->checkUTF8; 93 | } 94 | 95 | hand->callbacks = callbacks; 96 | hand->ctx = ctx; 97 | hand->lexer = yajl_lex_alloc(&(hand->alloc), allowComments, validateUTF8); 98 | hand->bytesConsumed = 0; 99 | hand->decodeBuf = yajl_buf_alloc(&(hand->alloc)); 100 | yajl_bs_init(hand->stateStack, &(hand->alloc)); 101 | 102 | yajl_bs_push(hand->stateStack, yajl_state_start); 103 | 104 | return hand; 105 | } 106 | 107 | void 108 | yajl_free(yajl_handle handle) 109 | { 110 | yajl_bs_free(handle->stateStack); 111 | yajl_buf_free(handle->decodeBuf); 112 | yajl_lex_free(handle->lexer); 113 | YA_FREE(&(handle->alloc), handle); 114 | } 115 | 116 | yajl_status 117 | yajl_parse(yajl_handle hand, const unsigned char * jsonText, 118 | unsigned int jsonTextLen) 119 | { 120 | yajl_status status; 121 | status = yajl_do_parse(hand, jsonText, jsonTextLen); 122 | return status; 123 | } 124 | 125 | yajl_status 126 | yajl_parse_complete(yajl_handle hand) 127 | { 128 | /* The particular case we want to handle is a trailing number. 129 | * Further input consisting of digits could cause our interpretation 130 | * of the number to change (buffered "1" but "2" comes in). 131 | * A very simple approach to this is to inject whitespace to terminate 132 | * any number in the lex buffer. 133 | */ 134 | return yajl_parse(hand, (const unsigned char *)" ", 1); 135 | } 136 | 137 | unsigned char * 138 | yajl_get_error(yajl_handle hand, int verbose, 139 | const unsigned char * jsonText, unsigned int jsonTextLen) 140 | { 141 | return yajl_render_error_string(hand, jsonText, jsonTextLen, verbose); 142 | } 143 | 144 | unsigned int 145 | yajl_get_bytes_consumed(yajl_handle hand) 146 | { 147 | if (!hand) return 0; 148 | else return hand->bytesConsumed; 149 | } 150 | 151 | 152 | void 153 | yajl_free_error(yajl_handle hand, unsigned char * str) 154 | { 155 | /* use memory allocation functions if set */ 156 | YA_FREE(&(hand->alloc), str); 157 | } 158 | 159 | /* XXX: add utility routines to parse from file */ 160 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_alloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | * \file yajl_alloc.h 35 | * default memory allocation routines for yajl which use malloc/realloc and 36 | * free 37 | */ 38 | 39 | #include "yajl_alloc.h" 40 | #include 41 | 42 | static void * yajl_internal_malloc(void *ctx, unsigned int sz) 43 | { 44 | return malloc(sz); 45 | } 46 | 47 | static void * yajl_internal_realloc(void *ctx, void * previous, 48 | unsigned int sz) 49 | { 50 | return realloc(previous, sz); 51 | } 52 | 53 | static void yajl_internal_free(void *ctx, void * ptr) 54 | { 55 | free(ptr); 56 | } 57 | 58 | void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf) 59 | { 60 | yaf->malloc = yajl_internal_malloc; 61 | yaf->free = yajl_internal_free; 62 | yaf->realloc = yajl_internal_realloc; 63 | yaf->ctx = NULL; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_alloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | * \file yajl_alloc.h 35 | * default memory allocation routines for yajl which use malloc/realloc and 36 | * free 37 | */ 38 | 39 | #ifndef __YAJL_ALLOC_H__ 40 | #define __YAJL_ALLOC_H__ 41 | 42 | #include "api/yajl_common.h" 43 | 44 | #define YA_MALLOC(afs, sz) (afs)->malloc((afs)->ctx, (sz)) 45 | #define YA_FREE(afs, ptr) (afs)->free((afs)->ctx, (ptr)) 46 | #define YA_REALLOC(afs, ptr, sz) (afs)->realloc((afs)->ctx, (ptr), (sz)) 47 | 48 | void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_buf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include "yajl_buf.h" 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #define YAJL_BUF_INIT_SIZE 2048 40 | 41 | struct yajl_buf_t { 42 | unsigned int len; 43 | unsigned int used; 44 | unsigned char * data; 45 | yajl_alloc_funcs * alloc; 46 | }; 47 | 48 | static 49 | void yajl_buf_ensure_available(yajl_buf buf, unsigned int want) 50 | { 51 | unsigned int need; 52 | 53 | assert(buf != NULL); 54 | 55 | /* first call */ 56 | if (buf->data == NULL) { 57 | buf->len = YAJL_BUF_INIT_SIZE; 58 | buf->data = (unsigned char *) YA_MALLOC(buf->alloc, buf->len); 59 | buf->data[0] = 0; 60 | } 61 | 62 | need = buf->len; 63 | 64 | while (want >= (need - buf->used)) need <<= 1; 65 | 66 | if (need != buf->len) { 67 | buf->data = (unsigned char *) YA_REALLOC(buf->alloc, buf->data, need); 68 | buf->len = need; 69 | } 70 | } 71 | 72 | yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc) 73 | { 74 | yajl_buf b = YA_MALLOC(alloc, sizeof(struct yajl_buf_t)); 75 | memset((void *) b, 0, sizeof(struct yajl_buf_t)); 76 | b->alloc = alloc; 77 | return b; 78 | } 79 | 80 | void yajl_buf_free(yajl_buf buf) 81 | { 82 | assert(buf != NULL); 83 | if (buf->data) YA_FREE(buf->alloc, buf->data); 84 | YA_FREE(buf->alloc, buf); 85 | } 86 | 87 | void yajl_buf_append(yajl_buf buf, const void * data, unsigned int len) 88 | { 89 | yajl_buf_ensure_available(buf, len); 90 | if (len > 0) { 91 | assert(data != NULL); 92 | memcpy(buf->data + buf->used, data, len); 93 | buf->used += len; 94 | buf->data[buf->used] = 0; 95 | } 96 | } 97 | 98 | void yajl_buf_clear(yajl_buf buf) 99 | { 100 | buf->used = 0; 101 | if (buf->data) buf->data[buf->used] = 0; 102 | } 103 | 104 | const unsigned char * yajl_buf_data(yajl_buf buf) 105 | { 106 | return buf->data; 107 | } 108 | 109 | unsigned int yajl_buf_len(yajl_buf buf) 110 | { 111 | return buf->used; 112 | } 113 | 114 | void 115 | yajl_buf_truncate(yajl_buf buf, unsigned int len) 116 | { 117 | assert(len <= buf->used); 118 | buf->used = len; 119 | } 120 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_buf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __YAJL_BUF_H__ 34 | #define __YAJL_BUF_H__ 35 | 36 | #include "api/yajl_common.h" 37 | #include "yajl_alloc.h" 38 | 39 | /* 40 | * Implementation/performance notes. If this were moved to a header 41 | * only implementation using #define's where possible we might be 42 | * able to sqeeze a little performance out of the guy by killing function 43 | * call overhead. YMMV. 44 | */ 45 | 46 | /** 47 | * yajl_buf is a buffer with exponential growth. the buffer ensures that 48 | * you are always null padded. 49 | */ 50 | typedef struct yajl_buf_t * yajl_buf; 51 | 52 | /* allocate a new buffer */ 53 | yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc); 54 | 55 | /* free the buffer */ 56 | void yajl_buf_free(yajl_buf buf); 57 | 58 | /* append a number of bytes to the buffer */ 59 | void yajl_buf_append(yajl_buf buf, const void * data, unsigned int len); 60 | 61 | /* empty the buffer */ 62 | void yajl_buf_clear(yajl_buf buf); 63 | 64 | /* get a pointer to the beginning of the buffer */ 65 | const unsigned char * yajl_buf_data(yajl_buf buf); 66 | 67 | /* get the length of the buffer */ 68 | unsigned int yajl_buf_len(yajl_buf buf); 69 | 70 | /* truncate the buffer */ 71 | void yajl_buf_truncate(yajl_buf buf, unsigned int len); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_bytestack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | /* 34 | * A header only implementation of a simple stack of bytes, used in YAJL 35 | * to maintain parse state. 36 | */ 37 | 38 | #ifndef __YAJL_BYTESTACK_H__ 39 | #define __YAJL_BYTESTACK_H__ 40 | 41 | #include "api/yajl_common.h" 42 | 43 | #define YAJL_BS_INC 128 44 | 45 | typedef struct yajl_bytestack_t 46 | { 47 | unsigned char * stack; 48 | unsigned int size; 49 | unsigned int used; 50 | yajl_alloc_funcs * yaf; 51 | } yajl_bytestack; 52 | 53 | /* initialize a bytestack */ 54 | #define yajl_bs_init(obs, _yaf) { \ 55 | (obs).stack = NULL; \ 56 | (obs).size = 0; \ 57 | (obs).used = 0; \ 58 | (obs).yaf = (_yaf); \ 59 | } \ 60 | 61 | 62 | /* initialize a bytestack */ 63 | #define yajl_bs_free(obs) \ 64 | if ((obs).stack) (obs).yaf->free((obs).yaf->ctx, (obs).stack); 65 | 66 | #define yajl_bs_current(obs) \ 67 | (assert((obs).used > 0), (obs).stack[(obs).used - 1]) 68 | 69 | #define yajl_bs_push(obs, byte) { \ 70 | if (((obs).size - (obs).used) == 0) { \ 71 | (obs).size += YAJL_BS_INC; \ 72 | (obs).stack = (obs).yaf->realloc((obs).yaf->ctx,\ 73 | (void *) (obs).stack, (obs).size);\ 74 | } \ 75 | (obs).stack[((obs).used)++] = (byte); \ 76 | } 77 | 78 | /* removes the top item of the stack, returns nothing */ 79 | #define yajl_bs_pop(obs) { ((obs).used)--; } 80 | 81 | #define yajl_bs_set(obs, byte) \ 82 | (obs).stack[((obs).used) - 1] = (byte); 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_common.h: -------------------------------------------------------------------------------- 1 | api/yajl_common.h -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_encode.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include "yajl_encode.h" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | static void CharToHex(unsigned char c, char * hexBuf) 41 | { 42 | const char * hexchar = "0123456789ABCDEF"; 43 | hexBuf[0] = hexchar[c >> 4]; 44 | hexBuf[1] = hexchar[c & 0x0F]; 45 | } 46 | 47 | void 48 | yajl_string_encode(yajl_buf buf, const unsigned char * str, 49 | unsigned int len) 50 | { 51 | yajl_string_encode2((const yajl_print_t) &yajl_buf_append, buf, str, len); 52 | } 53 | 54 | void 55 | yajl_string_encode2(const yajl_print_t print, 56 | void * ctx, 57 | const unsigned char * str, 58 | unsigned int len) 59 | { 60 | unsigned int beg = 0; 61 | unsigned int end = 0; 62 | char hexBuf[7]; 63 | hexBuf[0] = '\\'; hexBuf[1] = 'u'; hexBuf[2] = '0'; hexBuf[3] = '0'; 64 | hexBuf[6] = 0; 65 | 66 | while (end < len) { 67 | const char * escaped = NULL; 68 | switch (str[end]) { 69 | case '\r': escaped = "\\r"; break; 70 | case '\n': escaped = "\\n"; break; 71 | case '\\': escaped = "\\\\"; break; 72 | /* case '/': escaped = "\\/"; break; */ 73 | case '"': escaped = "\\\""; break; 74 | case '\f': escaped = "\\f"; break; 75 | case '\b': escaped = "\\b"; break; 76 | case '\t': escaped = "\\t"; break; 77 | default: 78 | if ((unsigned char) str[end] < 32) { 79 | CharToHex(str[end], hexBuf + 4); 80 | escaped = hexBuf; 81 | } 82 | break; 83 | } 84 | if (escaped != NULL) { 85 | print(ctx, (const char *) (str + beg), end - beg); 86 | print(ctx, escaped, strlen(escaped)); 87 | beg = ++end; 88 | } else { 89 | ++end; 90 | } 91 | } 92 | print(ctx, (const char *) (str + beg), end - beg); 93 | } 94 | 95 | static void hexToDigit(unsigned int * val, const unsigned char * hex) 96 | { 97 | unsigned int i; 98 | for (i=0;i<4;i++) { 99 | unsigned char c = hex[i]; 100 | if (c >= 'A') c = (c & ~0x20) - 7; 101 | c -= '0'; 102 | assert(!(c & 0xF0)); 103 | *val = (*val << 4) | c; 104 | } 105 | } 106 | 107 | static void Utf32toUtf8(unsigned int codepoint, char * utf8Buf) 108 | { 109 | if (codepoint < 0x80) { 110 | utf8Buf[0] = (char) codepoint; 111 | utf8Buf[1] = 0; 112 | } else if (codepoint < 0x0800) { 113 | utf8Buf[0] = (char) ((codepoint >> 6) | 0xC0); 114 | utf8Buf[1] = (char) ((codepoint & 0x3F) | 0x80); 115 | utf8Buf[2] = 0; 116 | } else if (codepoint < 0x10000) { 117 | utf8Buf[0] = (char) ((codepoint >> 12) | 0xE0); 118 | utf8Buf[1] = (char) (((codepoint >> 6) & 0x3F) | 0x80); 119 | utf8Buf[2] = (char) ((codepoint & 0x3F) | 0x80); 120 | utf8Buf[3] = 0; 121 | } else if (codepoint < 0x200000) { 122 | utf8Buf[0] =(char)((codepoint >> 18) | 0xF0); 123 | utf8Buf[1] =(char)(((codepoint >> 12) & 0x3F) | 0x80); 124 | utf8Buf[2] =(char)(((codepoint >> 6) & 0x3F) | 0x80); 125 | utf8Buf[3] =(char)((codepoint & 0x3F) | 0x80); 126 | utf8Buf[4] = 0; 127 | } else { 128 | utf8Buf[0] = '?'; 129 | utf8Buf[1] = 0; 130 | } 131 | } 132 | 133 | void yajl_string_decode(yajl_buf buf, const unsigned char * str, 134 | unsigned int len) 135 | { 136 | unsigned int beg = 0; 137 | unsigned int end = 0; 138 | 139 | while (end < len) { 140 | if (str[end] == '\\') { 141 | char utf8Buf[5]; 142 | const char * unescaped = "?"; 143 | yajl_buf_append(buf, str + beg, end - beg); 144 | switch (str[++end]) { 145 | case 'r': unescaped = "\r"; break; 146 | case 'n': unescaped = "\n"; break; 147 | case '\\': unescaped = "\\"; break; 148 | case '/': unescaped = "/"; break; 149 | case '"': unescaped = "\""; break; 150 | case 'f': unescaped = "\f"; break; 151 | case 'b': unescaped = "\b"; break; 152 | case 't': unescaped = "\t"; break; 153 | case 'u': { 154 | unsigned int codepoint = 0; 155 | hexToDigit(&codepoint, str + ++end); 156 | end+=3; 157 | /* check if this is a surrogate */ 158 | if ((codepoint & 0xFC00) == 0xD800) { 159 | end++; 160 | if (str[end] == '\\' && str[end + 1] == 'u') { 161 | unsigned int surrogate = 0; 162 | hexToDigit(&surrogate, str + end + 2); 163 | codepoint = 164 | (((codepoint & 0x3F) << 10) | 165 | ((((codepoint >> 6) & 0xF) + 1) << 16) | 166 | (surrogate & 0x3FF)); 167 | end += 5; 168 | } else { 169 | unescaped = "?"; 170 | break; 171 | } 172 | } 173 | 174 | Utf32toUtf8(codepoint, utf8Buf); 175 | unescaped = utf8Buf; 176 | break; 177 | } 178 | default: 179 | assert("this should never happen" == NULL); 180 | } 181 | yajl_buf_append(buf, unescaped, strlen(unescaped)); 182 | beg = ++end; 183 | } else { 184 | end++; 185 | } 186 | } 187 | yajl_buf_append(buf, str + beg, end - beg); 188 | } 189 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_encode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __YAJL_ENCODE_H__ 34 | #define __YAJL_ENCODE_H__ 35 | 36 | #include "yajl_buf.h" 37 | #include "api/yajl_gen.h" 38 | 39 | void yajl_string_encode2(const yajl_print_t printer, 40 | void * ctx, 41 | const unsigned char * str, 42 | unsigned int length); 43 | 44 | void yajl_string_encode(yajl_buf buf, const unsigned char * str, 45 | unsigned int length); 46 | 47 | void yajl_string_decode(yajl_buf buf, const unsigned char * str, 48 | unsigned int length); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_gen.h: -------------------------------------------------------------------------------- 1 | api/yajl_gen.h -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_lex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __YAJL_LEX_H__ 34 | #define __YAJL_LEX_H__ 35 | 36 | #include "api/yajl_common.h" 37 | 38 | typedef enum { 39 | yajl_tok_bool, 40 | yajl_tok_colon, 41 | yajl_tok_comma, 42 | yajl_tok_eof, 43 | yajl_tok_error, 44 | yajl_tok_left_brace, 45 | yajl_tok_left_bracket, 46 | yajl_tok_null, 47 | yajl_tok_right_brace, 48 | yajl_tok_right_bracket, 49 | 50 | /* we differentiate between integers and doubles to allow the 51 | * parser to interpret the number without re-scanning */ 52 | yajl_tok_integer, 53 | yajl_tok_double, 54 | 55 | /* we differentiate between strings which require further processing, 56 | * and strings that do not */ 57 | yajl_tok_string, 58 | yajl_tok_string_with_escapes, 59 | 60 | /* comment tokens are not currently returned to the parser, ever */ 61 | yajl_tok_comment 62 | } yajl_tok; 63 | 64 | typedef struct yajl_lexer_t * yajl_lexer; 65 | 66 | yajl_lexer yajl_lex_alloc(yajl_alloc_funcs * alloc, 67 | unsigned int allowComments, 68 | unsigned int validateUTF8); 69 | 70 | void yajl_lex_free(yajl_lexer lexer); 71 | 72 | /** 73 | * run/continue a lex. "offset" is an input/output parameter. 74 | * It should be initialized to zero for a 75 | * new chunk of target text, and upon subsetquent calls with the same 76 | * target text should passed with the value of the previous invocation. 77 | * 78 | * the client may be interested in the value of offset when an error is 79 | * returned from the lexer. This allows the client to render useful 80 | n * error messages. 81 | * 82 | * When you pass the next chunk of data, context should be reinitialized 83 | * to zero. 84 | * 85 | * Finally, the output buffer is usually just a pointer into the jsonText, 86 | * however in cases where the entity being lexed spans multiple chunks, 87 | * the lexer will buffer the entity and the data returned will be 88 | * a pointer into that buffer. 89 | * 90 | * This behavior is abstracted from client code except for the performance 91 | * implications which require that the client choose a reasonable chunk 92 | * size to get adequate performance. 93 | */ 94 | yajl_tok yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText, 95 | unsigned int jsonTextLen, unsigned int * offset, 96 | const unsigned char ** outBuf, unsigned int * outLen); 97 | 98 | /** have a peek at the next token, but don't move the lexer forward */ 99 | yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText, 100 | unsigned int jsonTextLen, unsigned int offset); 101 | 102 | 103 | typedef enum { 104 | yajl_lex_e_ok = 0, 105 | yajl_lex_string_invalid_utf8, 106 | yajl_lex_string_invalid_escaped_char, 107 | yajl_lex_string_invalid_json_char, 108 | yajl_lex_string_invalid_hex_char, 109 | yajl_lex_invalid_char, 110 | yajl_lex_invalid_string, 111 | yajl_lex_missing_integer_after_decimal, 112 | yajl_lex_missing_integer_after_exponent, 113 | yajl_lex_missing_integer_after_minus, 114 | yajl_lex_unallowed_comment 115 | } yajl_lex_error; 116 | 117 | const char * yajl_lex_error_to_string(yajl_lex_error error); 118 | 119 | /** allows access to more specific information about the lexical 120 | * error when yajl_lex_lex returns yajl_tok_error. */ 121 | yajl_lex_error yajl_lex_get_error(yajl_lexer lexer); 122 | 123 | /** get the current offset into the most recently lexed json string. */ 124 | unsigned int yajl_lex_current_offset(yajl_lexer lexer); 125 | 126 | /** get the number of lines lexed by this lexer instance */ 127 | unsigned int yajl_lex_current_line(yajl_lexer lexer); 128 | 129 | /** get the number of chars lexed by this lexer instance since the last 130 | * \n or \r */ 131 | unsigned int yajl_lex_current_char(yajl_lexer lexer); 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_parse.h: -------------------------------------------------------------------------------- 1 | api/yajl_parse.h -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/extensions/json/yajl/yajl_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-2009, Lloyd Hilaiel. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __YAJL_PARSER_H__ 34 | #define __YAJL_PARSER_H__ 35 | 36 | #include "api/yajl_parse.h" 37 | #include "yajl_bytestack.h" 38 | #include "yajl_buf.h" 39 | 40 | 41 | typedef enum { 42 | yajl_state_start = 0, 43 | yajl_state_parse_complete, 44 | yajl_state_parse_error, 45 | yajl_state_lexical_error, 46 | yajl_state_map_start, 47 | yajl_state_map_sep, 48 | yajl_state_map_need_val, 49 | yajl_state_map_got_val, 50 | yajl_state_map_need_key, 51 | yajl_state_array_start, 52 | yajl_state_array_got_val, 53 | yajl_state_array_need_val 54 | } yajl_state; 55 | 56 | struct yajl_handle_t { 57 | const yajl_callbacks * callbacks; 58 | void * ctx; 59 | yajl_lexer lexer; 60 | const char * parseError; 61 | /* the number of bytes consumed from the last client buffer, 62 | * in the case of an error this will be an error offset, in the 63 | * case of an error this can be used as the error offset */ 64 | unsigned int bytesConsumed; 65 | /* temporary storage for decoded strings */ 66 | yajl_buf decodeBuf; 67 | /* a stack of states. access with yajl_state_XXX routines */ 68 | yajl_bytestack stateStack; 69 | /* memory allocation routines */ 70 | yajl_alloc_funcs alloc; 71 | }; 72 | 73 | yajl_status 74 | yajl_do_parse(yajl_handle handle, const unsigned char * jsonText, 75 | unsigned int jsonTextLen); 76 | 77 | unsigned char * 78 | yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText, 79 | unsigned int jsonTextLen, int verbose); 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lauxlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions for building Lua libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lauxlib_h 9 | #define lauxlib_h 10 | 11 | 12 | #include 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | 18 | #if defined(LUA_COMPAT_GETN) 19 | LUALIB_API int (luaL_getn) (lua_State *L, int t); 20 | LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); 21 | #else 22 | #define luaL_getn(L,i) ((int)lua_objlen(L, i)) 23 | #define luaL_setn(L,i,j) ((void)0) /* no op! */ 24 | #endif 25 | 26 | #if defined(LUA_COMPAT_OPENLIB) 27 | #define luaI_openlib luaL_openlib 28 | #endif 29 | 30 | 31 | /* extra error code for `luaL_load' */ 32 | #define LUA_ERRFILE (LUA_ERRERR+1) 33 | 34 | 35 | typedef struct luaL_Reg { 36 | const char *name; 37 | lua_CFunction func; 38 | } luaL_Reg; 39 | 40 | 41 | 42 | LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, 43 | const luaL_Reg *l, int nup); 44 | LUALIB_API void (luaL_register) (lua_State *L, const char *libname, 45 | const luaL_Reg *l); 46 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 47 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 48 | LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); 49 | LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); 50 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, 51 | size_t *l); 52 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, 53 | const char *def, size_t *l); 54 | LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); 55 | LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); 56 | 57 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); 58 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, 59 | lua_Integer def); 60 | 61 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 62 | LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); 63 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); 64 | 65 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); 66 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); 67 | 68 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); 69 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); 70 | 71 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, 72 | const char *const lst[]); 73 | 74 | LUALIB_API int (luaL_ref) (lua_State *L, int t); 75 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); 76 | 77 | LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); 78 | LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, 79 | const char *name); 80 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); 81 | 82 | LUALIB_API lua_State *(luaL_newstate) (void); 83 | 84 | 85 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, 86 | const char *r); 87 | 88 | LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, 89 | const char *fname, int szhint); 90 | 91 | 92 | 93 | 94 | /* 95 | ** =============================================================== 96 | ** some useful macros 97 | ** =============================================================== 98 | */ 99 | 100 | #define luaL_argcheck(L, cond,numarg,extramsg) \ 101 | ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) 102 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 103 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 104 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) 105 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) 106 | #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) 107 | #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) 108 | 109 | #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) 110 | 111 | #define luaL_dofile(L, fn) \ 112 | (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 113 | 114 | #define luaL_dostring(L, s) \ 115 | (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 116 | 117 | #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) 118 | 119 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) 120 | 121 | /* 122 | ** {====================================================== 123 | ** Generic Buffer manipulation 124 | ** ======================================================= 125 | */ 126 | 127 | 128 | 129 | typedef struct luaL_Buffer { 130 | char *p; /* current position in buffer */ 131 | int lvl; /* number of strings in the stack (level) */ 132 | lua_State *L; 133 | char buffer[LUAL_BUFFERSIZE]; 134 | } luaL_Buffer; 135 | 136 | #define luaL_addchar(B,c) \ 137 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ 138 | (*(B)->p++ = (char)(c))) 139 | 140 | /* compatibility only */ 141 | #define luaL_putchar(B,c) luaL_addchar(B,c) 142 | 143 | #define luaL_addsize(B,n) ((B)->p += (n)) 144 | 145 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); 146 | LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); 147 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); 148 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); 149 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); 150 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); 151 | 152 | 153 | /* }====================================================== */ 154 | 155 | 156 | /* compatibility with ref system */ 157 | 158 | /* pre-defined references */ 159 | #define LUA_NOREF (-2) 160 | #define LUA_REFNIL (-1) 161 | 162 | #define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ 163 | (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) 164 | 165 | #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) 166 | 167 | #define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) 168 | 169 | 170 | #define luaL_reg luaL_Reg 171 | 172 | #endif 173 | 174 | 175 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, 28 | OPR_CONCAT, 29 | OPR_NE, OPR_EQ, 30 | OPR_LT, OPR_LE, OPR_GT, OPR_GE, 31 | OPR_AND, OPR_OR, 32 | OPR_NOBINOPR 33 | } BinOpr; 34 | 35 | 36 | typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 37 | 38 | 39 | #define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) 40 | 41 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 42 | 43 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 44 | 45 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 46 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 47 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 48 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 49 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 50 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 51 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 52 | LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); 53 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 54 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 55 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 56 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 57 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 58 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 59 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 60 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 61 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 62 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 63 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 64 | LUAI_FUNC int luaK_jump (FuncState *fs); 65 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 66 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 67 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 68 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 69 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 70 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); 71 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 72 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); 73 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 24 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, 25 | const TValue *p2); 26 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, 27 | const TValue *p2); 28 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); 29 | LUAI_FUNC void luaG_errormsg (lua_State *L); 30 | LUAI_FUNC int luaG_checkcode (const Proto *pt); 31 | LUAI_FUNC int luaG_checkopenop (Instruction i); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) \ 17 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ 18 | luaD_growstack(L, n); \ 19 | else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); 20 | 21 | 22 | #define incr_top(L) {luaD_checkstack(L,1); L->top++;} 23 | 24 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 25 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 26 | 27 | #define saveci(L,p) ((char *)(p) - (char *)L->base_ci) 28 | #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) 29 | 30 | 31 | /* results from luaD_precall */ 32 | #define PCRLUA 0 /* initiated a call to a Lua function */ 33 | #define PCRC 1 /* did a call to a C function */ 34 | #define PCRYIELD 2 /* C funtion yielded */ 35 | 36 | 37 | /* type of protected functions, to be ran by `runprotected' */ 38 | typedef void (*Pfunc) (lua_State *L, void *ud); 39 | 40 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); 41 | LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 45 | ptrdiff_t oldtop, ptrdiff_t ef); 46 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 47 | LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); 48 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 49 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 50 | 51 | LUAI_FUNC void luaD_throw (lua_State *L, int errcode); 52 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 53 | 54 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** save precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #include 8 | 9 | #define ldump_c 10 | #define LUA_CORE 11 | 12 | #include "lua.h" 13 | 14 | #include "lobject.h" 15 | #include "lstate.h" 16 | #include "lundump.h" 17 | 18 | typedef struct { 19 | lua_State* L; 20 | lua_Writer writer; 21 | void* data; 22 | int strip; 23 | int status; 24 | } DumpState; 25 | 26 | #define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) 27 | #define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) 28 | 29 | static void DumpBlock(const void* b, size_t size, DumpState* D) 30 | { 31 | if (D->status==0) 32 | { 33 | lua_unlock(D->L); 34 | D->status=(*D->writer)(D->L,b,size,D->data); 35 | lua_lock(D->L); 36 | } 37 | } 38 | 39 | static void DumpChar(int y, DumpState* D) 40 | { 41 | char x=(char)y; 42 | DumpVar(x,D); 43 | } 44 | 45 | static void DumpInt(int x, DumpState* D) 46 | { 47 | DumpVar(x,D); 48 | } 49 | 50 | static void DumpNumber(lua_Number x, DumpState* D) 51 | { 52 | DumpVar(x,D); 53 | } 54 | 55 | static void DumpVector(const void* b, int n, size_t size, DumpState* D) 56 | { 57 | DumpInt(n,D); 58 | DumpMem(b,n,size,D); 59 | } 60 | 61 | static void DumpString(const TString* s, DumpState* D) 62 | { 63 | if (s==NULL || getstr(s)==NULL) 64 | { 65 | size_t size=0; 66 | DumpVar(size,D); 67 | } 68 | else 69 | { 70 | size_t size=s->tsv.len+1; /* include trailing '\0' */ 71 | DumpVar(size,D); 72 | DumpBlock(getstr(s),size,D); 73 | } 74 | } 75 | 76 | #define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) 77 | 78 | static void DumpFunction(const Proto* f, const TString* p, DumpState* D); 79 | 80 | static void DumpConstants(const Proto* f, DumpState* D) 81 | { 82 | int i,n=f->sizek; 83 | DumpInt(n,D); 84 | for (i=0; ik[i]; 87 | DumpChar(ttype(o),D); 88 | switch (ttype(o)) 89 | { 90 | case LUA_TNIL: 91 | break; 92 | case LUA_TBOOLEAN: 93 | DumpChar(bvalue(o),D); 94 | break; 95 | case LUA_TNUMBER: 96 | DumpNumber(nvalue(o),D); 97 | break; 98 | case LUA_TSTRING: 99 | DumpString(rawtsvalue(o),D); 100 | break; 101 | default: 102 | lua_assert(0); /* cannot happen */ 103 | break; 104 | } 105 | } 106 | n=f->sizep; 107 | DumpInt(n,D); 108 | for (i=0; ip[i],f->source,D); 109 | } 110 | 111 | static void DumpDebug(const Proto* f, DumpState* D) 112 | { 113 | int i,n; 114 | n= (D->strip) ? 0 : f->sizelineinfo; 115 | DumpVector(f->lineinfo,n,sizeof(int),D); 116 | n= (D->strip) ? 0 : f->sizelocvars; 117 | DumpInt(n,D); 118 | for (i=0; ilocvars[i].varname,D); 121 | DumpInt(f->locvars[i].startpc,D); 122 | DumpInt(f->locvars[i].endpc,D); 123 | } 124 | n= (D->strip) ? 0 : f->sizeupvalues; 125 | DumpInt(n,D); 126 | for (i=0; iupvalues[i],D); 127 | } 128 | 129 | static void DumpFunction(const Proto* f, const TString* p, DumpState* D) 130 | { 131 | DumpString((f->source==p || D->strip) ? NULL : f->source,D); 132 | DumpInt(f->linedefined,D); 133 | DumpInt(f->lastlinedefined,D); 134 | DumpChar(f->nups,D); 135 | DumpChar(f->numparams,D); 136 | DumpChar(f->is_vararg,D); 137 | DumpChar(f->maxstacksize,D); 138 | DumpCode(f,D); 139 | DumpConstants(f,D); 140 | DumpDebug(f,D); 141 | } 142 | 143 | static void DumpHeader(DumpState* D) 144 | { 145 | char h[LUAC_HEADERSIZE]; 146 | luaU_header(h); 147 | DumpBlock(h,LUAC_HEADERSIZE,D); 148 | } 149 | 150 | /* 151 | ** dump Lua function as precompiled chunk 152 | */ 153 | int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) 154 | { 155 | DumpState D; 156 | D.L=L; 157 | D.writer=w; 158 | D.data=data; 159 | D.strip=strip; 160 | D.status=0; 161 | DumpHeader(&D); 162 | DumpFunction(f,NULL,&D); 163 | return D.status; 164 | } 165 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lfunc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lfunc_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lfunc.h" 16 | #include "lgc.h" 17 | #include "lmem.h" 18 | #include "lobject.h" 19 | #include "lstate.h" 20 | 21 | 22 | 23 | Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) { 24 | Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); 25 | luaC_link(L, obj2gco(c), LUA_TFUNCTION); 26 | c->c.isC = 1; 27 | c->c.env = e; 28 | c->c.nupvalues = cast_byte(nelems); 29 | return c; 30 | } 31 | 32 | 33 | Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) { 34 | Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); 35 | luaC_link(L, obj2gco(c), LUA_TFUNCTION); 36 | c->l.isC = 0; 37 | c->l.env = e; 38 | c->l.nupvalues = cast_byte(nelems); 39 | while (nelems--) c->l.upvals[nelems] = NULL; 40 | return c; 41 | } 42 | 43 | 44 | UpVal *luaF_newupval (lua_State *L) { 45 | UpVal *uv = luaM_new(L, UpVal); 46 | luaC_link(L, obj2gco(uv), LUA_TUPVAL); 47 | uv->v = &uv->u.value; 48 | setnilvalue(uv->v); 49 | return uv; 50 | } 51 | 52 | 53 | UpVal *luaF_findupval (lua_State *L, StkId level) { 54 | global_State *g = G(L); 55 | GCObject **pp = &L->openupval; 56 | UpVal *p; 57 | UpVal *uv; 58 | while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { 59 | lua_assert(p->v != &p->u.value); 60 | if (p->v == level) { /* found a corresponding upvalue? */ 61 | if (isdead(g, obj2gco(p))) /* is it dead? */ 62 | changewhite(obj2gco(p)); /* ressurect it */ 63 | return p; 64 | } 65 | pp = &p->next; 66 | } 67 | uv = luaM_new(L, UpVal); /* not found: create a new one */ 68 | uv->tt = LUA_TUPVAL; 69 | uv->marked = luaC_white(g); 70 | uv->v = level; /* current value lives in the stack */ 71 | uv->next = *pp; /* chain it in the proper position */ 72 | *pp = obj2gco(uv); 73 | uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */ 74 | uv->u.l.next = g->uvhead.u.l.next; 75 | uv->u.l.next->u.l.prev = uv; 76 | g->uvhead.u.l.next = uv; 77 | lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); 78 | return uv; 79 | } 80 | 81 | 82 | static void unlinkupval (UpVal *uv) { 83 | lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv); 84 | uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */ 85 | uv->u.l.prev->u.l.next = uv->u.l.next; 86 | } 87 | 88 | 89 | void luaF_freeupval (lua_State *L, UpVal *uv) { 90 | if (uv->v != &uv->u.value) /* is it open? */ 91 | unlinkupval(uv); /* remove from open list */ 92 | luaM_free(L, uv); /* free upvalue */ 93 | } 94 | 95 | 96 | void luaF_close (lua_State *L, StkId level) { 97 | UpVal *uv; 98 | global_State *g = G(L); 99 | while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { 100 | GCObject *o = obj2gco(uv); 101 | lua_assert(!isblack(o) && uv->v != &uv->u.value); 102 | L->openupval = uv->next; /* remove from `open' list */ 103 | if (isdead(g, o)) 104 | luaF_freeupval(L, uv); /* free upvalue */ 105 | else { 106 | unlinkupval(uv); 107 | setobj(L, &uv->u.value, uv->v); 108 | uv->v = &uv->u.value; /* now current value lives here */ 109 | luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */ 110 | } 111 | } 112 | } 113 | 114 | 115 | Proto *luaF_newproto (lua_State *L) { 116 | Proto *f = luaM_new(L, Proto); 117 | luaC_link(L, obj2gco(f), LUA_TPROTO); 118 | f->k = NULL; 119 | f->sizek = 0; 120 | f->p = NULL; 121 | f->sizep = 0; 122 | f->code = NULL; 123 | f->sizecode = 0; 124 | f->sizelineinfo = 0; 125 | f->sizeupvalues = 0; 126 | f->nups = 0; 127 | f->upvalues = NULL; 128 | f->numparams = 0; 129 | f->is_vararg = 0; 130 | f->maxstacksize = 0; 131 | f->lineinfo = NULL; 132 | f->sizelocvars = 0; 133 | f->locvars = NULL; 134 | f->linedefined = 0; 135 | f->lastlinedefined = 0; 136 | f->source = NULL; 137 | return f; 138 | } 139 | 140 | 141 | void luaF_freeproto (lua_State *L, Proto *f) { 142 | luaM_freearray(L, f->code, f->sizecode, Instruction); 143 | luaM_freearray(L, f->p, f->sizep, Proto *); 144 | luaM_freearray(L, f->k, f->sizek, TValue); 145 | luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); 146 | luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); 147 | luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); 148 | luaM_free(L, f); 149 | } 150 | 151 | 152 | void luaF_freeclosure (lua_State *L, Closure *c) { 153 | int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) : 154 | sizeLclosure(c->l.nupvalues); 155 | luaM_freemem(L, c, size); 156 | } 157 | 158 | 159 | /* 160 | ** Look for n-th local variable at line `line' in function `func'. 161 | ** Returns NULL if not found. 162 | */ 163 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { 164 | int i; 165 | for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { 166 | if (pc < f->locvars[i].endpc) { /* is variable active? */ 167 | local_number--; 168 | if (local_number == 0) 169 | return getstr(f->locvars[i].varname); 170 | } 171 | } 172 | return NULL; /* not found */ 173 | } 174 | 175 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); 29 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 30 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 31 | int pc); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 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 | 13 | 14 | /* 15 | ** Possible states of the Garbage Collector 16 | */ 17 | #define GCSpause 0 18 | #define GCSpropagate 1 19 | #define GCSsweepstring 2 20 | #define GCSsweep 3 21 | #define GCSfinalize 4 22 | 23 | 24 | /* 25 | ** some userful bit tricks 26 | */ 27 | #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) 28 | #define setbits(x,m) ((x) |= (m)) 29 | #define testbits(x,m) ((x) & (m)) 30 | #define bitmask(b) (1<<(b)) 31 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 32 | #define l_setbit(x,b) setbits(x, bitmask(b)) 33 | #define resetbit(x,b) resetbits(x, bitmask(b)) 34 | #define testbit(x,b) testbits(x, bitmask(b)) 35 | #define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) 36 | #define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) 37 | #define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) 38 | 39 | 40 | 41 | /* 42 | ** Layout for bit use in `marked' field: 43 | ** bit 0 - object is white (type 0) 44 | ** bit 1 - object is white (type 1) 45 | ** bit 2 - object is black 46 | ** bit 3 - for userdata: has been finalized 47 | ** bit 3 - for tables: has weak keys 48 | ** bit 4 - for tables: has weak values 49 | ** bit 5 - object is fixed (should not be collected) 50 | ** bit 6 - object is "super" fixed (only the main thread) 51 | */ 52 | 53 | 54 | #define WHITE0BIT 0 55 | #define WHITE1BIT 1 56 | #define BLACKBIT 2 57 | #define FINALIZEDBIT 3 58 | #define KEYWEAKBIT 3 59 | #define VALUEWEAKBIT 4 60 | #define FIXEDBIT 5 61 | #define SFIXEDBIT 6 62 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 63 | 64 | 65 | #define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) 66 | #define isblack(x) testbit((x)->gch.marked, BLACKBIT) 67 | #define isgray(x) (!isblack(x) && !iswhite(x)) 68 | 69 | #define otherwhite(g) (g->currentwhite ^ WHITEBITS) 70 | #define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) 71 | 72 | #define changewhite(x) ((x)->gch.marked ^= WHITEBITS) 73 | #define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) 74 | 75 | #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) 76 | 77 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) 78 | 79 | 80 | #define luaC_checkGC(L) { \ 81 | condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ 82 | if (G(L)->totalbytes >= G(L)->GCthreshold) \ 83 | luaC_step(L); } 84 | 85 | 86 | #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ 87 | luaC_barrierf(L,obj2gco(p),gcvalue(v)); } 88 | 89 | #define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ 90 | luaC_barrierback(L,t); } 91 | 92 | #define luaC_objbarrier(L,p,o) \ 93 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ 94 | luaC_barrierf(L,obj2gco(p),obj2gco(o)); } 95 | 96 | #define luaC_objbarriert(L,t,o) \ 97 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } 98 | 99 | LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); 100 | LUAI_FUNC void luaC_callGCTM (lua_State *L); 101 | LUAI_FUNC void luaC_freeall (lua_State *L); 102 | LUAI_FUNC void luaC_step (lua_State *L); 103 | LUAI_FUNC void luaC_fullgc (lua_State *L); 104 | LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); 105 | LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); 106 | LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); 107 | LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); 108 | 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Initialization of libraries for lua.c 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | #include "lua.h" 12 | 13 | #include "lualib.h" 14 | #include "lauxlib.h" 15 | 16 | 17 | static const luaL_Reg lualibs[] = { 18 | {"", luaopen_base}, 19 | {LUA_LOADLIBNAME, luaopen_package}, 20 | {LUA_TABLIBNAME, luaopen_table}, 21 | {LUA_IOLIBNAME, luaopen_io}, 22 | {LUA_OSLIBNAME, luaopen_os}, 23 | {LUA_STRLIBNAME, luaopen_string}, 24 | {LUA_MATHLIBNAME, luaopen_math}, 25 | {LUA_DBLIBNAME, luaopen_debug}, 26 | {NULL, NULL} 27 | }; 28 | 29 | 30 | LUALIB_API void luaL_openlibs (lua_State *L) { 31 | const luaL_Reg *lib = lualibs; 32 | for (; lib->func; lib++) { 33 | lua_pushcfunction(L, lib->func); 34 | lua_pushstring(L, lib->name); 35 | lua_call(L, 1, 0); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | /* maximum length of a reserved word */ 17 | #define TOKEN_LEN (sizeof("function")/sizeof(char)) 18 | 19 | 20 | /* 21 | * WARNING: if you change the order of this enumeration, 22 | * grep "ORDER RESERVED" 23 | */ 24 | enum RESERVED { 25 | /* terminal symbols denoted by reserved words */ 26 | TK_AND = FIRST_RESERVED, TK_BREAK, 27 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 28 | TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 29 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 30 | /* other terminal symbols */ 31 | TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, 32 | TK_NAME, TK_STRING, TK_EOS 33 | }; 34 | 35 | /* number of reserved words */ 36 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 37 | 38 | 39 | /* array with token `names' */ 40 | LUAI_DATA const char *const luaX_tokens []; 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | TString *ts; 46 | } SemInfo; /* semantics information */ 47 | 48 | 49 | typedef struct Token { 50 | int token; 51 | SemInfo seminfo; 52 | } Token; 53 | 54 | 55 | typedef struct LexState { 56 | int current; /* current character (charint) */ 57 | int linenumber; /* input line counter */ 58 | int lastline; /* line of last token `consumed' */ 59 | Token t; /* current token */ 60 | Token lookahead; /* look ahead token */ 61 | struct FuncState *fs; /* `FuncState' is private to the parser */ 62 | struct lua_State *L; 63 | ZIO *z; /* input stream */ 64 | Mbuffer *buff; /* buffer for tokens */ 65 | TString *source; /* current source name */ 66 | char decpoint; /* locale decimal point */ 67 | } LexState; 68 | 69 | 70 | LUAI_FUNC void luaX_init (lua_State *L); 71 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 72 | TString *source); 73 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 74 | LUAI_FUNC void luaX_next (LexState *ls); 75 | LUAI_FUNC void luaX_lookahead (LexState *ls); 76 | LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); 77 | LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); 78 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 79 | 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/llimits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Limits, basic types, and some other `installation-dependent' definitions 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llimits_h 8 | #define llimits_h 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | #include "lua.h" 16 | 17 | 18 | typedef LUAI_UINT32 lu_int32; 19 | 20 | typedef LUAI_UMEM lu_mem; 21 | 22 | typedef LUAI_MEM l_mem; 23 | 24 | 25 | 26 | /* chars used as small naturals (so that `char' is reserved for characters) */ 27 | typedef unsigned char lu_byte; 28 | 29 | 30 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) 31 | 32 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) 33 | 34 | 35 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ 36 | 37 | /* 38 | ** conversion of pointer to integer 39 | ** this is for hashing only; there is no problem if the integer 40 | ** cannot hold the whole pointer value 41 | */ 42 | #define IntPoint(p) ((unsigned int)(lu_mem)(p)) 43 | 44 | 45 | 46 | /* type to ensure maximum alignment */ 47 | typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; 48 | 49 | 50 | /* result of a `usual argument conversion' over lua_Number */ 51 | typedef LUAI_UACNUMBER l_uacNumber; 52 | 53 | 54 | /* internal assertions for in-house debugging */ 55 | #ifdef lua_assert 56 | 57 | #define check_exp(c,e) (lua_assert(c), (e)) 58 | #define api_check(l,e) lua_assert(e) 59 | 60 | #else 61 | 62 | #define lua_assert(c) ((void)0) 63 | #define check_exp(c,e) (e) 64 | #define api_check luai_apicheck 65 | 66 | #endif 67 | 68 | 69 | #ifndef UNUSED 70 | #define UNUSED(x) ((void)(x)) /* to avoid warnings */ 71 | #endif 72 | 73 | 74 | #ifndef cast 75 | #define cast(t, exp) ((t)(exp)) 76 | #endif 77 | 78 | #define cast_byte(i) cast(lu_byte, (i)) 79 | #define cast_num(i) cast(lua_Number, (i)) 80 | #define cast_int(i) cast(int, (i)) 81 | 82 | 83 | 84 | /* 85 | ** type for virtual-machine instructions 86 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 87 | */ 88 | typedef lu_int32 Instruction; 89 | 90 | 91 | 92 | /* maximum stack for a Lua function */ 93 | #define MAXSTACK 250 94 | 95 | 96 | 97 | /* minimum size for the string table (must be power of 2) */ 98 | #ifndef MINSTRTABSIZE 99 | #define MINSTRTABSIZE 32 100 | #endif 101 | 102 | 103 | /* minimum size for string buffer */ 104 | #ifndef LUA_MINBUFFER 105 | #define LUA_MINBUFFER 32 106 | #endif 107 | 108 | 109 | #ifndef lua_lock 110 | #define lua_lock(L) ((void) 0) 111 | #define lua_unlock(L) ((void) 0) 112 | #endif 113 | 114 | #ifndef luai_threadyield 115 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} 116 | #endif 117 | 118 | 119 | /* 120 | ** macro to control inclusion of some hard tests on stack reallocation 121 | */ 122 | #ifndef HARDSTACKTESTS 123 | #define condhardstacktests(x) ((void)0) 124 | #else 125 | #define condhardstacktests(x) x 126 | #endif 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lmathlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Standard mathematical library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | #define lmathlib_c 12 | #define LUA_LIB 13 | 14 | #include "lua.h" 15 | 16 | #include "lauxlib.h" 17 | #include "lualib.h" 18 | 19 | 20 | #undef PI 21 | #define PI (3.14159265358979323846) 22 | #define RADIANS_PER_DEGREE (PI/180.0) 23 | 24 | 25 | 26 | static int math_abs (lua_State *L) { 27 | lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); 28 | return 1; 29 | } 30 | 31 | static int math_sin (lua_State *L) { 32 | lua_pushnumber(L, sin(luaL_checknumber(L, 1))); 33 | return 1; 34 | } 35 | 36 | static int math_sinh (lua_State *L) { 37 | lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); 38 | return 1; 39 | } 40 | 41 | static int math_cos (lua_State *L) { 42 | lua_pushnumber(L, cos(luaL_checknumber(L, 1))); 43 | return 1; 44 | } 45 | 46 | static int math_cosh (lua_State *L) { 47 | lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); 48 | return 1; 49 | } 50 | 51 | static int math_tan (lua_State *L) { 52 | lua_pushnumber(L, tan(luaL_checknumber(L, 1))); 53 | return 1; 54 | } 55 | 56 | static int math_tanh (lua_State *L) { 57 | lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); 58 | return 1; 59 | } 60 | 61 | static int math_asin (lua_State *L) { 62 | lua_pushnumber(L, asin(luaL_checknumber(L, 1))); 63 | return 1; 64 | } 65 | 66 | static int math_acos (lua_State *L) { 67 | lua_pushnumber(L, acos(luaL_checknumber(L, 1))); 68 | return 1; 69 | } 70 | 71 | static int math_atan (lua_State *L) { 72 | lua_pushnumber(L, atan(luaL_checknumber(L, 1))); 73 | return 1; 74 | } 75 | 76 | static int math_atan2 (lua_State *L) { 77 | lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); 78 | return 1; 79 | } 80 | 81 | static int math_ceil (lua_State *L) { 82 | lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); 83 | return 1; 84 | } 85 | 86 | static int math_floor (lua_State *L) { 87 | lua_pushnumber(L, floor(luaL_checknumber(L, 1))); 88 | return 1; 89 | } 90 | 91 | static int math_fmod (lua_State *L) { 92 | lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); 93 | return 1; 94 | } 95 | 96 | static int math_modf (lua_State *L) { 97 | double ip; 98 | double fp = modf(luaL_checknumber(L, 1), &ip); 99 | lua_pushnumber(L, ip); 100 | lua_pushnumber(L, fp); 101 | return 2; 102 | } 103 | 104 | static int math_sqrt (lua_State *L) { 105 | lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); 106 | return 1; 107 | } 108 | 109 | static int math_pow (lua_State *L) { 110 | lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); 111 | return 1; 112 | } 113 | 114 | static int math_log (lua_State *L) { 115 | lua_pushnumber(L, log(luaL_checknumber(L, 1))); 116 | return 1; 117 | } 118 | 119 | static int math_log10 (lua_State *L) { 120 | lua_pushnumber(L, log10(luaL_checknumber(L, 1))); 121 | return 1; 122 | } 123 | 124 | static int math_exp (lua_State *L) { 125 | lua_pushnumber(L, exp(luaL_checknumber(L, 1))); 126 | return 1; 127 | } 128 | 129 | static int math_deg (lua_State *L) { 130 | lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); 131 | return 1; 132 | } 133 | 134 | static int math_rad (lua_State *L) { 135 | lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); 136 | return 1; 137 | } 138 | 139 | static int math_frexp (lua_State *L) { 140 | int e; 141 | lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); 142 | lua_pushinteger(L, e); 143 | return 2; 144 | } 145 | 146 | static int math_ldexp (lua_State *L) { 147 | lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); 148 | return 1; 149 | } 150 | 151 | 152 | 153 | static int math_min (lua_State *L) { 154 | int n = lua_gettop(L); /* number of arguments */ 155 | lua_Number dmin = luaL_checknumber(L, 1); 156 | int i; 157 | for (i=2; i<=n; i++) { 158 | lua_Number d = luaL_checknumber(L, i); 159 | if (d < dmin) 160 | dmin = d; 161 | } 162 | lua_pushnumber(L, dmin); 163 | return 1; 164 | } 165 | 166 | 167 | static int math_max (lua_State *L) { 168 | int n = lua_gettop(L); /* number of arguments */ 169 | lua_Number dmax = luaL_checknumber(L, 1); 170 | int i; 171 | for (i=2; i<=n; i++) { 172 | lua_Number d = luaL_checknumber(L, i); 173 | if (d > dmax) 174 | dmax = d; 175 | } 176 | lua_pushnumber(L, dmax); 177 | return 1; 178 | } 179 | 180 | 181 | static int math_random (lua_State *L) { 182 | /* the `%' avoids the (rare) case of r==1, and is needed also because on 183 | some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */ 184 | lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX; 185 | switch (lua_gettop(L)) { /* check number of arguments */ 186 | case 0: { /* no arguments */ 187 | lua_pushnumber(L, r); /* Number between 0 and 1 */ 188 | break; 189 | } 190 | case 1: { /* only upper limit */ 191 | int u = luaL_checkint(L, 1); 192 | luaL_argcheck(L, 1<=u, 1, "interval is empty"); 193 | lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */ 194 | break; 195 | } 196 | case 2: { /* lower and upper limits */ 197 | int l = luaL_checkint(L, 1); 198 | int u = luaL_checkint(L, 2); 199 | luaL_argcheck(L, l<=u, 2, "interval is empty"); 200 | lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */ 201 | break; 202 | } 203 | default: return luaL_error(L, "wrong number of arguments"); 204 | } 205 | return 1; 206 | } 207 | 208 | 209 | static int math_randomseed (lua_State *L) { 210 | srand(luaL_checkint(L, 1)); 211 | return 0; 212 | } 213 | 214 | 215 | static const luaL_Reg mathlib[] = { 216 | {"abs", math_abs}, 217 | {"acos", math_acos}, 218 | {"asin", math_asin}, 219 | {"atan2", math_atan2}, 220 | {"atan", math_atan}, 221 | {"ceil", math_ceil}, 222 | {"cosh", math_cosh}, 223 | {"cos", math_cos}, 224 | {"deg", math_deg}, 225 | {"exp", math_exp}, 226 | {"floor", math_floor}, 227 | {"fmod", math_fmod}, 228 | {"frexp", math_frexp}, 229 | {"ldexp", math_ldexp}, 230 | {"log10", math_log10}, 231 | {"log", math_log}, 232 | {"max", math_max}, 233 | {"min", math_min}, 234 | {"modf", math_modf}, 235 | {"pow", math_pow}, 236 | {"rad", math_rad}, 237 | {"random", math_random}, 238 | {"randomseed", math_randomseed}, 239 | {"sinh", math_sinh}, 240 | {"sin", math_sin}, 241 | {"sqrt", math_sqrt}, 242 | {"tanh", math_tanh}, 243 | {"tan", math_tan}, 244 | {NULL, NULL} 245 | }; 246 | 247 | 248 | /* 249 | ** Open math library 250 | */ 251 | LUALIB_API int luaopen_math (lua_State *L) { 252 | luaL_register(L, LUA_MATHLIBNAME, mathlib); 253 | lua_pushnumber(L, PI); 254 | lua_setfield(L, -2, "pi"); 255 | lua_pushnumber(L, HUGE_VAL); 256 | lua_setfield(L, -2, "huge"); 257 | #if defined(LUA_COMPAT_MOD) 258 | lua_getfield(L, -1, "fmod"); 259 | lua_setfield(L, -2, "mod"); 260 | #endif 261 | return 1; 262 | } 263 | 264 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lmem_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "ldebug.h" 16 | #include "ldo.h" 17 | #include "lmem.h" 18 | #include "lobject.h" 19 | #include "lstate.h" 20 | 21 | 22 | 23 | /* 24 | ** About the realloc function: 25 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 26 | ** (`osize' is the old size, `nsize' is the new size) 27 | ** 28 | ** Lua ensures that (ptr == NULL) iff (osize == 0). 29 | ** 30 | ** * frealloc(ud, NULL, 0, x) creates a new block of size `x' 31 | ** 32 | ** * frealloc(ud, p, x, 0) frees the block `p' 33 | ** (in this specific case, frealloc must return NULL). 34 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 35 | ** (which is equivalent to free(NULL) in ANSI C) 36 | ** 37 | ** frealloc returns NULL if it cannot create or reallocate the area 38 | ** (any reallocation to an equal or smaller size cannot fail!) 39 | */ 40 | 41 | 42 | 43 | #define MINSIZEARRAY 4 44 | 45 | 46 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 47 | int limit, const char *errormsg) { 48 | void *newblock; 49 | int newsize; 50 | if (*size >= limit/2) { /* cannot double it? */ 51 | if (*size >= limit) /* cannot grow even a little? */ 52 | luaG_runerror(L, errormsg); 53 | newsize = limit; /* still have at least one free place */ 54 | } 55 | else { 56 | newsize = (*size)*2; 57 | if (newsize < MINSIZEARRAY) 58 | newsize = MINSIZEARRAY; /* minimum size */ 59 | } 60 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 61 | *size = newsize; /* update only when everything else is OK */ 62 | return newblock; 63 | } 64 | 65 | 66 | void *luaM_toobig (lua_State *L) { 67 | luaG_runerror(L, "memory allocation error: block too big"); 68 | return NULL; /* to avoid warnings */ 69 | } 70 | 71 | 72 | 73 | /* 74 | ** generic allocation routine. 75 | */ 76 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 77 | global_State *g = G(L); 78 | lua_assert((osize == 0) == (block == NULL)); 79 | block = (*g->frealloc)(g->ud, block, osize, nsize); 80 | if (block == NULL && nsize > 0) 81 | luaD_throw(L, LUA_ERRMEM); 82 | lua_assert((nsize == 0) == (block == NULL)); 83 | g->totalbytes = (g->totalbytes - osize) + nsize; 84 | return block; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | #define MEMERRMSG "not enough memory" 17 | 18 | 19 | #define luaM_reallocv(L,b,on,n,e) \ 20 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ 21 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ 22 | luaM_toobig(L)) 23 | 24 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 25 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 26 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 27 | 28 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) 29 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 30 | #define luaM_newvector(L,n,t) \ 31 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 32 | 33 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 34 | if ((nelems)+1 > (size)) \ 35 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 36 | 37 | #define luaM_reallocvector(L, v,oldn,n,t) \ 38 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 39 | 40 | 41 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 42 | size_t size); 43 | LUAI_FUNC void *luaM_toobig (lua_State *L); 44 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 45 | size_t size_elem, int limit, 46 | const char *errormsg); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lobject.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Some generic functions over Lua objects 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define lobject_c 14 | #define LUA_CORE 15 | 16 | #include "lua.h" 17 | 18 | #include "ldo.h" 19 | #include "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | #include "lstring.h" 23 | #include "lvm.h" 24 | 25 | 26 | 27 | const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; 28 | 29 | 30 | /* 31 | ** converts an integer to a "floating point byte", represented as 32 | ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if 33 | ** eeeee != 0 and (xxx) otherwise. 34 | */ 35 | int luaO_int2fb (unsigned int x) { 36 | int e = 0; /* expoent */ 37 | while (x >= 16) { 38 | x = (x+1) >> 1; 39 | e++; 40 | } 41 | if (x < 8) return x; 42 | else return ((e+1) << 3) | (cast_int(x) - 8); 43 | } 44 | 45 | 46 | /* converts back */ 47 | int luaO_fb2int (int x) { 48 | int e = (x >> 3) & 31; 49 | if (e == 0) return x; 50 | else return ((x & 7)+8) << (e - 1); 51 | } 52 | 53 | 54 | int luaO_log2 (unsigned int x) { 55 | static const lu_byte log_2[256] = { 56 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 57 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 58 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 59 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 60 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 61 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 62 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 63 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 64 | }; 65 | int l = -1; 66 | while (x >= 256) { l += 8; x >>= 8; } 67 | return l + log_2[x]; 68 | 69 | } 70 | 71 | 72 | int luaO_rawequalObj (const TValue *t1, const TValue *t2) { 73 | if (ttype(t1) != ttype(t2)) return 0; 74 | else switch (ttype(t1)) { 75 | case LUA_TNIL: 76 | return 1; 77 | case LUA_TNUMBER: 78 | return luai_numeq(nvalue(t1), nvalue(t2)); 79 | case LUA_TBOOLEAN: 80 | return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ 81 | case LUA_TLIGHTUSERDATA: 82 | return pvalue(t1) == pvalue(t2); 83 | default: 84 | lua_assert(iscollectable(t1)); 85 | return gcvalue(t1) == gcvalue(t2); 86 | } 87 | } 88 | 89 | 90 | int luaO_str2d (const char *s, lua_Number *result) { 91 | char *endptr; 92 | *result = lua_str2number(s, &endptr); 93 | if (endptr == s) return 0; /* conversion failed */ 94 | if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ 95 | *result = cast_num(strtoul(s, &endptr, 16)); 96 | if (*endptr == '\0') return 1; /* most common case */ 97 | while (isspace(cast(unsigned char, *endptr))) endptr++; 98 | if (*endptr != '\0') return 0; /* invalid trailing characters? */ 99 | return 1; 100 | } 101 | 102 | 103 | 104 | static void pushstr (lua_State *L, const char *str) { 105 | setsvalue2s(L, L->top, luaS_new(L, str)); 106 | incr_top(L); 107 | } 108 | 109 | 110 | /* this function handles only `%d', `%c', %f, %p, and `%s' formats */ 111 | const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { 112 | int n = 1; 113 | pushstr(L, ""); 114 | for (;;) { 115 | const char *e = strchr(fmt, '%'); 116 | if (e == NULL) break; 117 | setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); 118 | incr_top(L); 119 | switch (*(e+1)) { 120 | case 's': { 121 | const char *s = va_arg(argp, char *); 122 | if (s == NULL) s = "(null)"; 123 | pushstr(L, s); 124 | break; 125 | } 126 | case 'c': { 127 | char buff[2]; 128 | buff[0] = cast(char, va_arg(argp, int)); 129 | buff[1] = '\0'; 130 | pushstr(L, buff); 131 | break; 132 | } 133 | case 'd': { 134 | setnvalue(L->top, cast_num(va_arg(argp, int))); 135 | incr_top(L); 136 | break; 137 | } 138 | case 'f': { 139 | setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); 140 | incr_top(L); 141 | break; 142 | } 143 | case 'p': { 144 | char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */ 145 | sprintf(buff, "%p", va_arg(argp, void *)); 146 | pushstr(L, buff); 147 | break; 148 | } 149 | case '%': { 150 | pushstr(L, "%"); 151 | break; 152 | } 153 | default: { 154 | char buff[3]; 155 | buff[0] = '%'; 156 | buff[1] = *(e+1); 157 | buff[2] = '\0'; 158 | pushstr(L, buff); 159 | break; 160 | } 161 | } 162 | n += 2; 163 | fmt = e+2; 164 | } 165 | pushstr(L, fmt); 166 | luaV_concat(L, n+1, cast_int(L->top - L->base) - 1); 167 | L->top -= n; 168 | return svalue(L->top - 1); 169 | } 170 | 171 | 172 | const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { 173 | const char *msg; 174 | va_list argp; 175 | va_start(argp, fmt); 176 | msg = luaO_pushvfstring(L, fmt, argp); 177 | va_end(argp); 178 | return msg; 179 | } 180 | 181 | 182 | void luaO_chunkid (char *out, const char *source, size_t bufflen) { 183 | if (*source == '=') { 184 | strncpy(out, source+1, bufflen); /* remove first char */ 185 | out[bufflen-1] = '\0'; /* ensures null termination */ 186 | } 187 | else { /* out = "source", or "...source" */ 188 | if (*source == '@') { 189 | size_t l; 190 | source++; /* skip the `@' */ 191 | bufflen -= sizeof(" '...' "); 192 | l = strlen(source); 193 | strcpy(out, ""); 194 | if (l > bufflen) { 195 | source += (l-bufflen); /* get last part of file name */ 196 | strcat(out, "..."); 197 | } 198 | strcat(out, source); 199 | } 200 | else { /* out = [string "string"] */ 201 | size_t len = strcspn(source, "\n\r"); /* stop at first newline */ 202 | bufflen -= sizeof(" [string \"...\"] "); 203 | if (len > bufflen) len = bufflen; 204 | strcpy(out, "[string \""); 205 | if (source[len] != '\0') { /* must truncate? */ 206 | strncat(out, source, len); 207 | strcat(out, "..."); 208 | } 209 | else 210 | strcat(out, source); 211 | strcat(out, "\"]"); 212 | } 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** See Copyright Notice in lua.h 4 | */ 5 | 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | 11 | #include "lopcodes.h" 12 | 13 | 14 | /* ORDER OP */ 15 | 16 | const char *const luaP_opnames[NUM_OPCODES+1] = { 17 | "MOVE", 18 | "LOADK", 19 | "LOADBOOL", 20 | "LOADNIL", 21 | "GETUPVAL", 22 | "GETGLOBAL", 23 | "GETTABLE", 24 | "SETGLOBAL", 25 | "SETUPVAL", 26 | "SETTABLE", 27 | "NEWTABLE", 28 | "SELF", 29 | "ADD", 30 | "SUB", 31 | "MUL", 32 | "DIV", 33 | "MOD", 34 | "POW", 35 | "UNM", 36 | "NOT", 37 | "LEN", 38 | "CONCAT", 39 | "JMP", 40 | "EQ", 41 | "LT", 42 | "LE", 43 | "TEST", 44 | "TESTSET", 45 | "CALL", 46 | "TAILCALL", 47 | "RETURN", 48 | "FORLOOP", 49 | "FORPREP", 50 | "TFORLOOP", 51 | "SETLIST", 52 | "CLOSE", 53 | "CLOSURE", 54 | "VARARG", 55 | NULL 56 | }; 57 | 58 | 59 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) 60 | 61 | const lu_byte luaP_opmodes[NUM_OPCODES] = { 62 | /* T A B C mode opcode */ 63 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 64 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 65 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 66 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ 67 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 68 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ 69 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 70 | ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ 71 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ 72 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ 73 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ 74 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ 75 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ 76 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ 77 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ 78 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ 79 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ 80 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ 81 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ 82 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ 83 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ 84 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ 85 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ 86 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ 87 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ 88 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ 89 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ 90 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ 91 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ 92 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ 93 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ 94 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ 95 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ 96 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ 97 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ 98 | ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ 99 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 100 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 101 | }; 102 | 103 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/loslib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $ 3 | ** Standard Operating System library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define loslib_c 15 | #define LUA_LIB 16 | 17 | #include "lua.h" 18 | 19 | #include "lauxlib.h" 20 | #include "lualib.h" 21 | 22 | 23 | static int os_pushresult (lua_State *L, int i, const char *filename) { 24 | int en = errno; /* calls to Lua API may change this value */ 25 | if (i) { 26 | lua_pushboolean(L, 1); 27 | return 1; 28 | } 29 | else { 30 | lua_pushnil(L); 31 | lua_pushfstring(L, "%s: %s", filename, strerror(en)); 32 | lua_pushinteger(L, en); 33 | return 3; 34 | } 35 | } 36 | 37 | 38 | static int os_execute (lua_State *L) { 39 | lua_pushinteger(L, system(luaL_optstring(L, 1, NULL))); 40 | return 1; 41 | } 42 | 43 | 44 | static int os_remove (lua_State *L) { 45 | const char *filename = luaL_checkstring(L, 1); 46 | return os_pushresult(L, remove(filename) == 0, filename); 47 | } 48 | 49 | 50 | static int os_rename (lua_State *L) { 51 | const char *fromname = luaL_checkstring(L, 1); 52 | const char *toname = luaL_checkstring(L, 2); 53 | return os_pushresult(L, rename(fromname, toname) == 0, fromname); 54 | } 55 | 56 | 57 | static int os_tmpname (lua_State *L) { 58 | char buff[LUA_TMPNAMBUFSIZE]; 59 | int err; 60 | lua_tmpnam(buff, err); 61 | if (err) 62 | return luaL_error(L, "unable to generate a unique filename"); 63 | lua_pushstring(L, buff); 64 | return 1; 65 | } 66 | 67 | 68 | static int os_getenv (lua_State *L) { 69 | lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ 70 | return 1; 71 | } 72 | 73 | 74 | static int os_clock (lua_State *L) { 75 | lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); 76 | return 1; 77 | } 78 | 79 | 80 | /* 81 | ** {====================================================== 82 | ** Time/Date operations 83 | ** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S, 84 | ** wday=%w+1, yday=%j, isdst=? } 85 | ** ======================================================= 86 | */ 87 | 88 | static void setfield (lua_State *L, const char *key, int value) { 89 | lua_pushinteger(L, value); 90 | lua_setfield(L, -2, key); 91 | } 92 | 93 | static void setboolfield (lua_State *L, const char *key, int value) { 94 | if (value < 0) /* undefined? */ 95 | return; /* does not set field */ 96 | lua_pushboolean(L, value); 97 | lua_setfield(L, -2, key); 98 | } 99 | 100 | static int getboolfield (lua_State *L, const char *key) { 101 | int res; 102 | lua_getfield(L, -1, key); 103 | res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1); 104 | lua_pop(L, 1); 105 | return res; 106 | } 107 | 108 | 109 | static int getfield (lua_State *L, const char *key, int d) { 110 | int res; 111 | lua_getfield(L, -1, key); 112 | if (lua_isnumber(L, -1)) 113 | res = (int)lua_tointeger(L, -1); 114 | else { 115 | if (d < 0) 116 | return luaL_error(L, "field " LUA_QS " missing in date table", key); 117 | res = d; 118 | } 119 | lua_pop(L, 1); 120 | return res; 121 | } 122 | 123 | 124 | static int os_date (lua_State *L) { 125 | const char *s = luaL_optstring(L, 1, "%c"); 126 | time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); 127 | struct tm *stm; 128 | if (*s == '!') { /* UTC? */ 129 | stm = gmtime(&t); 130 | s++; /* skip `!' */ 131 | } 132 | else 133 | stm = localtime(&t); 134 | if (stm == NULL) /* invalid date? */ 135 | lua_pushnil(L); 136 | else if (strcmp(s, "*t") == 0) { 137 | lua_createtable(L, 0, 9); /* 9 = number of fields */ 138 | setfield(L, "sec", stm->tm_sec); 139 | setfield(L, "min", stm->tm_min); 140 | setfield(L, "hour", stm->tm_hour); 141 | setfield(L, "day", stm->tm_mday); 142 | setfield(L, "month", stm->tm_mon+1); 143 | setfield(L, "year", stm->tm_year+1900); 144 | setfield(L, "wday", stm->tm_wday+1); 145 | setfield(L, "yday", stm->tm_yday+1); 146 | setboolfield(L, "isdst", stm->tm_isdst); 147 | } 148 | else { 149 | char cc[3]; 150 | luaL_Buffer b; 151 | cc[0] = '%'; cc[2] = '\0'; 152 | luaL_buffinit(L, &b); 153 | for (; *s; s++) { 154 | if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ 155 | luaL_addchar(&b, *s); 156 | else { 157 | size_t reslen; 158 | char buff[200]; /* should be big enough for any conversion result */ 159 | cc[1] = *(++s); 160 | reslen = strftime(buff, sizeof(buff), cc, stm); 161 | luaL_addlstring(&b, buff, reslen); 162 | } 163 | } 164 | luaL_pushresult(&b); 165 | } 166 | return 1; 167 | } 168 | 169 | 170 | static int os_time (lua_State *L) { 171 | time_t t; 172 | if (lua_isnoneornil(L, 1)) /* called without args? */ 173 | t = time(NULL); /* get current time */ 174 | else { 175 | struct tm ts; 176 | luaL_checktype(L, 1, LUA_TTABLE); 177 | lua_settop(L, 1); /* make sure table is at the top */ 178 | ts.tm_sec = getfield(L, "sec", 0); 179 | ts.tm_min = getfield(L, "min", 0); 180 | ts.tm_hour = getfield(L, "hour", 12); 181 | ts.tm_mday = getfield(L, "day", -1); 182 | ts.tm_mon = getfield(L, "month", -1) - 1; 183 | ts.tm_year = getfield(L, "year", -1) - 1900; 184 | ts.tm_isdst = getboolfield(L, "isdst"); 185 | t = mktime(&ts); 186 | } 187 | if (t == (time_t)(-1)) 188 | lua_pushnil(L); 189 | else 190 | lua_pushnumber(L, (lua_Number)t); 191 | return 1; 192 | } 193 | 194 | 195 | static int os_difftime (lua_State *L) { 196 | lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), 197 | (time_t)(luaL_optnumber(L, 2, 0)))); 198 | return 1; 199 | } 200 | 201 | /* }====================================================== */ 202 | 203 | 204 | static int os_setlocale (lua_State *L) { 205 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, 206 | LC_NUMERIC, LC_TIME}; 207 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", 208 | "numeric", "time", NULL}; 209 | const char *l = luaL_optstring(L, 1, NULL); 210 | int op = luaL_checkoption(L, 2, "all", catnames); 211 | lua_pushstring(L, setlocale(cat[op], l)); 212 | return 1; 213 | } 214 | 215 | 216 | static int os_exit (lua_State *L) { 217 | exit(luaL_optint(L, 1, EXIT_SUCCESS)); 218 | } 219 | 220 | static const luaL_Reg syslib[] = { 221 | {"clock", os_clock}, 222 | {"date", os_date}, 223 | {"difftime", os_difftime}, 224 | {"execute", os_execute}, 225 | {"exit", os_exit}, 226 | {"getenv", os_getenv}, 227 | {"remove", os_remove}, 228 | {"rename", os_rename}, 229 | {"setlocale", os_setlocale}, 230 | {"time", os_time}, 231 | {"tmpname", os_tmpname}, 232 | {NULL, NULL} 233 | }; 234 | 235 | /* }====================================================== */ 236 | 237 | 238 | 239 | LUALIB_API int luaopen_os (lua_State *L) { 240 | luaL_register(L, LUA_OSLIBNAME, syslib); 241 | return 1; 242 | } 243 | 244 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression descriptor 17 | */ 18 | 19 | typedef enum { 20 | VVOID, /* no value */ 21 | VNIL, 22 | VTRUE, 23 | VFALSE, 24 | VK, /* info = index of constant in `k' */ 25 | VKNUM, /* nval = numerical value */ 26 | VLOCAL, /* info = local register */ 27 | VUPVAL, /* info = index of upvalue in `upvalues' */ 28 | VGLOBAL, /* info = index of table; aux = index of global name in `k' */ 29 | VINDEXED, /* info = table register; aux = index register (or `k') */ 30 | VJMP, /* info = instruction pc */ 31 | VRELOCABLE, /* info = instruction pc */ 32 | VNONRELOC, /* info = result register */ 33 | VCALL, /* info = instruction pc */ 34 | VVARARG /* info = instruction pc */ 35 | } expkind; 36 | 37 | typedef struct expdesc { 38 | expkind k; 39 | union { 40 | struct { int info, aux; } s; 41 | lua_Number nval; 42 | } u; 43 | int t; /* patch list of `exit when true' */ 44 | int f; /* patch list of `exit when false' */ 45 | } expdesc; 46 | 47 | 48 | typedef struct upvaldesc { 49 | lu_byte k; 50 | lu_byte info; 51 | } upvaldesc; 52 | 53 | 54 | struct BlockCnt; /* defined in lparser.c */ 55 | 56 | 57 | /* state needed to generate code for a given function */ 58 | typedef struct FuncState { 59 | Proto *f; /* current function header */ 60 | Table *h; /* table to find (and reuse) elements in `k' */ 61 | struct FuncState *prev; /* enclosing function */ 62 | struct LexState *ls; /* lexical state */ 63 | struct lua_State *L; /* copy of the Lua state */ 64 | struct BlockCnt *bl; /* chain of current blocks */ 65 | int pc; /* next position to code (equivalent to `ncode') */ 66 | int lasttarget; /* `pc' of last `jump target' */ 67 | int jpc; /* list of pending jumps to `pc' */ 68 | int freereg; /* first free register */ 69 | int nk; /* number of elements in `k' */ 70 | int np; /* number of elements in `p' */ 71 | short nlocvars; /* number of elements in `locvars' */ 72 | lu_byte nactvar; /* number of active local variables */ 73 | upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ 74 | unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ 75 | } FuncState; 76 | 77 | 78 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 79 | const char *name); 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lstate.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $ 3 | ** Global State 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lstate_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "ldebug.h" 16 | #include "ldo.h" 17 | #include "lfunc.h" 18 | #include "lgc.h" 19 | #include "llex.h" 20 | #include "lmem.h" 21 | #include "lstate.h" 22 | #include "lstring.h" 23 | #include "ltable.h" 24 | #include "ltm.h" 25 | 26 | 27 | #define state_size(x) (sizeof(x) + LUAI_EXTRASPACE) 28 | #define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE) 29 | #define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE)) 30 | 31 | 32 | /* 33 | ** Main thread combines a thread state and the global state 34 | */ 35 | typedef struct LG { 36 | lua_State l; 37 | global_State g; 38 | } LG; 39 | 40 | 41 | 42 | static void stack_init (lua_State *L1, lua_State *L) { 43 | /* initialize CallInfo array */ 44 | L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); 45 | L1->ci = L1->base_ci; 46 | L1->size_ci = BASIC_CI_SIZE; 47 | L1->end_ci = L1->base_ci + L1->size_ci - 1; 48 | /* initialize stack array */ 49 | L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); 50 | L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; 51 | L1->top = L1->stack; 52 | L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; 53 | /* initialize first ci */ 54 | L1->ci->func = L1->top; 55 | setnilvalue(L1->top++); /* `function' entry for this `ci' */ 56 | L1->base = L1->ci->base = L1->top; 57 | L1->ci->top = L1->top + LUA_MINSTACK; 58 | } 59 | 60 | 61 | static void freestack (lua_State *L, lua_State *L1) { 62 | luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); 63 | luaM_freearray(L, L1->stack, L1->stacksize, TValue); 64 | } 65 | 66 | 67 | /* 68 | ** open parts that may cause memory-allocation errors 69 | */ 70 | static void f_luaopen (lua_State *L, void *ud) { 71 | global_State *g = G(L); 72 | UNUSED(ud); 73 | stack_init(L, L); /* init stack */ 74 | sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */ 75 | sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */ 76 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ 77 | luaT_init(L); 78 | luaX_init(L); 79 | luaS_fix(luaS_newliteral(L, MEMERRMSG)); 80 | g->GCthreshold = 4*g->totalbytes; 81 | } 82 | 83 | 84 | static void preinit_state (lua_State *L, global_State *g) { 85 | G(L) = g; 86 | L->stack = NULL; 87 | L->stacksize = 0; 88 | L->errorJmp = NULL; 89 | L->hook = NULL; 90 | L->hookmask = 0; 91 | L->basehookcount = 0; 92 | L->allowhook = 1; 93 | resethookcount(L); 94 | L->openupval = NULL; 95 | L->size_ci = 0; 96 | L->nCcalls = L->baseCcalls = 0; 97 | L->status = 0; 98 | L->base_ci = L->ci = NULL; 99 | L->savedpc = NULL; 100 | L->errfunc = 0; 101 | setnilvalue(gt(L)); 102 | } 103 | 104 | 105 | static void close_state (lua_State *L) { 106 | global_State *g = G(L); 107 | luaF_close(L, L->stack); /* close all upvalues for this thread */ 108 | luaC_freeall(L); /* collect all objects */ 109 | lua_assert(g->rootgc == obj2gco(L)); 110 | lua_assert(g->strt.nuse == 0); 111 | luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); 112 | luaZ_freebuffer(L, &g->buff); 113 | freestack(L, L); 114 | lua_assert(g->totalbytes == sizeof(LG)); 115 | (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0); 116 | } 117 | 118 | 119 | lua_State *luaE_newthread (lua_State *L) { 120 | lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); 121 | luaC_link(L, obj2gco(L1), LUA_TTHREAD); 122 | preinit_state(L1, G(L)); 123 | stack_init(L1, L); /* init stack */ 124 | setobj2n(L, gt(L1), gt(L)); /* share table of globals */ 125 | L1->hookmask = L->hookmask; 126 | L1->basehookcount = L->basehookcount; 127 | L1->hook = L->hook; 128 | resethookcount(L1); 129 | lua_assert(iswhite(obj2gco(L1))); 130 | return L1; 131 | } 132 | 133 | 134 | void luaE_freethread (lua_State *L, lua_State *L1) { 135 | luaF_close(L1, L1->stack); /* close all upvalues for this thread */ 136 | lua_assert(L1->openupval == NULL); 137 | luai_userstatefree(L1); 138 | freestack(L, L1); 139 | luaM_freemem(L, fromstate(L1), state_size(lua_State)); 140 | } 141 | 142 | 143 | LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { 144 | int i; 145 | lua_State *L; 146 | global_State *g; 147 | void *l = (*f)(ud, NULL, 0, state_size(LG)); 148 | if (l == NULL) return NULL; 149 | L = tostate(l); 150 | g = &((LG *)L)->g; 151 | L->next = NULL; 152 | L->tt = LUA_TTHREAD; 153 | g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); 154 | L->marked = luaC_white(g); 155 | set2bits(L->marked, FIXEDBIT, SFIXEDBIT); 156 | preinit_state(L, g); 157 | g->frealloc = f; 158 | g->ud = ud; 159 | g->mainthread = L; 160 | g->uvhead.u.l.prev = &g->uvhead; 161 | g->uvhead.u.l.next = &g->uvhead; 162 | g->GCthreshold = 0; /* mark it as unfinished state */ 163 | g->strt.size = 0; 164 | g->strt.nuse = 0; 165 | g->strt.hash = NULL; 166 | setnilvalue(registry(L)); 167 | luaZ_initbuffer(L, &g->buff); 168 | g->panic = NULL; 169 | g->gcstate = GCSpause; 170 | g->rootgc = obj2gco(L); 171 | g->sweepstrgc = 0; 172 | g->sweepgc = &g->rootgc; 173 | g->gray = NULL; 174 | g->grayagain = NULL; 175 | g->weak = NULL; 176 | g->tmudata = NULL; 177 | g->totalbytes = sizeof(LG); 178 | g->gcpause = LUAI_GCPAUSE; 179 | g->gcstepmul = LUAI_GCMUL; 180 | g->gcdept = 0; 181 | for (i=0; imt[i] = NULL; 182 | if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { 183 | /* memory allocation error: free partial state */ 184 | close_state(L); 185 | L = NULL; 186 | } 187 | else 188 | luai_userstateopen(L); 189 | return L; 190 | } 191 | 192 | 193 | static void callallgcTM (lua_State *L, void *ud) { 194 | UNUSED(ud); 195 | luaC_callGCTM(L); /* call GC metamethods for all udata */ 196 | } 197 | 198 | 199 | LUA_API void lua_close (lua_State *L) { 200 | L = G(L)->mainthread; /* only the main thread can be closed */ 201 | lua_lock(L); 202 | luaF_close(L, L->stack); /* close all upvalues for this thread */ 203 | luaC_separateudata(L, 1); /* separate udata that have GC metamethods */ 204 | L->errfunc = 0; /* no error function during GC metamethods */ 205 | do { /* repeat until no more errors */ 206 | L->ci = L->base_ci; 207 | L->base = L->top = L->ci->base; 208 | L->nCcalls = L->baseCcalls = 0; 209 | } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); 210 | lua_assert(G(L)->tmudata == NULL); 211 | luai_userstateclose(L); 212 | close_state(L); 213 | } 214 | 215 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ 3 | ** Global State 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstate_h 8 | #define lstate_h 9 | 10 | #include "lua.h" 11 | 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | #include "lzio.h" 15 | 16 | 17 | 18 | struct lua_longjmp; /* defined in ldo.c */ 19 | 20 | 21 | /* table of globals */ 22 | #define gt(L) (&L->l_gt) 23 | 24 | /* registry */ 25 | #define registry(L) (&G(L)->l_registry) 26 | 27 | 28 | /* extra stack space to handle TM calls and some other extras */ 29 | #define EXTRA_STACK 5 30 | 31 | 32 | #define BASIC_CI_SIZE 8 33 | 34 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK) 35 | 36 | 37 | 38 | typedef struct stringtable { 39 | GCObject **hash; 40 | lu_int32 nuse; /* number of elements */ 41 | int size; 42 | } stringtable; 43 | 44 | 45 | /* 46 | ** informations about a call 47 | */ 48 | typedef struct CallInfo { 49 | StkId base; /* base for this function */ 50 | StkId func; /* function index in the stack */ 51 | StkId top; /* top for this function */ 52 | const Instruction *savedpc; 53 | int nresults; /* expected number of results from this function */ 54 | int tailcalls; /* number of tail calls lost under this entry */ 55 | } CallInfo; 56 | 57 | 58 | 59 | #define curr_func(L) (clvalue(L->ci->func)) 60 | #define ci_func(ci) (clvalue((ci)->func)) 61 | #define f_isLua(ci) (!ci_func(ci)->c.isC) 62 | #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) 63 | 64 | 65 | /* 66 | ** `global state', shared by all threads of this state 67 | */ 68 | typedef struct global_State { 69 | stringtable strt; /* hash table for strings */ 70 | lua_Alloc frealloc; /* function to reallocate memory */ 71 | void *ud; /* auxiliary data to `frealloc' */ 72 | lu_byte currentwhite; 73 | lu_byte gcstate; /* state of garbage collector */ 74 | int sweepstrgc; /* position of sweep in `strt' */ 75 | GCObject *rootgc; /* list of all collectable objects */ 76 | GCObject **sweepgc; /* position of sweep in `rootgc' */ 77 | GCObject *gray; /* list of gray objects */ 78 | GCObject *grayagain; /* list of objects to be traversed atomically */ 79 | GCObject *weak; /* list of weak tables (to be cleared) */ 80 | GCObject *tmudata; /* last element of list of userdata to be GC */ 81 | Mbuffer buff; /* temporary buffer for string concatentation */ 82 | lu_mem GCthreshold; 83 | lu_mem totalbytes; /* number of bytes currently allocated */ 84 | lu_mem estimate; /* an estimate of number of bytes actually in use */ 85 | lu_mem gcdept; /* how much GC is `behind schedule' */ 86 | int gcpause; /* size of pause between successive GCs */ 87 | int gcstepmul; /* GC `granularity' */ 88 | lua_CFunction panic; /* to be called in unprotected errors */ 89 | TValue l_registry; 90 | struct lua_State *mainthread; 91 | UpVal uvhead; /* head of double-linked list of all open upvalues */ 92 | struct Table *mt[NUM_TAGS]; /* metatables for basic types */ 93 | TString *tmname[TM_N]; /* array with tag-method names */ 94 | } global_State; 95 | 96 | 97 | /* 98 | ** `per thread' state 99 | */ 100 | struct lua_State { 101 | CommonHeader; 102 | lu_byte status; 103 | StkId top; /* first free slot in the stack */ 104 | StkId base; /* base of current function */ 105 | global_State *l_G; 106 | CallInfo *ci; /* call info for current function */ 107 | const Instruction *savedpc; /* `savedpc' of current function */ 108 | StkId stack_last; /* last free slot in the stack */ 109 | StkId stack; /* stack base */ 110 | CallInfo *end_ci; /* points after end of ci array*/ 111 | CallInfo *base_ci; /* array of CallInfo's */ 112 | int stacksize; 113 | int size_ci; /* size of array `base_ci' */ 114 | unsigned short nCcalls; /* number of nested C calls */ 115 | unsigned short baseCcalls; /* nested C calls when resuming coroutine */ 116 | lu_byte hookmask; 117 | lu_byte allowhook; 118 | int basehookcount; 119 | int hookcount; 120 | lua_Hook hook; 121 | TValue l_gt; /* table of globals */ 122 | TValue env; /* temporary place for environments */ 123 | GCObject *openupval; /* list of open upvalues in this stack */ 124 | GCObject *gclist; 125 | struct lua_longjmp *errorJmp; /* current error recover point */ 126 | ptrdiff_t errfunc; /* current error handling function (stack index) */ 127 | }; 128 | 129 | 130 | #define G(L) (L->l_G) 131 | 132 | 133 | /* 134 | ** Union of all collectable objects 135 | */ 136 | union GCObject { 137 | GCheader gch; 138 | union TString ts; 139 | union Udata u; 140 | union Closure cl; 141 | struct Table h; 142 | struct Proto p; 143 | struct UpVal uv; 144 | struct lua_State th; /* thread */ 145 | }; 146 | 147 | 148 | /* macros to convert a GCObject into a specific value */ 149 | #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) 150 | #define gco2ts(o) (&rawgco2ts(o)->tsv) 151 | #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) 152 | #define gco2u(o) (&rawgco2u(o)->uv) 153 | #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) 154 | #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) 155 | #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) 156 | #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 157 | #define ngcotouv(o) \ 158 | check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 159 | #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) 160 | 161 | /* macro to convert any Lua object into a GCObject */ 162 | #define obj2gco(v) (cast(GCObject *, (v))) 163 | 164 | 165 | LUAI_FUNC lua_State *luaE_newthread (lua_State *L); 166 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); 167 | 168 | #endif 169 | 170 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keeps all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lstring_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lmem.h" 16 | #include "lobject.h" 17 | #include "lstate.h" 18 | #include "lstring.h" 19 | 20 | 21 | 22 | void luaS_resize (lua_State *L, int newsize) { 23 | GCObject **newhash; 24 | stringtable *tb; 25 | int i; 26 | if (G(L)->gcstate == GCSsweepstring) 27 | return; /* cannot resize during GC traverse */ 28 | newhash = luaM_newvector(L, newsize, GCObject *); 29 | tb = &G(L)->strt; 30 | for (i=0; isize; i++) { 33 | GCObject *p = tb->hash[i]; 34 | while (p) { /* for each node in the list */ 35 | GCObject *next = p->gch.next; /* save next */ 36 | unsigned int h = gco2ts(p)->hash; 37 | int h1 = lmod(h, newsize); /* new position */ 38 | lua_assert(cast_int(h%newsize) == lmod(h, newsize)); 39 | p->gch.next = newhash[h1]; /* chain it */ 40 | newhash[h1] = p; 41 | p = next; 42 | } 43 | } 44 | luaM_freearray(L, tb->hash, tb->size, TString *); 45 | tb->size = newsize; 46 | tb->hash = newhash; 47 | } 48 | 49 | 50 | static TString *newlstr (lua_State *L, const char *str, size_t l, 51 | unsigned int h) { 52 | TString *ts; 53 | stringtable *tb; 54 | if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) 55 | luaM_toobig(L); 56 | ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); 57 | ts->tsv.len = l; 58 | ts->tsv.hash = h; 59 | ts->tsv.marked = luaC_white(G(L)); 60 | ts->tsv.tt = LUA_TSTRING; 61 | ts->tsv.reserved = 0; 62 | memcpy(ts+1, str, l*sizeof(char)); 63 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */ 64 | tb = &G(L)->strt; 65 | h = lmod(h, tb->size); 66 | ts->tsv.next = tb->hash[h]; /* chain new entry */ 67 | tb->hash[h] = obj2gco(ts); 68 | tb->nuse++; 69 | if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) 70 | luaS_resize(L, tb->size*2); /* too crowded */ 71 | return ts; 72 | } 73 | 74 | 75 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 76 | GCObject *o; 77 | unsigned int h = cast(unsigned int, l); /* seed */ 78 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ 79 | size_t l1; 80 | for (l1=l; l1>=step; l1-=step) /* compute hash */ 81 | h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); 82 | for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; 83 | o != NULL; 84 | o = o->gch.next) { 85 | TString *ts = rawgco2ts(o); 86 | if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { 87 | /* string may be dead */ 88 | if (isdead(G(L), o)) changewhite(o); 89 | return ts; 90 | } 91 | } 92 | return newlstr(L, str, l, h); /* not found */ 93 | } 94 | 95 | 96 | Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { 97 | Udata *u; 98 | if (s > MAX_SIZET - sizeof(Udata)) 99 | luaM_toobig(L); 100 | u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); 101 | u->uv.marked = luaC_white(G(L)); /* is not finalized */ 102 | u->uv.tt = LUA_TUSERDATA; 103 | u->uv.len = s; 104 | u->uv.metatable = NULL; 105 | u->uv.env = e; 106 | /* chain it on udata list (after main thread) */ 107 | u->uv.next = G(L)->mainthread->next; 108 | G(L)->mainthread->next = obj2gco(u); 109 | return u; 110 | } 111 | 112 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lgc.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | 15 | 16 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 17 | 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 19 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 22 | (sizeof(s)/sizeof(char))-1)) 23 | 24 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 25 | 26 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 27 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 28 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.nk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define key2tval(n) (&(n)->i_key.tvk) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); 22 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 24 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); 25 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 26 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 27 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); 28 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 29 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 30 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 31 | LUAI_FUNC int luaH_getn (Table *t); 32 | 33 | 34 | #if defined(LUA_DEBUG) 35 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 36 | LUAI_FUNC int luaH_isdummy (Node *n); 37 | #endif 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define ltm_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lobject.h" 16 | #include "lstate.h" 17 | #include "lstring.h" 18 | #include "ltable.h" 19 | #include "ltm.h" 20 | 21 | 22 | 23 | const char *const luaT_typenames[] = { 24 | "nil", "boolean", "userdata", "number", 25 | "string", "table", "function", "userdata", "thread", 26 | "proto", "upval" 27 | }; 28 | 29 | 30 | void luaT_init (lua_State *L) { 31 | static const char *const luaT_eventname[] = { /* ORDER TM */ 32 | "__index", "__newindex", 33 | "__gc", "__mode", "__eq", 34 | "__add", "__sub", "__mul", "__div", "__mod", 35 | "__pow", "__unm", "__len", "__lt", "__le", 36 | "__concat", "__call" 37 | }; 38 | int i; 39 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 41 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ 42 | } 43 | } 44 | 45 | 46 | /* 47 | ** function to be used with macro "fasttm": optimized for absence of 48 | ** tag methods 49 | */ 50 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 51 | const TValue *tm = luaH_getstr(events, ename); 52 | lua_assert(event <= TM_EQ); 53 | if (ttisnil(tm)) { /* no tag method? */ 54 | events->flags |= cast_byte(1u<metatable; 66 | break; 67 | case LUA_TUSERDATA: 68 | mt = uvalue(o)->metatable; 69 | break; 70 | default: 71 | mt = G(L)->mt[ttype(o)]; 72 | } 73 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 74 | } 75 | 76 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_MOD, 29 | TM_POW, 30 | TM_UNM, 31 | TM_LEN, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | LUAI_DATA const char *const luaT_typenames[]; 47 | 48 | 49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 51 | TMS event); 52 | LUAI_FUNC void luaT_init (lua_State *L); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* Key to file-handle type */ 15 | #define LUA_FILEHANDLE "FILE*" 16 | 17 | 18 | #define LUA_COLIBNAME "coroutine" 19 | LUALIB_API int (luaopen_base) (lua_State *L); 20 | 21 | #define LUA_TABLIBNAME "table" 22 | LUALIB_API int (luaopen_table) (lua_State *L); 23 | 24 | #define LUA_IOLIBNAME "io" 25 | LUALIB_API int (luaopen_io) (lua_State *L); 26 | 27 | #define LUA_OSLIBNAME "os" 28 | LUALIB_API int (luaopen_os) (lua_State *L); 29 | 30 | #define LUA_STRLIBNAME "string" 31 | LUALIB_API int (luaopen_string) (lua_State *L); 32 | 33 | #define LUA_MATHLIBNAME "math" 34 | LUALIB_API int (luaopen_math) (lua_State *L); 35 | 36 | #define LUA_DBLIBNAME "debug" 37 | LUALIB_API int (luaopen_debug) (lua_State *L); 38 | 39 | #define LUA_LOADLIBNAME "package" 40 | LUALIB_API int (luaopen_package) (lua_State *L); 41 | 42 | 43 | /* open all previous libraries */ 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); 45 | 46 | 47 | 48 | #ifndef lua_assert 49 | #define lua_assert(x) ((void)0) 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lundump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #include 8 | 9 | #define lundump_c 10 | #define LUA_CORE 11 | 12 | #include "lua.h" 13 | 14 | #include "ldebug.h" 15 | #include "ldo.h" 16 | #include "lfunc.h" 17 | #include "lmem.h" 18 | #include "lobject.h" 19 | #include "lstring.h" 20 | #include "lundump.h" 21 | #include "lzio.h" 22 | 23 | typedef struct { 24 | lua_State* L; 25 | ZIO* Z; 26 | Mbuffer* b; 27 | const char* name; 28 | } LoadState; 29 | 30 | #ifdef LUAC_TRUST_BINARIES 31 | #define IF(c,s) 32 | #define error(S,s) 33 | #else 34 | #define IF(c,s) if (c) error(S,s) 35 | 36 | static void error(LoadState* S, const char* why) 37 | { 38 | luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why); 39 | luaD_throw(S->L,LUA_ERRSYNTAX); 40 | } 41 | #endif 42 | 43 | #define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) 44 | #define LoadByte(S) (lu_byte)LoadChar(S) 45 | #define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) 46 | #define LoadVector(S,b,n,size) LoadMem(S,b,n,size) 47 | 48 | static void LoadBlock(LoadState* S, void* b, size_t size) 49 | { 50 | size_t r=luaZ_read(S->Z,b,size); 51 | IF (r!=0, "unexpected end"); 52 | } 53 | 54 | static int LoadChar(LoadState* S) 55 | { 56 | char x; 57 | LoadVar(S,x); 58 | return x; 59 | } 60 | 61 | static int LoadInt(LoadState* S) 62 | { 63 | int x; 64 | LoadVar(S,x); 65 | IF (x<0, "bad integer"); 66 | return x; 67 | } 68 | 69 | static lua_Number LoadNumber(LoadState* S) 70 | { 71 | lua_Number x; 72 | LoadVar(S,x); 73 | return x; 74 | } 75 | 76 | static TString* LoadString(LoadState* S) 77 | { 78 | size_t size; 79 | LoadVar(S,size); 80 | if (size==0) 81 | return NULL; 82 | else 83 | { 84 | char* s=luaZ_openspace(S->L,S->b,size); 85 | LoadBlock(S,s,size); 86 | return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ 87 | } 88 | } 89 | 90 | static void LoadCode(LoadState* S, Proto* f) 91 | { 92 | int n=LoadInt(S); 93 | f->code=luaM_newvector(S->L,n,Instruction); 94 | f->sizecode=n; 95 | LoadVector(S,f->code,n,sizeof(Instruction)); 96 | } 97 | 98 | static Proto* LoadFunction(LoadState* S, TString* p); 99 | 100 | static void LoadConstants(LoadState* S, Proto* f) 101 | { 102 | int i,n; 103 | n=LoadInt(S); 104 | f->k=luaM_newvector(S->L,n,TValue); 105 | f->sizek=n; 106 | for (i=0; ik[i]); 107 | for (i=0; ik[i]; 110 | int t=LoadChar(S); 111 | switch (t) 112 | { 113 | case LUA_TNIL: 114 | setnilvalue(o); 115 | break; 116 | case LUA_TBOOLEAN: 117 | setbvalue(o,LoadChar(S)!=0); 118 | break; 119 | case LUA_TNUMBER: 120 | setnvalue(o,LoadNumber(S)); 121 | break; 122 | case LUA_TSTRING: 123 | setsvalue2n(S->L,o,LoadString(S)); 124 | break; 125 | default: 126 | error(S,"bad constant"); 127 | break; 128 | } 129 | } 130 | n=LoadInt(S); 131 | f->p=luaM_newvector(S->L,n,Proto*); 132 | f->sizep=n; 133 | for (i=0; ip[i]=NULL; 134 | for (i=0; ip[i]=LoadFunction(S,f->source); 135 | } 136 | 137 | static void LoadDebug(LoadState* S, Proto* f) 138 | { 139 | int i,n; 140 | n=LoadInt(S); 141 | f->lineinfo=luaM_newvector(S->L,n,int); 142 | f->sizelineinfo=n; 143 | LoadVector(S,f->lineinfo,n,sizeof(int)); 144 | n=LoadInt(S); 145 | f->locvars=luaM_newvector(S->L,n,LocVar); 146 | f->sizelocvars=n; 147 | for (i=0; ilocvars[i].varname=NULL; 148 | for (i=0; ilocvars[i].varname=LoadString(S); 151 | f->locvars[i].startpc=LoadInt(S); 152 | f->locvars[i].endpc=LoadInt(S); 153 | } 154 | n=LoadInt(S); 155 | f->upvalues=luaM_newvector(S->L,n,TString*); 156 | f->sizeupvalues=n; 157 | for (i=0; iupvalues[i]=NULL; 158 | for (i=0; iupvalues[i]=LoadString(S); 159 | } 160 | 161 | static Proto* LoadFunction(LoadState* S, TString* p) 162 | { 163 | Proto* f; 164 | if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep"); 165 | f=luaF_newproto(S->L); 166 | setptvalue2s(S->L,S->L->top,f); incr_top(S->L); 167 | f->source=LoadString(S); if (f->source==NULL) f->source=p; 168 | f->linedefined=LoadInt(S); 169 | f->lastlinedefined=LoadInt(S); 170 | f->nups=LoadByte(S); 171 | f->numparams=LoadByte(S); 172 | f->is_vararg=LoadByte(S); 173 | f->maxstacksize=LoadByte(S); 174 | LoadCode(S,f); 175 | LoadConstants(S,f); 176 | LoadDebug(S,f); 177 | IF (!luaG_checkcode(f), "bad code"); 178 | S->L->top--; 179 | S->L->nCcalls--; 180 | return f; 181 | } 182 | 183 | static void LoadHeader(LoadState* S) 184 | { 185 | char h[LUAC_HEADERSIZE]; 186 | char s[LUAC_HEADERSIZE]; 187 | luaU_header(h); 188 | LoadBlock(S,s,LUAC_HEADERSIZE); 189 | IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); 190 | } 191 | 192 | /* 193 | ** load precompiled chunk 194 | */ 195 | Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) 196 | { 197 | LoadState S; 198 | if (*name=='@' || *name=='=') 199 | S.name=name+1; 200 | else if (*name==LUA_SIGNATURE[0]) 201 | S.name="binary string"; 202 | else 203 | S.name=name; 204 | S.L=L; 205 | S.Z=Z; 206 | S.b=buff; 207 | LoadHeader(&S); 208 | return LoadFunction(&S,luaS_newliteral(L,"=?")); 209 | } 210 | 211 | /* 212 | * make header 213 | */ 214 | void luaU_header (char* h) 215 | { 216 | int x=1; 217 | memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); 218 | h+=sizeof(LUA_SIGNATURE)-1; 219 | *h++=(char)LUAC_VERSION; 220 | *h++=(char)LUAC_FORMAT; 221 | *h++=(char)*(char*)&x; /* endianness */ 222 | *h++=(char)sizeof(int); 223 | *h++=(char)sizeof(size_t); 224 | *h++=(char)sizeof(Instruction); 225 | *h++=(char)sizeof(lua_Number); 226 | *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */ 227 | } 228 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (char* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | #ifdef luac_c 23 | /* print one chunk; from print.c */ 24 | LUAI_FUNC void luaU_print (const Proto* f, int full); 25 | #endif 26 | 27 | /* for header of binary files -- this is Lua 5.1 */ 28 | #define LUAC_VERSION 0x51 29 | 30 | /* for header of binary files -- this is the official format */ 31 | #define LUAC_FORMAT 0 32 | 33 | /* size of header of binary files */ 34 | #define LUAC_HEADERSIZE 12 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 30 | StkId val); 31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 32 | StkId val); 33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); 34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** a generic input stream interface 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) return EOZ; 29 | z->n = size - 1; 30 | z->p = buff; 31 | return char2int(*(z->p++)); 32 | } 33 | 34 | 35 | int luaZ_lookahead (ZIO *z) { 36 | if (z->n == 0) { 37 | if (luaZ_fill(z) == EOZ) 38 | return EOZ; 39 | else { 40 | z->n++; /* luaZ_fill removed first byte; put back it */ 41 | z->p--; 42 | } 43 | } 44 | return char2int(*z->p); 45 | } 46 | 47 | 48 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 49 | z->L = L; 50 | z->reader = reader; 51 | z->data = data; 52 | z->n = 0; 53 | z->p = NULL; 54 | } 55 | 56 | 57 | /* --------------------------------------------------------------- read --- */ 58 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 59 | while (n) { 60 | size_t m; 61 | if (luaZ_lookahead(z) == EOZ) 62 | return n; /* return number of missing bytes */ 63 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 64 | memcpy(b, z->p, m); 65 | z->n -= m; 66 | z->p += m; 67 | b = (char *)b + m; 68 | n -= m; 69 | } 70 | return 0; 71 | } 72 | 73 | /* ------------------------------------------------------------------------ */ 74 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 75 | if (n > buff->buffsize) { 76 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 77 | luaZ_resizebuffer(L, buff, n); 78 | } 79 | return buff->buffer; 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define char2int(c) cast(int, cast(unsigned char, (c))) 21 | 22 | #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) 23 | 24 | typedef struct Mbuffer { 25 | char *buffer; 26 | size_t n; 27 | size_t buffsize; 28 | } Mbuffer; 29 | 30 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 31 | 32 | #define luaZ_buffer(buff) ((buff)->buffer) 33 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 34 | #define luaZ_bufflen(buff) ((buff)->n) 35 | 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 41 | (buff)->buffsize = size) 42 | 43 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 44 | 45 | 46 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 50 | LUAI_FUNC int luaZ_lookahead (ZIO *z); 51 | 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; 60 | void* data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/lua/print.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $ 3 | ** print bytecodes 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #define luac_c 11 | #define LUA_CORE 12 | 13 | #include "ldebug.h" 14 | #include "lobject.h" 15 | #include "lopcodes.h" 16 | #include "lundump.h" 17 | 18 | #define PrintFunction luaU_print 19 | 20 | #define Sizeof(x) ((int)sizeof(x)) 21 | #define VOID(p) ((const void*)(p)) 22 | 23 | static void PrintString(const TString* ts) 24 | { 25 | const char* s=getstr(ts); 26 | size_t i,n=ts->tsv.len; 27 | putchar('"'); 28 | for (i=0; ik[i]; 54 | switch (ttype(o)) 55 | { 56 | case LUA_TNIL: 57 | printf("nil"); 58 | break; 59 | case LUA_TBOOLEAN: 60 | printf(bvalue(o) ? "true" : "false"); 61 | break; 62 | case LUA_TNUMBER: 63 | printf(LUA_NUMBER_FMT,nvalue(o)); 64 | break; 65 | case LUA_TSTRING: 66 | PrintString(rawtsvalue(o)); 67 | break; 68 | default: /* cannot happen */ 69 | printf("? type=%d",ttype(o)); 70 | break; 71 | } 72 | } 73 | 74 | static void PrintCode(const Proto* f) 75 | { 76 | const Instruction* code=f->code; 77 | int pc,n=f->sizecode; 78 | for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t"); 90 | printf("%-9s\t",luaP_opnames[o]); 91 | switch (getOpMode(o)) 92 | { 93 | case iABC: 94 | printf("%d",a); 95 | if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b); 96 | if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c); 97 | break; 98 | case iABx: 99 | if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx); 100 | break; 101 | case iAsBx: 102 | if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx); 103 | break; 104 | } 105 | switch (o) 106 | { 107 | case OP_LOADK: 108 | printf("\t; "); PrintConstant(f,bx); 109 | break; 110 | case OP_GETUPVAL: 111 | case OP_SETUPVAL: 112 | printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-"); 113 | break; 114 | case OP_GETGLOBAL: 115 | case OP_SETGLOBAL: 116 | printf("\t; %s",svalue(&f->k[bx])); 117 | break; 118 | case OP_GETTABLE: 119 | case OP_SELF: 120 | if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); } 121 | break; 122 | case OP_SETTABLE: 123 | case OP_ADD: 124 | case OP_SUB: 125 | case OP_MUL: 126 | case OP_DIV: 127 | case OP_POW: 128 | case OP_EQ: 129 | case OP_LT: 130 | case OP_LE: 131 | if (ISK(b) || ISK(c)) 132 | { 133 | printf("\t; "); 134 | if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-"); 135 | printf(" "); 136 | if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-"); 137 | } 138 | break; 139 | case OP_JMP: 140 | case OP_FORLOOP: 141 | case OP_FORPREP: 142 | printf("\t; to %d",sbx+pc+2); 143 | break; 144 | case OP_CLOSURE: 145 | printf("\t; %p",VOID(f->p[bx])); 146 | break; 147 | case OP_SETLIST: 148 | if (c==0) printf("\t; %d",(int)code[++pc]); 149 | else printf("\t; %d",c); 150 | break; 151 | default: 152 | break; 153 | } 154 | printf("\n"); 155 | } 156 | } 157 | 158 | #define SS(x) (x==1)?"":"s" 159 | #define S(x) x,SS(x) 160 | 161 | static void PrintHeader(const Proto* f) 162 | { 163 | const char* s=getstr(f->source); 164 | if (*s=='@' || *s=='=') 165 | s++; 166 | else if (*s==LUA_SIGNATURE[0]) 167 | s="(bstring)"; 168 | else 169 | s="(string)"; 170 | printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n", 171 | (f->linedefined==0)?"main":"function",s, 172 | f->linedefined,f->lastlinedefined, 173 | S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f)); 174 | printf("%d%s param%s, %d slot%s, %d upvalue%s, ", 175 | f->numparams,f->is_vararg?"+":"",SS(f->numparams), 176 | S(f->maxstacksize),S(f->nups)); 177 | printf("%d local%s, %d constant%s, %d function%s\n", 178 | S(f->sizelocvars),S(f->sizek),S(f->sizep)); 179 | } 180 | 181 | static void PrintConstants(const Proto* f) 182 | { 183 | int i,n=f->sizek; 184 | printf("constants (%d) for %p:\n",n,VOID(f)); 185 | for (i=0; isizelocvars; 196 | printf("locals (%d) for %p:\n",n,VOID(f)); 197 | for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1); 201 | } 202 | } 203 | 204 | static void PrintUpvalues(const Proto* f) 205 | { 206 | int i,n=f->sizeupvalues; 207 | printf("upvalues (%d) for %p:\n",n,VOID(f)); 208 | if (f->upvalues==NULL) return; 209 | for (i=0; iupvalues[i])); 212 | } 213 | } 214 | 215 | void PrintFunction(const Proto* f, int full) 216 | { 217 | int i,n=f->sizep; 218 | PrintHeader(f); 219 | PrintCode(f); 220 | if (full) 221 | { 222 | PrintConstants(f); 223 | PrintLocals(f); 224 | PrintUpvalues(f); 225 | } 226 | for (i=0; ip[i],full); 227 | } 228 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/wax.h: -------------------------------------------------------------------------------- 1 | // Created by ProbablyInteractive. 2 | // Copyright 2009 Probably Interactive. All rights reserved. 3 | 4 | #import 5 | #import "lua.h" 6 | 7 | #define WAX_VERSION 0.93 8 | 9 | void wax_setup(); 10 | void wax_start(char *initScript, lua_CFunction extensionFunctions, ...); 11 | void wax_startWithServer(); 12 | void wax_end(); 13 | 14 | lua_State *wax_currentLuaState(); 15 | 16 | void luaopen_wax(lua_State *L); 17 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/wax.m: -------------------------------------------------------------------------------- 1 | // 2 | // ObjLua.m 3 | // Lua 4 | // 5 | // Created by ProbablyInteractive on 5/27/09. 6 | // Copyright 2009 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import "ProtocolLoader.h" 10 | 11 | #import "wax.h" 12 | #import "wax_class.h" 13 | #import "wax_instance.h" 14 | #import "wax_struct.h" 15 | #import "wax_helpers.h" 16 | #import "wax_gc.h" 17 | #import "wax_server.h" 18 | #import "wax_stdlib.h" 19 | 20 | #import "lauxlib.h" 21 | #import "lobject.h" 22 | #import "lualib.h" 23 | 24 | static void addGlobals(lua_State *L); 25 | static int waxRoot(lua_State *L); 26 | static int waxPrint(lua_State *L); 27 | static int tolua(lua_State *L); 28 | static int toobjc(lua_State *L); 29 | static int exitApp(lua_State *L); 30 | static int objcDebug(lua_State *L); 31 | 32 | static lua_State *currentL; 33 | lua_State *wax_currentLuaState() { 34 | 35 | if (!currentL) 36 | currentL = lua_open(); 37 | 38 | return currentL; 39 | } 40 | 41 | void uncaughtExceptionHandler(NSException *e) { 42 | NSLog(@"ERROR: Uncaught exception %@", [e description]); 43 | lua_State *L = wax_currentLuaState(); 44 | 45 | if (L) { 46 | wax_getStackTrace(L); 47 | const char *stackTrace = luaL_checkstring(L, -1); 48 | NSLog(@"%s", stackTrace); 49 | lua_pop(L, -1); // remove the stackTrace 50 | } 51 | } 52 | 53 | int wax_panic(lua_State *L) { 54 | printf("Lua panicked and quit: %s\n", luaL_checkstring(L, -1)); 55 | exit(EXIT_FAILURE); 56 | } 57 | 58 | lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf); 59 | 60 | void wax_setup() { 61 | NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); 62 | 63 | NSFileManager *fileManager = [NSFileManager defaultManager]; 64 | [fileManager changeCurrentDirectoryPath:[[NSBundle mainBundle] bundlePath]]; 65 | 66 | lua_State *L = wax_currentLuaState(); 67 | lua_atpanic(L, &wax_panic); 68 | 69 | luaL_openlibs(L); 70 | 71 | luaopen_wax_class(L); 72 | luaopen_wax_instance(L); 73 | luaopen_wax_struct(L); 74 | 75 | addGlobals(L); 76 | 77 | [wax_gc start]; 78 | } 79 | 80 | void wax_start(char* initScript, lua_CFunction extensionFunction, ...) { 81 | wax_setup(); 82 | 83 | lua_State *L = wax_currentLuaState(); 84 | 85 | // Load extentions 86 | // --------------- 87 | if (extensionFunction) { 88 | extensionFunction(L); 89 | 90 | va_list ap; 91 | va_start(ap, extensionFunction); 92 | while((extensionFunction = va_arg(ap, lua_CFunction))) extensionFunction(L); 93 | 94 | va_end(ap); 95 | } 96 | 97 | // Load stdlib 98 | // --------------- 99 | #ifdef WAX_STDLIB 100 | // If the stdlib was autogenerated and included in the source, load 101 | char stdlib[] = WAX_STDLIB; 102 | size_t stdlibSize = sizeof(stdlib); 103 | #else 104 | char stdlib[] = "require 'wax'"; 105 | size_t stdlibSize = strlen(stdlib); 106 | #endif 107 | 108 | if (luaL_loadbuffer(L, stdlib, stdlibSize, "loading wax stdlib") || lua_pcall(L, 0, LUA_MULTRET, 0)) { 109 | fprintf(stderr,"Error opening wax scripts: %s\n", lua_tostring(L,-1)); 110 | } 111 | 112 | // Run Tests or the REPL? 113 | // ---------------------- 114 | NSDictionary *env = [[NSProcessInfo processInfo] environment]; 115 | if ([[env objectForKey:@"WAX_TEST"] isEqual:@"YES"]) { 116 | printf("Running Tests\n"); 117 | if (luaL_dostring(L, "require 'tests'") != 0) { 118 | fprintf(stderr,"Fatal error running tests: %s\n", lua_tostring(L,-1)); 119 | } 120 | exit(1); 121 | } 122 | else if ([[env objectForKey:@"WAX_REPL"] isEqual:@"YES"]) { 123 | printf("Starting REPL\n"); 124 | if (luaL_dostring(L, "require 'wax.repl'") != 0) { 125 | fprintf(stderr,"Fatal error starting the REPL: %s\n", lua_tostring(L,-1)); 126 | } 127 | exit(1); 128 | } 129 | else { 130 | // Load app 131 | char appLoadString[512]; 132 | snprintf(appLoadString, sizeof(appLoadString), "local f = '%s' require(f:gsub('%%.[^.]*$', ''))", initScript); // Strip the extension off the file. 133 | if (luaL_dostring(L, appLoadString) != 0) { 134 | fprintf(stderr,"Error opening wax scripts: %s\n", lua_tostring(L,-1)); 135 | } 136 | } 137 | 138 | } 139 | 140 | void wax_startWithServer() { 141 | wax_setup(); 142 | [wax_server class]; // You need to load the class somehow via the wax.framework 143 | lua_State *L = wax_currentLuaState(); 144 | 145 | // Load all the wax lua scripts 146 | if (luaL_dofile(L, WAX_SCRIPTS_DIR "/scripts/wax/init.lua") != 0) { 147 | fprintf(stderr,"Fatal error opening wax scripts: %s\n", lua_tostring(L,-1)); 148 | } 149 | 150 | Class WaxServer = objc_getClass("WaxServer"); 151 | if (!WaxServer) [NSException raise:@"Wax Server Error" format:@"Could load Wax Server"]; 152 | 153 | [WaxServer start]; 154 | } 155 | 156 | void wax_end() { 157 | [wax_gc stop]; 158 | lua_close(wax_currentLuaState()); 159 | currentL = 0; 160 | } 161 | 162 | static void addGlobals(lua_State *L) { 163 | lua_getglobal(L, "wax"); 164 | if (lua_isnil(L, -1)) { 165 | lua_pop(L, 1); // Get rid of the nil 166 | lua_newtable(L); 167 | lua_pushvalue(L, -1); 168 | lua_setglobal(L, "wax"); 169 | } 170 | 171 | lua_pushnumber(L, WAX_VERSION); 172 | lua_setfield(L, -2, "version"); 173 | 174 | lua_pushstring(L, [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] UTF8String]); 175 | lua_setfield(L, -2, "appVersion"); 176 | 177 | lua_pushcfunction(L, waxRoot); 178 | lua_setfield(L, -2, "root"); 179 | 180 | lua_pushcfunction(L, waxPrint); 181 | lua_setfield(L, -2, "print"); 182 | 183 | #ifdef DEBUG 184 | lua_pushboolean(L, YES); 185 | lua_setfield(L, -2, "isDebug"); 186 | #endif 187 | 188 | lua_pop(L, 1); // pop the wax global off 189 | 190 | 191 | lua_pushcfunction(L, tolua); 192 | lua_setglobal(L, "tolua"); 193 | 194 | lua_pushcfunction(L, toobjc); 195 | lua_setglobal(L, "toobjc"); 196 | 197 | lua_pushcfunction(L, exitApp); 198 | lua_setglobal(L, "exitApp"); 199 | 200 | lua_pushstring(L, [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] UTF8String]); 201 | lua_setglobal(L, "NSDocumentDirectory"); 202 | 203 | lua_pushstring(L, [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0] UTF8String]); 204 | lua_setglobal(L, "NSLibraryDirectory"); 205 | 206 | NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 207 | lua_pushstring(L, [cachePath UTF8String]); 208 | lua_setglobal(L, "NSCacheDirectory"); 209 | 210 | NSError *error = nil; 211 | [[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:YES attributes: nil error:&error]; 212 | if (error) { 213 | wax_log(LOG_DEBUG, @"Error creating cache path. %@", [error localizedDescription]); 214 | } 215 | } 216 | 217 | static int waxPrint(lua_State *L) { 218 | NSLog(@"%s", luaL_checkstring(L, 1)); 219 | return 0; 220 | } 221 | 222 | static int waxRoot(lua_State *L) { 223 | luaL_Buffer b; 224 | luaL_buffinit(L, &b); 225 | luaL_addstring(&b, WAX_SCRIPTS_DIR); 226 | 227 | for (int i = 1; i <= lua_gettop(L); i++) { 228 | luaL_addstring(&b, "/"); 229 | luaL_addstring(&b, luaL_checkstring(L, i)); 230 | } 231 | 232 | luaL_pushresult(&b); 233 | 234 | return 1; 235 | } 236 | 237 | static int tolua(lua_State *L) { 238 | if (lua_isuserdata(L, 1)) { // If it's not userdata... it's already lua! 239 | wax_instance_userdata *instanceUserdata = (wax_instance_userdata *)luaL_checkudata(L, 1, WAX_INSTANCE_METATABLE_NAME); 240 | wax_fromInstance(L, instanceUserdata->instance); 241 | } 242 | 243 | return 1; 244 | } 245 | 246 | static int toobjc(lua_State *L) { 247 | id *instancePointer = wax_copyToObjc(L, "@", 1, nil); 248 | id instance = *(id *)instancePointer; 249 | 250 | wax_instance_create(L, instance, NO); 251 | 252 | if (instancePointer) free(instancePointer); 253 | 254 | return 1; 255 | } 256 | 257 | static int exitApp(lua_State *L) { 258 | exit(0); 259 | return 0; 260 | } -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/wax_class.h: -------------------------------------------------------------------------------- 1 | // 2 | // wax_class.h 3 | // Lua 4 | // 5 | // Created by ProbablyInteractive on 5/20/09. 6 | // Copyright 2009 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | #import "lua.h" 14 | 15 | #define WAX_CLASS_METATABLE_NAME "wax.class" 16 | #define WAX_CLASS_INSTANCE_USERDATA_IVAR_NAME "wax_instance_userdata" 17 | 18 | int luaopen_wax_class(lua_State *L); 19 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/wax_class.m: -------------------------------------------------------------------------------- 1 | // 2 | // wax_class.m 3 | // Lua 4 | // 5 | // Created by ProbablyInteractive on 5/20/09. 6 | // Copyright 2009 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import "wax_class.h" 10 | 11 | #import "wax.h" 12 | #import "wax_instance.h" 13 | #import "wax_helpers.h" 14 | 15 | #import "lua.h" 16 | #import "lauxlib.h" 17 | 18 | static int __index(lua_State *L); 19 | static int __call(lua_State *L); 20 | 21 | static int addProtocols(lua_State *L); 22 | static int name(lua_State *L); 23 | static id alloc(id self, SEL _cmd); 24 | static id allocWithZone(id self, SEL _cmd, NSZone *); 25 | static id valueForUndefinedKey(id self, SEL cmd, NSString *key); 26 | static void setValueForUndefinedKey(id self, SEL cmd, id value, NSString *key); 27 | 28 | static const struct luaL_Reg MetaMethods[] = { 29 | {"__index", __index}, 30 | {"__call", __call}, 31 | {NULL, NULL} 32 | }; 33 | 34 | static const struct luaL_Reg Methods[] = { 35 | {"addProtocols", addProtocols}, 36 | {"name", name}, 37 | {NULL, NULL} 38 | }; 39 | 40 | int luaopen_wax_class(lua_State *L) { 41 | BEGIN_STACK_MODIFY(L); 42 | 43 | luaL_newmetatable(L, WAX_CLASS_METATABLE_NAME); 44 | luaL_register(L, NULL, MetaMethods); 45 | luaL_register(L, WAX_CLASS_METATABLE_NAME, Methods); 46 | 47 | // Set the metatable for the module 48 | luaL_getmetatable(L, WAX_CLASS_METATABLE_NAME); 49 | lua_setmetatable(L, -2); 50 | 51 | END_STACK_MODIFY(L, 0) 52 | 53 | return 1; 54 | } 55 | 56 | 57 | // Finds an ObjC class 58 | static int __index(lua_State *L) { 59 | const char *className = luaL_checkstring(L, 2); 60 | Class klass = objc_getClass(className); 61 | if (klass) { 62 | wax_instance_create(L, klass, YES); 63 | } 64 | else { 65 | lua_pushnil(L); 66 | } 67 | 68 | return 1; 69 | } 70 | 71 | // Creates a new ObjC class 72 | static int __call(lua_State *L) { 73 | const char *className = luaL_checkstring(L, 2); 74 | Class klass = objc_getClass(className); 75 | 76 | if (!klass) { 77 | Class superClass; 78 | if (lua_isuserdata(L, 3)) { 79 | wax_instance_userdata *instanceUserdata = (wax_instance_userdata *)luaL_checkudata(L, 3, WAX_INSTANCE_METATABLE_NAME); 80 | superClass = instanceUserdata->instance; 81 | } 82 | else if (lua_isnoneornil(L, 3)) { 83 | superClass = [NSObject class]; 84 | } 85 | else { 86 | const char *superClassName = luaL_checkstring(L, 3); 87 | superClass = objc_getClass(superClassName); 88 | } 89 | 90 | if (!superClass) { 91 | luaL_error(L, "Failed to create '%s'. Unknown superclass \"%s\" received.", className, luaL_checkstring(L, 3)); 92 | } 93 | 94 | klass = objc_allocateClassPair(superClass, className, 0); 95 | NSUInteger size; 96 | NSUInteger alignment; 97 | NSGetSizeAndAlignment("*", &size, &alignment); 98 | class_addIvar(klass, WAX_CLASS_INSTANCE_USERDATA_IVAR_NAME, size, alignment, "*"); // Holds a reference to the lua userdata 99 | objc_registerClassPair(klass); 100 | 101 | // Make Key-Value complient 102 | class_addMethod(klass, @selector(setValue:forUndefinedKey:), (IMP)setValueForUndefinedKey, "v@:@@"); 103 | class_addMethod(klass, @selector(valueForUndefinedKey:), (IMP)valueForUndefinedKey, "@@:@"); 104 | 105 | id metaclass = object_getClass(klass); 106 | 107 | // So objects created in ObjC will get an associated lua object 108 | // Store the original allocWithZone implementation in case something secret goes on in there. 109 | // Calls to `alloc` always are end up calling `allocWithZone:` so we don't bother handling alloc here. 110 | Method m = class_getInstanceMethod(metaclass, @selector(allocWithZone:)); 111 | 112 | // If we the method has already been swizzled (by the class's super, then 113 | // just leave it up to the super! 114 | if (method_getImplementation(m) != (IMP)allocWithZone) { 115 | class_addMethod(metaclass, @selector(wax_originalAllocWithZone:), method_getImplementation(m), method_getTypeEncoding(m)); 116 | class_addMethod(metaclass, @selector(allocWithZone:), (IMP)allocWithZone, "@@:^{_NSZone=}"); 117 | } 118 | } 119 | 120 | wax_instance_create(L, klass, YES); 121 | 122 | return 1; 123 | } 124 | 125 | static int addProtocols(lua_State *L) { 126 | wax_instance_userdata *instanceUserdata = (wax_instance_userdata *)luaL_checkudata(L, 1, WAX_INSTANCE_METATABLE_NAME); 127 | 128 | if (!instanceUserdata->isClass) { 129 | luaL_error(L, "ERROR: Can only set a protocol on a class (You are trying to set one on an instance)"); 130 | return 0; 131 | } 132 | 133 | for (int i = 2; i <= lua_gettop(L); i++) { 134 | const char *protocolName = luaL_checkstring(L, i); 135 | Protocol *protocol = objc_getProtocol(protocolName); 136 | if (!protocol) luaL_error(L, "Could not find protocol named '%s'\nHint: Sometimes the runtime cannot automatically find a protocol. Try adding it (via xCode) to the file ProtocolLoader.h", protocolName); 137 | class_addProtocol(instanceUserdata->instance, protocol); 138 | } 139 | 140 | return 0; 141 | } 142 | 143 | static int name(lua_State *L) { 144 | wax_instance_userdata *instanceUserdata = (wax_instance_userdata *)luaL_checkudata(L, 1, WAX_INSTANCE_METATABLE_NAME); 145 | lua_pushstring(L, [NSStringFromClass([instanceUserdata->instance class]) UTF8String]); 146 | return 1; 147 | } 148 | 149 | static id allocWithZone(id self, SEL _cmd, NSZone *zone) { 150 | lua_State *L = wax_currentLuaState(); 151 | BEGIN_STACK_MODIFY(L); 152 | 153 | id instance = [self wax_originalAllocWithZone:zone]; 154 | object_setInstanceVariable(instance, WAX_CLASS_INSTANCE_USERDATA_IVAR_NAME, @"YEAP"); 155 | 156 | END_STACK_MODIFY(L, 0); 157 | 158 | return instance; 159 | } 160 | 161 | 162 | static void setValueForUndefinedKey(id self, SEL cmd, id value, NSString *key) { 163 | lua_State *L = wax_currentLuaState(); 164 | 165 | BEGIN_STACK_MODIFY(L); 166 | 167 | wax_instance_pushUserdata(L, self); 168 | wax_fromObjc(L, "@", &value); 169 | lua_setfield(L, -2, [key UTF8String]); 170 | 171 | END_STACK_MODIFY(L, 0); 172 | } 173 | 174 | static id valueForUndefinedKey(id self, SEL cmd, NSString *key) { 175 | lua_State *L = wax_currentLuaState(); 176 | id result = nil; 177 | 178 | BEGIN_STACK_MODIFY(L); 179 | 180 | wax_instance_pushUserdata(L, self); 181 | lua_getfield(L, -1, [key UTF8String]); 182 | 183 | id *keyValue = wax_copyToObjc(L, "@", -1, nil); 184 | result = *keyValue; 185 | free(keyValue); 186 | 187 | END_STACK_MODIFY(L, 0); 188 | 189 | return result; 190 | } -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/wax_gc.h: -------------------------------------------------------------------------------- 1 | // 2 | // wax_garbage_collection.h 3 | // WaxTests 4 | // 5 | // Created by Corey Johnson on 2/23/10. 6 | // Copyright 2010 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface wax_gc : NSObject { 13 | 14 | } 15 | 16 | + (void)start; 17 | + (void)stop; 18 | + (void)cleanupUnusedObject; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/wax_gc.m: -------------------------------------------------------------------------------- 1 | // 2 | // wax_garbage_collection.m 3 | // WaxTests 4 | // 5 | // Created by Corey Johnson on 2/23/10. 6 | // Copyright 2010 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import "wax_gc.h" 10 | 11 | #import "lua.h" 12 | #import "lauxlib.h" 13 | 14 | #import "wax.h" 15 | #import "wax_instance.h" 16 | #import "wax_helpers.h" 17 | 18 | #define WAX_GC_TIMEOUT 1 19 | 20 | @implementation wax_gc 21 | 22 | static NSTimer* timer = nil; 23 | 24 | + (void)start { 25 | [timer invalidate]; 26 | timer = [NSTimer scheduledTimerWithTimeInterval:WAX_GC_TIMEOUT target:self selector:@selector(cleanupUnusedObject) userInfo:nil repeats:YES]; 27 | } 28 | 29 | + (void)stop { 30 | [timer invalidate]; 31 | timer = nil; 32 | } 33 | 34 | + (void)cleanupUnusedObject { 35 | lua_State *L = wax_currentLuaState(); 36 | BEGIN_STACK_MODIFY(L) 37 | 38 | wax_instance_pushStrongUserdataTable(L); 39 | 40 | lua_pushnil(L); // first key 41 | while (lua_next(L, -2)) { 42 | wax_instance_userdata *instanceUserdata = (wax_instance_userdata *)luaL_checkudata(L, -1, WAX_INSTANCE_METATABLE_NAME); 43 | lua_pop(L, 1); // pops the value, keeps the key 44 | 45 | if (!instanceUserdata->isClass && !instanceUserdata->isSuper && [instanceUserdata->instance retainCount] <= 1) { 46 | lua_pushvalue(L, -1); 47 | lua_pushnil(L); 48 | lua_rawset(L, -4); // Clear it! 49 | if(instanceUserdata->waxRetain) { 50 | [instanceUserdata->instance release]; 51 | instanceUserdata->waxRetain = NO; // fix gc bad exec 52 | } 53 | } 54 | } 55 | 56 | 57 | END_STACK_MODIFY(L, 0); 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/wax_helpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // wax_helpers.h 3 | // Lua 4 | // 5 | // Created by ProbablyInteractive on 5/18/09. 6 | // Copyright 2009 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | #import "wax_instance.h" 14 | 15 | #import "lua.h" 16 | 17 | //#define _C_ATOM '%' 18 | //#define _C_VECTOR '!' 19 | //#define _C_CONST 'r' 20 | 21 | // ENCODINGS CAN BE FOUND AT http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html 22 | #define WAX_TYPE_CHAR _C_CHR 23 | #define WAX_TYPE_INT _C_INT 24 | #define WAX_TYPE_SHORT _C_SHT 25 | #define WAX_TYPE_UNSIGNED_CHAR _C_UCHR 26 | #define WAX_TYPE_UNSIGNED_INT _C_UINT 27 | #define WAX_TYPE_UNSIGNED_SHORT _C_USHT 28 | 29 | #define WAX_TYPE_LONG _C_LNG 30 | #define WAX_TYPE_LONG_LONG _C_LNG_LNG 31 | #define WAX_TYPE_UNSIGNED_LONG _C_ULNG 32 | #define WAX_TYPE_UNSIGNED_LONG_LONG _C_ULNG_LNG 33 | #define WAX_TYPE_FLOAT _C_FLT 34 | #define WAX_TYPE_DOUBLE _C_DBL 35 | 36 | #define WAX_TYPE_C99_BOOL _C_BOOL 37 | 38 | #define WAX_TYPE_STRING _C_CHARPTR 39 | #define WAX_TYPE_VOID _C_VOID 40 | #define WAX_TYPE_ARRAY _C_ARY_B 41 | #define WAX_TYPE_ARRAY_END _C_ARY_E 42 | #define WAX_TYPE_BITFIELD _C_BFLD 43 | #define WAX_TYPE_ID _C_ID 44 | #define WAX_TYPE_CLASS _C_CLASS 45 | #define WAX_TYPE_SELECTOR _C_SEL 46 | #define WAX_TYPE_STRUCT _C_STRUCT_B 47 | #define WAX_TYPE_STRUCT_END _C_STRUCT_E 48 | #define WAX_TYPE_UNION _C_UNION_B 49 | #define WAX_TYPE_UNION_END _C_UNION_E 50 | #define WAX_TYPE_POINTER _C_PTR 51 | #define WAX_TYPE_UNKNOWN _C_UNDEF 52 | 53 | #define WAX_PROTOCOL_TYPE_CONST 'r' 54 | #define WAX_PROTOCOL_TYPE_IN 'n' 55 | #define WAX_PROTOCOL_TYPE_INOUT 'N' 56 | #define WAX_PROTOCOL_TYPE_OUT 'o' 57 | #define WAX_PROTOCOL_TYPE_BYCOPY 'O' 58 | #define WAX_PROTOCOL_TYPE_BYREF 'R' 59 | #define WAX_PROTOCOL_TYPE_ONEWAY 'V' 60 | 61 | #define BEGIN_STACK_MODIFY(L) int __startStackIndex = lua_gettop((L)); 62 | 63 | #define END_STACK_MODIFY(L, i) while(lua_gettop((L)) > (__startStackIndex + (i))) lua_remove((L), __startStackIndex + 1); 64 | 65 | #ifndef LOG_FLAGS 66 | #define LOG_FLAGS (LOG_FATAL | LOG_ERROR | LOG_DEBUG) 67 | #endif 68 | 69 | #define LOG_DEBUG 1 << 0 70 | #define LOG_ERROR 1 << 1 71 | #define LOG_FATAL 1 << 2 72 | 73 | #define LOG_GC 1 << 5 74 | #define LOG_NETWORK 1 << 6 75 | 76 | // Debug Helpers 77 | void wax_printStack(lua_State *L); 78 | void wax_printStackAt(lua_State *L, int i); 79 | void wax_printTable(lua_State *L, int t); 80 | void wax_log(int flag, NSString *format, ...); 81 | int wax_getStackTrace(lua_State *L); 82 | 83 | // Convertion Helpers 84 | int wax_fromObjc(lua_State *L, const char *typeDescription, void *buffer); 85 | void wax_fromInstance(lua_State *L, id instance); 86 | void wax_fromStruct(lua_State *L, const char *typeDescription, void *buffer); 87 | 88 | void *wax_copyToObjc(lua_State *L, const char *typeDescription, int stackIndex, int *outsize); 89 | 90 | // Misc Helpers 91 | void wax_selectorsForName(const char *methodName, SEL selectors[2]); 92 | BOOL wax_selectorForInstance(wax_instance_userdata *instanceUserdata, SEL* foundSelectors, const char *methodName, BOOL forceInstanceCheck); 93 | void wax_pushMethodNameFromSelector(lua_State *L, SEL selector); 94 | BOOL wax_isInitMethod(const char *methodName); 95 | 96 | const char *wax_removeProtocolEncodings(const char *type_descriptions); 97 | 98 | int wax_sizeOfTypeDescription(const char *full_type_description); 99 | int wax_simplifyTypeDescription(const char *in, char *out); 100 | 101 | int wax_errorFunction(lua_State *L); 102 | int wax_pcall(lua_State *L, int argumentCount, int returnCount); -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/wax_instance.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wax_instance.h 3 | * Lua 4 | * 5 | * Created by ProbablyInteractive on 5/18/09. 6 | * Copyright 2009 Probably Interactive. All rights reserved. 7 | * 8 | */ 9 | 10 | #import 11 | #import 12 | #import 13 | 14 | #import "lua.h" 15 | 16 | #define WAX_INSTANCE_METATABLE_NAME "wax.instance" 17 | 18 | typedef struct _wax_instance_userdata { 19 | id instance; 20 | BOOL isClass; 21 | Class isSuper; // isSuper not only stores whether the class is a super, but it also contains the value of the next superClass. 22 | BOOL actAsSuper; // It only acts like a super once, when it is called for the first time. 23 | BOOL waxRetain; // TODO: need release instance when gc 24 | } wax_instance_userdata; 25 | 26 | int luaopen_wax_instance(lua_State *L); 27 | 28 | wax_instance_userdata *wax_instance_create(lua_State *L, id instance, BOOL isClass); 29 | wax_instance_userdata *wax_instance_createSuper(lua_State *L, wax_instance_userdata *instanceUserdata); 30 | void wax_instance_pushUserdataTable(lua_State *L); 31 | void wax_instance_pushStrongUserdataTable(lua_State *L); 32 | 33 | BOOL wax_instance_pushFunction(lua_State *L, id self, SEL selector); 34 | void wax_instance_pushUserdata(lua_State *L, id object); 35 | BOOL wax_instance_isWaxClass(id instance); 36 | -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/wax_server.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class wax_server; 4 | 5 | NSString * const TCPServerErrorDomain; 6 | 7 | typedef enum { 8 | kTCPServerCouldNotBindToIPv4Address = 1, 9 | kTCPServerCouldNotBindToIPv6Address = 2, 10 | kTCPServerNoSocketsAvailable = 3, 11 | } TCPServerErrorCode; 12 | 13 | 14 | @protocol WaxServerDelegate 15 | 16 | @optional 17 | - (void)connected; 18 | - (void)disconnected; 19 | - (void)dataReceived:(NSData *)data; 20 | 21 | @end 22 | 23 | 24 | @interface wax_server : NSObject { 25 | CFSocketRef _ipv4socket; 26 | id _delegate; 27 | 28 | NSNetService *_netService; 29 | NSInputStream *_inStream; 30 | NSOutputStream *_outStream; 31 | } 32 | 33 | @property(nonatomic, assign) id delegate; 34 | 35 | - (NSError *)startOnPort:(NSUInteger)port; 36 | - (BOOL)stop; 37 | - (BOOL)enableBonjourOnPort:(NSUInteger)port; 38 | - (void)disableBonjour; 39 | 40 | - (BOOL)send:(NSString *)output; 41 | - (void)receive:(NSData *)output; 42 | 43 | @end 44 | 45 | // This is needed because the runtime doesn't automatically load protocols 46 | @interface HACK_WAX_DELEGATE_IMPLEMENTOR {} 47 | @end -------------------------------------------------------------------------------- /WaxPatch/WaxPatch/wax/wax_struct.h: -------------------------------------------------------------------------------- 1 | // 2 | // wax_struct.h 3 | // Rentals 4 | // 5 | // Created by ProbablyInteractive on 7/7/09. 6 | // Copyright 2009 Probably Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "lua.h" 11 | 12 | #define WAX_STRUCT_METATABLE_NAME "wax.struct" 13 | 14 | typedef struct _wax_struct_userdata { 15 | void *data; 16 | int size; 17 | char *name; 18 | char *typeDescription; 19 | } wax_struct_userdata; 20 | 21 | int luaopen_wax_struct(lua_State *L); 22 | 23 | wax_struct_userdata *wax_struct_create(lua_State *L, const char *typeDescription, void *buffer); 24 | void wax_struct_pushValueAt(lua_State *L, wax_struct_userdata *structUserdata, int index); 25 | void wax_struct_setValueAt(lua_State *L, wax_struct_userdata *structUserdata, int index, int stackIndex); 26 | int wax_struct_getOffsetForName(lua_State *L, wax_struct_userdata *structUserdata, const char *name); -------------------------------------------------------------------------------- /patch/MainViewController.lua: -------------------------------------------------------------------------------- 1 | waxClass{"MainViewController", UITableViewController} 2 | 3 | function tableView_cellForRowAtIndexPath(self, tableView, indexPath) 4 | local cell = self:ORIGtableView_cellForRowAtIndexPath(tableView, indexPath) 5 | cell:textLabel():setText("" .. (10 - indexPath:row())) 6 | cell:detailTextLabel():setText("http://github.com/mmin18") 7 | cell:textLabel():setTextColor(UIColor:redColor()) 8 | return cell 9 | end 10 | -------------------------------------------------------------------------------- /patch/patch.lua: -------------------------------------------------------------------------------- 1 | require "MainViewController" 2 | -------------------------------------------------------------------------------- /patch/patch.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmin18/WaxPatch/ab9187d0d13013d280aa81c8029c1a116d1cca0c/patch/patch.zip --------------------------------------------------------------------------------