Changeset 324

Show
Ignore:
Timestamp:
01/18/09 20:37:17 (3 years ago)
Author:
Trass3r
Message:

+ D2 compatibility!
+ precompiled lua 5.1.4
+ Exceptions support file and line arguments
* changed file encoding to UTF-8
* several bugfixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lua/buffer.d

    r314 r324  
    1 /******************************************************************************* 
     1/******************************************************************************* 
    22 
    33    copyright:      Copyright (c) 2008 Matthias Walter. All rights reserved 
     
    99module lua.buffer; 
    1010 
     11private import lua.common; 
    1112private import lua.state; 
    1213private import lua.lauxlib; 
     
    118119    *******************************************************************************/ 
    119120 
    120     public LuaBuffer addString (char[] string) 
     121    public LuaBuffer addString (cstring string) 
    121122    { 
    122123        luaL_addlstring (&this.buffer_, string.ptr, string.length); 
     
    196197{ 
    197198 
    198     char[] output = ""; 
    199  
    200     void write (char[] data) 
     199    string output = ""; 
     200 
     201    void write (cstring data) 
    201202    { 
    202203        output ~= data; 
     
    211212    buffer.addValue (); 
    212213 
    213     auto buf = buffer.prepare (); 
     214    auto buf = buffer.prepare(); 
    214215    buf[0] = 'B'; 
    215216    buf[1] = 'u'; 
  • trunk/lua/common.d

    r323 r324  
    99module lua.common; 
    1010 
     11// automatically link lua C library 
     12version(Windows)pragma(lib, "lua\\lua.lib"); 
     13version(linux)  pragma(lib, "lua/lua.lib"); 
     14 
    1115package 
    1216{ 
     
    1418version (D_Version2) 
    1519{ 
     20    pragma(msg, "D2 detected. Taking care of constness."); 
     21 
     22    // we need a mixin cause the code is syntactically illegal under D1 
     23    mixin(` 
     24    alias const(char) cchar; /// const char type 
     25    alias invariant(char) ichar; /// invariant char type 
     26 
    1627    alias char[] mstring; /// mutable string type 
    1728    alias const(char)[] cstring; /// const string type 
     
    2435    alias dchar[] mdstring; 
    2536    alias const(dchar)[] cdstring; 
    26     alias invariant(dchar)[] idstring; 
     37    alias invariant(dchar)[] idstring;`); 
    2738} 
    2839else 
    2940{ 
    30 /* 
    31     alias char[] string; 
    32     alias wchar[] wstring; 
    33     alias dchar[] dstring; 
    34 */ 
     41    pragma(msg, "D1 detected. All strings are mutable."); 
     42    alias char cchar; 
     43    alias char ichar; 
     44 
     45    alias char[] mstring; 
     46    alias char[] cstring; 
     47    alias char[] istring; 
     48 
     49    alias wchar[] mwstring; 
     50    alias wchar[] cwstring; 
     51    alias wchar[] iwstring; 
     52 
     53    alias dchar[] mdstring; 
     54    alias dchar[] cdstring; 
     55    alias dchar[] idstring; 
    3556} 
    3657} 
  • trunk/lua/data.d

    r314 r324  
    1 /******************************************************************************* 
     1/******************************************************************************* 
    22 
    33    copyright:      Copyright (c) 2008 Matthias Walter. All rights reserved 
     
    99module lua.data; 
    1010 
     11private import lua.common; 
    1112private import lua.lua; 
    1213private import lua.buffer, lua.mixins, lua.error, lua.state; 
     
    1516version (Tango) 
    1617{ 
    17     private import TangoFloat = tango.text.convert.Float; 
    18     alias TangoFloat.toString float2string; 
     18    private import tango.text.convert.Float : float2string = toString; 
    1919} 
    2020else 
     
    4141 
    4242    /// Returns a user-friendly string representation of the Object. 
    43     public abstract char[] toString (); 
     43    public abstract istring toString (); 
    4444 
    4545    /// Size of the header (currently only the LuaType in binary form.) 
     
    8383    { 
    8484        if (data.length < HEADER_SIZE) 
    85             throw new LuaFatalException ("Invalid stream: Could not read header."); 
     85            throw new LuaFatalException ("Invalid stream: Could not read header.", __FILE__, __LINE__); 
    8686 
    8787        LuaObject result; 
     
    9797            case LuaType.TABLE: result = new LuaTableObject (); break; 
    9898            default: 
    99                 throw new LuaFatalException ("Invalid stream: Wrong type code " ~ int2string (cast (int) * (cast (LuaType*) &data[0]))); 
     99                throw new LuaFatalException ("Invalid stream: Wrong type code " ~ int2string (cast (int) * (cast (LuaType*) &data[0])), __FILE__, __LINE__); 
    100100        } 
    101101        bytes_read = HEADER_SIZE; 
     
    124124    /// Pushes Nil onto the stack. 
    125125 
    126     public void push (LuaState state) 
     126    public override void push (LuaState state) 
    127127    { 
    128128        state.pushNil (); 
     
    131131    /// Returns the string representation. 
    132132 
    133     public override char[] toString () 
     133    public override istring toString () 
    134134    { 
    135135        return "nil"; 
     
    169169    /// You cannot push a saved Thread into a LuaState! 
    170170 
    171     public void push (LuaState state) 
    172     { 
    173         throw new LuaFatalException ("Error in LuaThreadObject: Cannot push threads."); 
    174     } 
    175      
    176     /// Returns the string representation. 
    177  
    178     public override char[] toString () 
     171    public override void push (LuaState state) 
     172    { 
     173        throw new LuaFatalException ("Error in LuaThreadObject: Cannot push threads.", __FILE__, __LINE__); 
     174    } 
     175     
     176    /// Returns the string representation. 
     177 
     178    public override istring toString () 
    179179    { 
    180180        return "thread"; 
     
    217217    /// Pushes the value onto the stack. 
    218218 
    219     public void push (LuaState state) 
     219    public override void push (LuaState state) 
    220220    { 
    221221        state.pushNumber (this.value_); 
     
    238238    /// Returns the string representation. 
    239239 
    240     public override char[] toString () 
    241     { 
    242             return float2string (this.value_); 
     240    public override istring toString () 
     241    { 
     242       return float2string (this.value_); 
    243243    } 
    244244     
     
    257257    { 
    258258        if (data.length < double.sizeof) 
    259             throw new LuaFatalException ("Invalid stream: Could not read Number."); 
     259            throw new LuaFatalException ("Invalid stream: Could not read Number.", __FILE__, __LINE__); 
    260260 
    261261        this.value_ = *(cast (double*) data.ptr); 
     
    286286    /// Pushes the bool value onto the Lua stack. 
    287287 
    288     public void push (LuaState state) 
     288    public override void push (LuaState state) 
    289289    { 
    290290        state.pushBool (this.value_); 
     
    307307    /// Returns the string representation. 
    308308 
    309     public override char[] toString () 
     309    public override istring toString () 
    310310    { 
    311311        return this.value_ ? "true" : "false"; 
     
    326326    { 
    327327        if (data.length < bool.sizeof) 
    328             throw new LuaFatalException ("Invalid stream: Could not read Boolean."); 
     328            throw new LuaFatalException ("Invalid stream: Could not read Boolean.", __FILE__, __LINE__); 
    329329 
    330330        this.value_ = *(cast (bool*) data.ptr); 
     
    344344{ 
    345345    /// String value 
    346     private char[] value_; 
     346    private mstring value_; 
    347347 
    348348    /// Constructs a LuaStringObject. 
    349349     
    350     public this (char[] value = "") 
    351     { 
    352         this.value_ = value
     350    public this (cstring value = "") 
     351    { 
     352        this.value_ = value.dup
    353353    } 
    354354     
    355355    /// Pushes the string onto the Lua stack. 
    356356 
    357     public void push (LuaState state) 
     357    public override void push (LuaState state) 
    358358    { 
    359359        state.pushString (this.value_); 
     
    361361     
    362362    /// Sets the value. 
    363      
    364     public char[] value (char[] v) 
    365     { 
    366         return (this.value_ = v); 
     363     
     364    public istring value (cstring v) 
     365    { 
     366        return cast(istring) (this.value_ = v.dup); 
    367367    } 
    368368     
    369369    /// Returns the value. 
    370370 
    371     public char[] value () 
    372     { 
    373         return this.value_; 
    374     } 
    375      
    376     /// Returns the string representation. 
    377  
    378     public override char[] toString () 
    379     { 
    380         return "\"" ~ this.value_ ~ "\""
     371    public istring value () 
     372    { 
     373        return cast(istring) this.value_; 
     374    } 
     375     
     376    /// Returns the string representation. 
     377 
     378    public override istring toString () 
     379    { 
     380        return cast(istring) ("\"" ~ this.value_ ~ "\"")
    381381    } 
    382382     
     
    398398    { 
    399399        if (data.length < size_t.sizeof) 
    400             throw new LuaFatalException ("Invalid stream: Could not read String length."); 
     400            throw new LuaFatalException ("Invalid stream: Could not read String length.", __FILE__, __LINE__); 
    401401 
    402402        this.value_ = new char[ *(cast (size_t*) data.ptr) ]; 
    403403        if (data.length < size_t.sizeof + this.value_.length) 
    404             throw new LuaFatalException ("Invalid stream: Could not read String."); 
     404            throw new LuaFatalException ("Invalid stream: Could not read String.", __FILE__, __LINE__); 
    405405 
    406406        auto p = cast (char*) &data[size_t.sizeof]; 
     
    443443    /// Pushes the LightUserdata onto the stack. Throws an error if it is a plain Userdata. 
    444444 
    445     public void push (LuaState state) 
     445    public override void push (LuaState state) 
    446446    { 
    447447        if (this.is_lightuserdata_) 
    448448            state.pushLightUserdata (this.value_); 
    449449        else 
    450             throw new LuaFatalException ("Error in LuaUserdataObject: Cannot push userdata."); 
     450            throw new LuaFatalException ("Error in LuaUserdataObject: Cannot push userdata.", __FILE__, __LINE__); 
    451451    } 
    452452     
     
    467467    /// Returns the string representation. 
    468468 
    469     public override char[] toString () 
     469    public override istring toString () 
    470470    { 
    471471        return (this.is_lightuserdata_ ? "LightUserdata: " : "Userdata: ") ~ int2string (cast (int) this.value_); 
     
    486486    { 
    487487        if (data.length < (void*).sizeof) 
    488             throw new LuaFatalException ("Invalid stream: Could not read Userdata."); 
     488            throw new LuaFatalException ("Invalid stream: Could not read Userdata.", __FILE__, __LINE__); 
    489489 
    490490        this.value_ = *(cast (void**) data.ptr); 
     
    529529    /// Pushes the C function onto the stack. 
    530530 
    531     public void push (LuaState state) 
     531    public override void push (LuaState state) 
    532532    { 
    533533        state.pushCFunction (this.value_); 
     
    536536    /// Returns the string representation. 
    537537 
    538     public override char[] toString () 
     538    public override istring toString () 
    539539    { 
    540540        if (this.value_ is null) 
     
    558558    { 
    559559        if (data.length < LuaCFunction.sizeof) 
    560             throw new LuaFatalException ("Invalid stream: Could not read Function."); 
     560            throw new LuaFatalException ("Invalid stream: Could not read Function.", __FILE__, __LINE__); 
    561561 
    562562        this.value_ = *(cast (LuaCFunction*) data.ptr); 
     
    609609    /// Pushes onto the stack the complete table. 
    610610 
    611     public void push (LuaState state) 
     611    public override void push (LuaState state) 
    612612    { 
    613613        state.createTable (); 
     
    623623    /// Returns the string representation. 
    624624 
    625     public override char[] toString () 
     625    public override istring toString () 
    626626    { 
    627627        if (this.data_ !is null) 
    628628        { 
    629             char[] result = "{ "; 
     629            istring result = "{ "; 
    630630            foreach (pair; this.data_) 
    631631            { 
     
    676676    { 
    677677        if (data.length < uint.sizeof) 
    678             throw new LuaFatalException ("Invalid stream: Could not read Table."); 
     678            throw new LuaFatalException ("Invalid stream: Could not read Table.", __FILE__, __LINE__); 
    679679 
    680680        this.data_ = new KeyValuePair [ *(cast (uint*) data.ptr) ]; 
  • trunk/lua/error.d

    r314 r324  
    1 /******************************************************************************* 
     1/******************************************************************************* 
    22 
    33    copyright:      Copyright (c) 2008 Matthias Walter. All rights reserved 
     
    99module lua.error; 
    1010 
     11private import lua.common; 
    1112private import lua.lua; 
    1213private import lua.lauxlib; 
     
    5556    ***************************************************************************/ 
    5657 
    57     private static CodeType parseCodeType (char[] str) 
     58    private static CodeType parseCodeType (cstring str) 
    5859    { 
    5960        switch (str) 
     
    6364            case "main": return CodeType.MAIN; 
    6465            case "tail": return CodeType.TAIL; 
    65             default: throw new LuaFatalException (str ~ " is an invalid LuaCodeType."); 
     66            default: throw new LuaFatalException ("parseCodeType: " ~ str ~ " is an invalid LuaCodeType."); 
    6667        } 
    6768    } 
     
    7677    ***************************************************************************/ 
    7778 
    78     public static char[] toString (CodeType code_type) 
     79    public static istring toString (CodeType code_type) 
    7980    { 
    8081        switch (code_type) 
     
    8485            case CodeType.MAIN: return "main"; 
    8586            case CodeType.TAIL: return "tail call"; 
     87            default: throw new LuaFatalException ("toString: " ~ int2string(cast(int)code_type) ~ " is an invalid LuaCodeType."); 
    8688        } 
    8789    } 
     
    9698    ***************************************************************************/ 
    9799 
    98     private static NameType parseNameType (char[] str) 
     100    private static NameType parseNameType (cstring str) 
    99101    { 
    100102        switch (str) 
     
    118120    ***************************************************************************/ 
    119121 
    120     public static char[] toString (NameType name_type) 
     122    public static istring toString (NameType name_type) 
    121123    { 
    122124        switch (name_type) 
     
    137139    private NameType name_type_; 
    138140    /// Name 
    139     private char[] name_; 
     141    private mstring name_; 
    140142    /// Whether this function was loaded from a file. 
    141143    private bool is_from_file_; 
    142144    /// Source string, containing the source or filename. 
    143     private char[] source_; 
     145    private mstring source_; 
    144146    /// Start of the definition of this function in the source. 
    145147    private uint definition_start_; 
     
    221223    /// Returns the name of the function. 
    222224 
    223     public char[] name () 
    224     { 
    225         return this.name_; 
     225    public istring name () 
     226    { 
     227        return cast(istring) this.name_; 
    226228    } 
    227229 
     
    235237    /// Returns the source for the function or the filename, where it was defined. 
    236238 
    237     public char[] source () 
    238     { 
    239         return this.source_; 
     239    public istring source () 
     240    { 
     241        return cast(istring) this.source_; 
    240242    } 
    241243 
     
    270272    /// Returns of compact string representation of the information about the function. 
    271273 
    272     public char[] toString () 
    273     { 
    274         char[] result = toString (codeType) ~ " function"; 
     274    public istring toString () 
     275    { 
     276        istring result = toString (codeType) ~ " function"; 
    275277 
    276278        if (this.name_ !is null) 
     
    326328    /// Prints the Call Trace in a user-friendly way. 
    327329 
    328     public char[] toString () 
    329     { 
    330  
    331         char[] result = "* Call Trace (last function call)\n"; 
     330    public istring toString () 
     331    { 
     332 
     333        istring result = "* Call Trace (last function call)\n"; 
    332334        foreach (level, record; this.records_) 
    333335        { 
     
    371373    /// Prints the Stack Trace in a user-friendly way. 
    372374 
    373     public char[] toString () 
    374     { 
    375         char[] result = "# Stack Trace (top of stack)\n"; 
     375    public istring toString () 
     376    { 
     377        istring result = "# Stack Trace (top of stack)\n"; 
    376378        foreach_reverse (i, obj; this.objects_) 
    377379        { 
     
    401403    ***************************************************************************/ 
    402404 
    403     this (char[] message) 
    404     { 
    405         super (message); 
    406     } 
     405    this (cstring message) 
     406    { 
     407        super (cast(istring) message); 
     408    } 
     409 
     410    /// ditto 
     411    this (cstring message, cstring file, size_t line) 
     412    { 
     413        version(D_Version2) 
     414            super(cast(istring) message, cast(istring) file, line); 
     415        else 
     416            super(this.classinfo.name ~ "@" ~ file ~ "(" ~ int2string(line) ~ "): " ~ message); 
     417    } 
    407418 
    408419    /*************************************************************************** 
     
    428439            super ("Unknown Lua error"); 
    429440    } 
     441 
     442    /// ditto 
     443    this (int error, cstring file, size_t line) 
     444    { 
     445        version(D_Version2) 
     446        { 
     447            if (error == LUA_ERRRUN) 
     448                super ("Runtime error", cast(istring) file, line); 
     449            else if (error == LUA_ERRMEM) 
     450                super ("Memory allocation error", cast(istring) file, line); 
     451            else if (error == LUA_ERRERR) 
     452                super ("Error while running the error handler function", cast(istring) file, line); 
     453            else if (error == LUA_ERRFILE) 
     454                super ("Error opening the file", cast(istring) file, line); 
     455            else 
     456                super ("Unknown Lua error", cast(istring) file, line); 
     457        } 
     458        else 
     459        { 
     460            if (error == LUA_ERRRUN) 
     461                super (this.classinfo.name ~ "@" ~ file ~ "(" ~ int2string(line) ~ "): " ~ "Runtime error"); 
     462            else if (error == LUA_ERRMEM) 
     463                super (this.classinfo.name ~ "@" ~ file ~ "(" ~ int2string(line) ~ "): " ~ "Memory allocation error"); 
     464            else if (error == LUA_ERRERR) 
     465                super (this.classinfo.name ~ "@" ~ file ~ "(" ~ int2string(line) ~ "): " ~ "Error while running the error handler function"); 
     466            else if (error == LUA_ERRFILE) 
     467                super (this.classinfo.name ~ "@" ~ file ~ "(" ~ int2string(line) ~ "): " ~ "Error opening the file"); 
     468            else 
     469                super (this.classinfo.name ~ "@" ~ file ~ "(" ~ int2string(line) ~ "): " ~ "Unknown Lua error"); 
     470        } 
     471    } 
    430472} 
    431473 
     
    445487    ***************************************************************************/ 
    446488 
    447     public this (char[] message) 
    448     { 
    449         super (message); 
    450     } 
     489    public this (cstring message) 
     490    { 
     491        super (cast(istring) message); 
     492    } 
     493 
     494    /// ditto 
     495    this (cstring message, cstring file, size_t line) 
     496    { 
     497        version(D_Version2) 
     498            super(cast(istring) message, cast(istring) file, line); 
     499        else 
     500            super(this.classinfo.name ~ "@" ~ file ~ "(" ~ int2string(line) ~ "): " ~ message); 
     501    } 
    451502} 
    452503 
     
    465516    ***************************************************************************/ 
    466517 
    467     public this (char[] message) 
    468     { 
    469         super (message); 
    470     } 
    471 
    472  
    473  
    474  
    475  
    476  
     518    public this (cstring message) 
     519    { 
     520        super (cast(istring) message); 
     521    } 
     522 
     523    /// ditto 
     524    this (cstring message, cstring file, size_t line) 
     525    { 
     526        version(D_Version2) 
     527            super(cast(istring) message, cast(istring) file, line); 
     528        else 
     529            super(this.classinfo.name ~ "@" ~ file ~ "(" ~ int2string(line) ~ "): " ~ message); 
     530    } 
     531
     532 
     533 
     534 
     535 
     536// D1 phobos Exceptions are missing an "Exception next;" attribute 
    477537version (Tango) 
    478 { 
    479538    alias Exception ExtendedException; 
    480 
     539else version (D_Version2) 
     540    alias Exception ExtendedException; 
    481541else 
    482542{ 
    483543    class ExtendedException : Exception 
    484544    { 
    485     private Exception next_; 
    486      
    487     this (char[] message, Exception next) 
    488     { 
    489         this.next_ = next; 
    490         super (message); 
    491     } 
    492      
    493     this (char[] message, char[] file, int line, Exception next) 
    494     { 
    495         this.next_ = next; 
    496         super (message); 
    497     } 
     545        Exception next; 
     546        istring file; 
     547        size_t line; 
     548         
     549        this (cstring message, Exception next=null) 
     550        { 
     551            this.next = next; 
     552            super (message); 
     553        } 
     554         
     555        this (cstring message, cstring file, size_t line, Exception next=null) 
     556        { 
     557            this.next = next; 
     558            super (message); 
     559            this.file = file; 
     560            this.line = line; 
     561        } 
     562 
     563        override istring toString() 
     564        { 
     565            mstring buf; 
     566 
     567            if (this.file) 
     568            { 
     569               buf ~= this.classinfo.name ~ "@" ~ this.file ~ "(" ~ int2string(this.line) ~ "): " ~ this.msg; 
     570            } 
     571            else 
     572            { 
     573               buf ~= this.classinfo.name ~ ": " ~ this.msg; 
     574            } 
     575            buf ~= this.next.classinfo.name ~ this.next.toString(); 
     576            return cast(istring) buf; 
     577        } 
    498578    } 
    499579} 
     
    541621    ***************************************************************************/ 
    542622 
    543     public this (LuaState state, Exception exception, char[] catcher_name) 
    544     { 
    545         super (catcher_name ~ " caught:\n\n" ~ this.call_trace_.toString ~ "\n\n" ~ this.stack_trace_.toString, exception); 
     623    public this (LuaState state, Exception exception, cstring catcher_name) 
     624    { 
     625        super (cast(istring) (catcher_name ~ " caught:\n\n" ~ this.call_trace_.toString ~ "\n\n" ~ this.stack_trace_.toString), exception); 
    546626 
    547627        this.call_trace_ = new LuaCallTrace (state); 
     
    563643    ***************************************************************************/ 
    564644 
    565     public this (LuaState state, Exception exception, char[] catcher_name, char[] file, long line) 
     645    public this (LuaState state, Exception exception, cstring catcher_name, cstring file, size_t line) 
    566646    { 
    567647        this.call_trace_ = new LuaCallTrace (state); 
    568648        this.stack_trace_ = new LuaStackTrace (state); 
    569649 
    570         super (catcher_name ~ " caught:\n\n" ~ this.call_trace_.toString ~ "\n\n" ~ this.stack_trace_.toString, file, line, exception); 
     650        super (cast(istring) (catcher_name ~ " caught:\n\n" ~ this.call_trace_.toString ~ "\n\n" ~ this.stack_trace_.toString), cast(istring) file, line, exception); 
    571651    } 
    572652 
     
    580660    ***************************************************************************/ 
    581661 
    582     public void forward (char[] forwarder_name) 
    583     { 
    584         this.msg = forwarder_name ~ " forwarded, " ~ this.msg
     662    public void forward (cstring forwarder_name) 
     663    { 
     664        this.msg = cast(istring) (forwarder_name ~ " forwarded, " ~ this.msg)
    585665    } 
    586666 
  • trunk/lua/lauxlib.d

    r265 r324  
    1 module lua.lauxlib; 
     1module lua.lauxlib; 
    22 
     3private import lua.common; 
    34private import lua.lua; 
    45private import lua.luaconf; 
     
    1314struct luaL_Reg 
    1415{ 
    15     char *name; 
     16    cchar *name; 
    1617    lua_CFunction func; 
    1718} 
    1819 
    19 void  luaL_openlib(lua_State *L, char *libname, luaL_Reg *l, int nup); 
    20 void  luaL_register(lua_State *L, char *libname, luaL_Reg *l); 
    21 int  luaL_getmetafield(lua_State *L, int obj, char *e); 
    22 int  luaL_callmeta(lua_State *L, int obj, char *e); 
    23 int  luaL_typerror(lua_State *L, int narg, char *tname); 
    24 int  luaL_argerror(lua_State *L, int numarg, char *extramsg); 
    25 char * luaL_checklstring(lua_State *L, int numArg, size_t *l); 
    26 char * luaL_optlstring(lua_State *L, int numArg, char *def, size_t *l); 
     20void  luaL_openlib(lua_State *L, cchar *libname, luaL_Reg *l, int nup); 
     21void  luaL_register(lua_State *L, cchar *libname, luaL_Reg *l); 
     22int  luaL_getmetafield(lua_State *L, int obj, cchar *e); 
     23int  luaL_callmeta(lua_State *L, int obj, cchar *e); 
     24int  luaL_typerror(lua_State *L, int narg, cchar *tname); 
     25int  luaL_argerror(lua_State *L, int numarg, cchar *extramsg); 
     26ichar * luaL_checklstring(lua_State *L, int numArg, size_t *l); 
     27ichar * luaL_optlstring(lua_State *L, int numArg, cchar *def, size_t *l); 
    2728lua_Number  luaL_checknumber(lua_State *L, int numArg); 
    2829lua_Number  luaL_optnumber(lua_State *L, int nArg, lua_Number def); 
     
    3132lua_Integer  luaL_optinteger(lua_State *L, int nArg, lua_Integer def); 
    3233 
    33 void  luaL_checkstack(lua_State *L, int sz, char *msg); 
     34void  luaL_checkstack(lua_State *L, int sz, cchar *msg); 
    3435void  luaL_checktype(lua_State *L, int narg, int t); 
    3536void  luaL_checkany(lua_State *L, int narg); 
    3637 
    37 int  luaL_newmetatable(lua_State *L, char *tname); 
    38 void * luaL_checkudata(lua_State *L, int ud, char *tname); 
     38int  luaL_newmetatable(lua_State *L, cchar *tname); 
     39void * luaL_checkudata(lua_State *L, int ud, cchar *tname); 
    3940 
    4041void  luaL_where(lua_State *L, int lvl); 
    41 int  luaL_error(lua_State *L, char *fmt,...); 
     42int  luaL_error(lua_State *L, cchar *fmt,...); 
    4243 
    43 int  luaL_checkoption(lua_State *L, int narg, char *def, char **lst); 
     44int  luaL_checkoption(lua_State *L, int narg, cchar *def, cchar **lst); 
    4445 
    4546int  luaL_ref(lua_State *L, int t); 
    4647void  luaL_unref(lua_State *L, int t, int _ref); 
    4748 
    48 int  luaL_loadfile(lua_State *L, char *filename); 
    49 int  luaL_loadbuffer(lua_State *L, char *buff, size_t sz, char *name); 
    50 int  luaL_loadstring(lua_State *L, char *s); 
     49int  luaL_loadfile(lua_State *L, cchar *filename); 
     50int  luaL_loadbuffer(lua_State *L, cchar *buff, size_t sz, cchar *name); 
     51int  luaL_loadstring(lua_State *L, cchar *s); 
    5152 
    5253lua_State * luaL_newstate(); 
    5354 
    54 char * luaL_gsub(lua_State *L, char *s, char *p, char *r); 
     55ichar * luaL_gsub(lua_State *L, cchar *s, cchar *p, cchar *r); 
    5556 
    56 char * luaL_findtable(lua_State *L, int idx, char *fname, int szhint); 
     57ichar * luaL_findtable(lua_State *L, int idx, cchar *fname, int szhint); 
    5758 
    5859// some useful macros 
    5960 
    60 void luaL_argcheck(lua_State* L, int cond, int numarg, char* extramsg) { if (!cond) luaL_argerror(L, numarg, extramsg); } 
    61 char* luaL_checkstring(lua_State* L, int n) { return luaL_checklstring(L, n, null); } 
    62 char* luaL_optstring(lua_State* L, int n, char* d) { return luaL_optlstring(L, n, d, null); } 
     61void luaL_argcheck(lua_State* L, int cond, int numarg, cchar* extramsg) { if (!cond) luaL_argerror(L, numarg, extramsg); } 
     62ichar* luaL_checkstring(lua_State* L, int n) { return luaL_checklstring(L, n, null); } 
     63ichar* luaL_optstring(lua_State* L, int n, cchar* d) { return luaL_optlstring(L, n, d, null); } 
    6364int luaL_checkint(lua_State* L, int n) { return luaL_checkinteger(L, n); } 
    6465int luaL_optint (lua_State* L, int n, int d) { return luaL_optinteger(L, n, d); } 
     
    6667int luaL_optlong(lua_State* L, int n, int d) { return luaL_optinteger(L, n, d); } 
    6768 
    68 char* luaL_typename(lua_State* L, int i) { return lua_typename(L, lua_type(L, i)); } 
     69ichar* luaL_typename(lua_State* L, int i) { return lua_typename(L, lua_type(L, i)); } 
    6970 
    70 int luaL_dofile(lua_State* L, char* fn) { return luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0); } 
     71int luaL_dofile(lua_State* L, cchar* fn) { return luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0); } 
    7172 
    72 int luaL_dostring(lua_State*L, char* s) { return luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0); } 
     73int luaL_dostring(lua_State*L, cchar* s) { return luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0); } 
    7374 
    74 void luaL_getmetatable(lua_State* L, char* s) { lua_getfield(L, LUA_REGISTRYINDEX, s); } 
     75void luaL_getmetatable(lua_State* L, cchar* s) { lua_getfield(L, LUA_REGISTRYINDEX, s); } 
    7576 
    7677bool luaL_opt(lua_State* L, int function(lua_State*, int) f, int n, int d) { return luaL_opt(L, f, n, d); } 
     
    100101void  luaL_buffinit(lua_State *L, luaL_Buffer *B); 
    101102char * luaL_prepbuffer(luaL_Buffer *B); 
    102 void  luaL_addlstring(luaL_Buffer *B, char *s, size_t l); 
    103 void  luaL_addstring(luaL_Buffer *B, char *s); 
     103void  luaL_addlstring(luaL_Buffer *B, cchar *s, size_t l); 
     104void  luaL_addstring(luaL_Buffer *B, cchar *s); 
    104105void  luaL_addvalue(luaL_Buffer *B); 
    105106void  luaL_pushresult(luaL_Buffer *B); 
  • trunk/lua/lua.d

    r265 r324  
    1 module lua.lua; 
    2  
     1module lua.lua; 
     2 
     3private import lua.common; 
    34private import lua.luaconf, lua.lauxlib; 
    45 
    56extern (C): 
    67 
    7 const char[] LUA_VERSION = "Lua 5.1"; 
    8 const char[] LUA_RELEASE = "Lua 5.1.3"; 
     8const LUA_VERSION = "Lua 5.1"; 
     9const LUA_RELEASE = "Lua 5.1.4"; 
    910const LUA_VERSION_NUM = 501; 
    10 const char[] LUA_COPYRIGHT = "Copyright (C) 1994-2008 Lua.org, PUC-Rio"; 
    11 const char[] LUA_AUTHORS = "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"; 
     11const LUA_COPYRIGHT = "Copyright (C) 1994-2008 Lua.org, PUC-Rio"; 
     12const LUA_AUTHORS = "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"; 
    1213 
    1314 
    1415// mark for precompiled code (`<esc>Lua') 
    15 const char[] LUA_SIGNATURE = "\033Lua"; 
     16const LUA_SIGNATURE = "\033Lua"; 
    1617 
    1718// option for multiple returns in `lua_pcall' and `lua_call' 
     
    9192int  lua_isuserdata(lua_State *L, int idx); 
    9293int  lua_type(lua_State *L, int idx); 
    93 char * lua_typename(lua_State *L, int tp); 
     94ichar * lua_typename(lua_State *L, int tp); 
    9495int  lua_equal(lua_State *L, int idx1, int idx2); 
    9596int  lua_rawequal(lua_State *L, int idx1, int idx2); 
     
    99100lua_Integer  lua_tointeger(lua_State *L, int idx); 
    100101int  lua_toboolean(lua_State *L, int idx); 
    101 char * lua_tolstring(lua_State *L, int idx, size_t *len); 
     102ichar * lua_tolstring(lua_State *L, int idx, size_t *len); 
    102103size_t  lua_objlen(lua_State *L, int idx); 
    103104lua_CFunction  lua_tocfunction(lua_State *L, int idx); 
     
    111112void  lua_pushnumber(lua_State *L, lua_Number n); 
    112113void  lua_pushinteger(lua_State *L, lua_Integer n); 
    113 void  lua_pushlstring(lua_State *L, char *s, size_t l); 
    114 void  lua_pushstring(lua_State *L, char *s); 
    115 char * lua_pushvfstring(lua_State *L, char *fmt, ...); 
    116 char * lua_pushfstring(lua_State *L, char *fmt,...); 
     114void  lua_pushlstring(lua_State *L, cchar *s, size_t l); 
     115void  lua_pushstring(lua_State *L, cchar *s); 
     116ichar * lua_pushvfstring(lua_State *L, cchar *fmt, ...); 
     117ichar * lua_pushfstring(lua_State *L, cchar *fmt,...); 
    117118void  lua_pushcclosure(lua_State *L, lua_CFunction fn, int n); 
    118119void  lua_pushboolean(lua_State *L, int b); 
     
    122123// get functions (Lua -> stack) 
    123124void  lua_gettable(lua_State *L, int idx); 
    124 void  lua_getfield(lua_State *L, int idx, char *k); 
     125void  lua_getfield(lua_State *L, int idx, cchar *k); 
    125126void  lua_rawget(lua_State *L, int idx); 
    126127void  lua_rawgeti(lua_State *L, int idx, int n); 
     
    132133// set functions (stack -> Lua) 
    133134void  lua_settable(lua_State *L, int idx); 
    134 void  lua_setfield(lua_State *L, int idx, char *k); 
     135void  lua_setfield(lua_State *L, int idx, cchar *k); 
    135136void  lua_rawset(lua_State *L, int idx); 
    136137void  lua_rawseti(lua_State *L, int idx, int n); 
     
    142143int  lua_pcall(lua_State *L, int nargs, int nresults, int errfunc); 
    143144int  lua_cpcall(lua_State *L, lua_CFunction func, void *ud); 
    144 int  lua_load(lua_State *L, lua_Reader reader, void *dt, char *chunkname); 
     145int  lua_load(lua_State *L, lua_Reader reader, void *dt, cchar *chunkname); 
    145146int  lua_dump(lua_State *L, lua_Writer writer, void *data); 
    146147 
     
    188189void lua_setglobal(lua_State* L, char* s) { lua_setfield(L, LUA_GLOBALSINDEX, s); } 
    189190void lua_getglobal(lua_State* L, char* s) { lua_getfield(L, LUA_GLOBALSINDEX, s); } 
    190 char* lua_tostring(lua_State* L, int i) { return lua_tolstring(L, i, null); } 
     191ichar* lua_tostring(lua_State* L, int i) { return lua_tolstring(L, i, null); } 
    191192 
    192193// compatibility macros and functions 
     
    219220 
    220221int  lua_getstack(lua_State *L, int level, lua_Debug *ar); 
    221 int  lua_getinfo(lua_State *L, char *what, lua_Debug *ar); 
    222 char * lua_getlocal(lua_State *L, lua_Debug *ar, int n); 
    223 char * lua_setlocal(lua_State *L, lua_Debug *ar, int n); 
    224 char * lua_getupvalue(lua_State *L, int funcindex, int n); 
    225 char * lua_setupvalue(lua_State *L, int funcindex, int n); 
     222int  lua_getinfo(lua_State *L, cchar *what, lua_Debug *ar); 
     223ichar * lua_getlocal(lua_State *L, lua_Debug *ar, int n); 
     224ichar * lua_setlocal(lua_State *L, lua_Debug *ar, int n); 
     225ichar * lua_getupvalue(lua_State *L, int funcindex, int n); 
     226ichar * lua_setupvalue(lua_State *L, int funcindex, int n); 
    226227int  lua_sethook(lua_State *L, lua_Hook func, int mask, int count); 
    227228lua_Hook  lua_gethook(lua_State *L); 
  • trunk/lua/luaconf.d

    r265 r324  
    1 module lua.luaconf; 
     1module lua.luaconf; 
    22 
    33extern (C): 
  • trunk/lua/lualib.d

    r265 r324  
    1 module lua.lualib; 
     1module lua.lualib; 
    22 
    33private import lua.lua; 
     
    55extern (C): 
    66 
    7 const char[] LUA_FILEHANDLE = "FILE*"; 
    8 const char[] LUA_COLIBNAME = "coroutine"; 
     7const LUA_FILEHANDLE = "FILE*"; 
     8const LUA_COLIBNAME = "coroutine"; 
    99int  luaopen_base(lua_State *L); 
    10 const char[] LUA_TABLIBNAME = "table"; 
     10const LUA_TABLIBNAME = "table"; 
    1111int  luaopen_table(lua_State *L); 
    12 const char[] LUA_IOLIBNAME = "io"; 
     12const LUA_IOLIBNAME = "io"; 
    1313int  luaopen_io(lua_State *L); 
    14 const char[] LUA_OSLIBNAME = "os"; 
     14const LUA_OSLIBNAME = "os"; 
    1515int  luaopen_os(lua_State *L); 
    16 const char[] LUA_STRLIBNAME = "string"; 
     16const LUA_STRLIBNAME = "string"; 
    1717int  luaopen_string(lua_State *L); 
    18 const char[] LUA_MATHLIBNAME = "math"; 
     18const LUA_MATHLIBNAME = "math"; 
    1919int  luaopen_math(lua_State *L); 
    20 const char[] LUA_DBLIBNAME = "debug"; 
     20const LUA_DBLIBNAME = "debug"; 
    2121int  luaopen_debug(lua_State *L); 
    22 const char[] LUA_LOADLIBNAME = "package"; 
     22const LUA_LOADLIBNAME = "package"; 
    2323int  luaopen_package(lua_State *L); 
    2424 
  • trunk/lua/mixins.d

    r314 r324  
    1 /******************************************************************************* 
     1/******************************************************************************* 
    22 
    33    copyright:      Copyright (c) 2008 Matthias Walter. All rights reserved 
     
    99module lua.mixins; 
    1010 
    11 public import lua.error : LuaForwardException; 
    12 private import lua.utils : rfind, ltrim, removeFirst, join; 
    13 public import lua.utils : int2string; 
    14 public import lua.lauxlib : luaL_error; 
    15 public import lua.lua : lua_State; 
     11private import lua.common; 
     12public import lua.error; 
     13private import lua.utils; 
     14public import lua.utils; 
     15public import lua.lauxlib; 
     16private import lua.lua; 
    1617 
    1718/******************************************************************************* 
     
    2122*******************************************************************************/ 
    2223 
    23 public static char[] mangleClass (char[] class_name) 
    24 { 
    25     char[] result = "d_class_" ~ class_name; 
     24public static mstring mangleClass (cstring class_name) 
     25{ 
     26    mstring result = "d_class_" ~ class_name; 
    2627    foreach (i, c; result) 
    2728    { 
     
    3839*******************************************************************************/ 
    3940 
    40 public static char[] mangleFunction (char[] function_name) 
    41 { 
    42     char[] result = "d_function_" ~ function_name; 
     41public static mstring mangleFunction (cstring function_name) 
     42{ 
     43    mstring result = "d_function_" ~ function_name; 
    4344    foreach (i, c; result) 
    4445    { 
     
    6364*******************************************************************************/ 
    6465 
    65 public static char[] mixinLuaRegisterMethodAtLine (char[] lua_state, char[] class_name, char[] method_name, char[] lua_name, int line_number) 
    66 
    67     char[] wrapper = `lua_wrapper_` ~ mangleClass (class_name) ~ "_" ~ method_name ~ "_" ~ int2string (line_number); 
    68  
    69     return `` 
    70         ~ `{` 
     66public static istring mixinLuaRegisterMethodAtLine (cstring lua_state, cstring class_name, cstring method_name, cstring lua_name, int line_number) 
     67
     68    istring wrapper = cast(istring) (`lua_wrapper_` ~ mangleClass (class_name) ~ "_" ~ method_name ~ "_" ~ int2string (line_number)); 
     69 
     70    return cast(istring) (`{` 
    7171        ~ `  extern (C) static int ` ~ wrapper ~ ` (lua_State *L)` 
    7272        ~ `  {` 
     
    7575        ~ `    {` 
    7676        ~ `      void* userdata = luaL_checkudata (L, 1, "` ~ mangleClass (class_name) ~ `");` // Check, whether it's the correct userdata 
    77         ~ `      luaL_argcheck (L, userdata != null, 1, "class pointer expected");` 
     77        ~ `      luaL_argcheck (L, userdata !is null, 1, "class pointer expected");` 
    7878        ~ `      lua_remove (L, 1);` // Remove the userdata 
    79         ~ `      return (cast (` ~class_name ~ ` *) userdata).` ~ method_name ~ ` (LuaState.states[L]);` // Call the wrapped 
     79        ~ `      return (cast (` ~class_name ~ ` *) userdata).` ~ method_name ~ ` (state);` // Call the wrapped 
    8080        ~ `    }` 
    8181        ~ `    catch (Exception e)` 
     
    8383        ~ `      auto f = new LuaForwardException (state, e, "` ~ class_name ~ `.` ~ method_name ~ `", __FILE__, __LINE__);` 
    8484        ~ `      LuaForwardException.exceptions[cast (void*) f] = f;` 
    85         ~ `      return luaL_error (L, lua.utils.toStringz ("LFE=" ~ lua.mixins.int2string (cast (ulong) cast(void*)  f) ~ ";"));` 
     85        ~ `      return luaL_error (L, lua.utils.toStringz ("LFE=" ~ lua.mixins.int2string (cast (size_t) cast(void*)  f) ~ ";"));` 
    8686        ~ `    }` 
    8787        ~ `  }` 
     
    8989        ~ `  ` ~ lua_state ~ `.registerMethod ("` ~ lua_name ~ `", cast (LuaCFunction) &` ~ wrapper ~ `);` 
    9090        ~ `  ` ~ lua_state ~ `.pop ();` 
    91         ~ `}`
     91        ~ `}`)
    9292} 
    9393 
     
    126126*******************************************************************************/ 
    127127 
    128 public static char[] mixinLuaRegisterMethod (char[] lua_state, char[] class_dot_method, char[] lua_name) 
     128public static istring mixinLuaRegisterMethod (cstring lua_state, cstring class_dot_method, cstring lua_name) 
    129129{ 
    130130    int pos = rfind (class_dot_method, '.'); 
    131     char[] class_name = class_dot_method [0 .. pos]; 
    132     char[] method_name = class_dot_method [pos+1 .. $]; 
    133  
    134     return `mixin (mixinLuaRegisterMethodAtLine ("` ~ lua_state ~ `", "` ~ class_name ~ `", "` ~ method_name ~ `", "` ~ lua_name ~ `", __LINE__));`; 
     131    cstring class_name = class_dot_method [0 .. pos]; 
     132    cstring method_name = class_dot_method [pos+1 .. $]; 
     133    return cast(istring) (`mixin (mixinLuaRegisterMethodAtLine ("` ~ lua_state ~ `", "` ~ class_name ~ `", "` ~ method_name ~ `", "` ~ lua_name ~ `", __LINE__));`); 
    135134} 
    136135 
     
    148147*******************************************************************************/ 
    149148 
    150 public static char[] mixinLuaPushFunctionAtLine (char[] lua_state, char[] name, int line_number) 
    151 { 
    152     char[] wrapper = "lua_wrapper_" ~ mangleFunction (name) ~ "_" ~ int2string (line_number); 
    153  
    154     return `` 
     149public static istring mixinLuaPushFunctionAtLine (cstring lua_state, cstring name, int line_number) 
     150{ 
     151    istring wrapper = cast(istring) ("lua_wrapper_" ~ mangleFunction (name) ~ "_" ~ int2string (line_number)); 
     152 
     153    return cast(istring) (`` 
    155154        ~ `{` 
    156155        ~ `  extern (C) static int `  ~ wrapper ~ ` (lua_State *L)` 
     
    165164        ~ `      auto f = new LuaForwardException (state, e, "` ~ name ~ `", __FILE__, __LINE__);` 
    166165        ~ `      LuaForwardException.exceptions[cast (void*) f] = f;` 
    167         ~ `      return luaL_error (L, lua.utils.toStringz ("LFE=" ~ lua.mixins.int2string (cast (ulong) cast(void*)  f) ~ ";"));` 
     166        ~ `      return luaL_error (L, lua.utils.toStringz ("LFE=" ~ lua.mixins.int2string (cast (size_t) cast(void*)  f) ~ ";"));` 
    168167        ~ `    }` 
    169168        ~ `  }` 
    170169        ~ `  ` ~ lua_state ~ `.pushCFunction (cast (int function (lua_State *L)) &` ~ wrapper ~ `);` 
    171         ~ `}`
     170        ~ `}`)
    172171} 
    173172 
     
    198197*******************************************************************************/ 
    199198 
    200 public static char[] mixinLuaPushFunction (char[] lua_state, char[] name) 
    201 { 
    202     return `mixin (mixinLuaPushFunctionAtLine ("` ~ lua_state ~ `", "` ~ name ~ `", __LINE__));`
     199public static istring mixinLuaPushFunction (cstring lua_state, cstring name) 
     200{ 
     201    return cast(istring) (`mixin (mixinLuaPushFunctionAtLine ("` ~ lua_state ~ `", "` ~ name ~ `", __LINE__));`)
    203202} 
    204203 
     
    217216*******************************************************************************/ 
    218217 
    219 public static char[] mixinLuaRegisterFunctionAtLine (char[] lua_state, char[] name, char[] lua_library_dot_name, int line_number) 
     218public static istring mixinLuaRegisterFunctionAtLine (cstring lua_state, cstring name, cstring lua_library_dot_name, int line_number) 
    220219{ 
    221220    int pos = rfind (lua_library_dot_name, '.'); 
    222     char[] lua_library = pos < 0 ? "null" : "\"" ~ lua_library_dot_name[0 .. pos] ~ "\""; 
    223     char[] lua_function = lua_library_dot_name[pos+1 .. $]; 
    224     char[] wrapper = "lua_wrapper_" ~ mangleFunction (name) ~ "_" ~ int2string (line_number); 
    225  
    226     return `` 
     221    cstring lua_library = pos < 0 ? "null" : "\"" ~ lua_library_dot_name[0 .. pos] ~ "\""; 
     222    cstring lua_function = lua_library_dot_name[pos+1 .. $]; 
     223    cstring wrapper = "lua_wrapper_" ~ mangleFunction (name) ~ "_" ~ int2string (line_number); 
     224 
     225    return cast(istring) (`` 
    227226        ~ `{` 
    228227        ~ `  extern (C) static int `  ~ wrapper ~ ` (lua_State* L)` 
     
    237236        ~ `      auto f = new LuaForwardException (state, e, "` ~ name ~ `", __FILE__, __LINE__);` 
    238237        ~ `      LuaForwardException.exceptions[cast (void*) f] = f;` 
    239         ~ `      return luaL_error (L, lua.utils.toStringz ("LFE=" ~ lua.mixins.int2string (cast (ulong) cast(void*)  f) ~ ";"));` 
     238        ~ `      return luaL_error (L, lua.utils.toStringz ("LFE=" ~ lua.mixins.int2string (cast (size_t) cast(void*)  f) ~ ";"));` 
    240239        ~ `    }` 
    241240        ~ `  }` 
    242241        ~ `  ` ~ lua_state ~ `.registerFunction ("` ~ lua_function ~ `", cast (int function (lua_State* L)) &` ~ wrapper ~ `, ` ~ lua_library ~ `);` 
    243         ~ `}`
     242        ~ `}`)
    244243} 
    245244 
     
    271270*******************************************************************************/ 
    272271 
    273 public static char[] mixinLuaRegisterFunction (char[] lua_state, char[] name, char[] lua_library_dot_name) 
    274 { 
    275     return `mixin (mixinLuaRegisterFunctionAtLine ("` ~ lua_state ~ `", "` ~ name ~ `", "` ~ lua_library_dot_name ~ `", __LINE__));`
     272public static istring mixinLuaRegisterFunction (cstring lua_state, cstring name, cstring lua_library_dot_name) 
     273{ 
     274    return cast(istring) (`mixin (mixinLuaRegisterFunctionAtLine ("` ~ lua_state ~ `", "` ~ name ~ `", "` ~ lua_library_dot_name ~ `", __LINE__));`)
    276275} 
    277276 
     
    290289*******************************************************************************/ 
    291290 
    292 public static char[] mixinLuaRegisterConstructorAtLine (char[] lua_state, char[] class_name, char[] lua_library_dot_name, int line_number) 
     291public static istring mixinLuaRegisterConstructorAtLine (cstring lua_state, cstring class_name, cstring lua_library_dot_name, int line_number) 
    293292{ 
    294293    int pos = rfind (lua_library_dot_name, '.'); 
    295     char[] lua_library = pos < 0 ? "" : "\"" ~ lua_library_dot_name[0 .. pos] ~ "\""; 
    296     char[] lua_function = lua_library_dot_name[pos+1 .. $]; 
    297     char[] wrapper = "lua_wrapper_" ~ mangleClass (class_name) ~ "_ctor_" ~ int2string (line_number); 
    298  
    299     return `` 
     294    cstring lua_library = pos < 0 ? "" : "\"" ~ lua_library_dot_name[0 .. pos] ~ "\""; 
     295    cstring lua_function = lua_library_dot_name[pos+1 .. $]; 
     296    cstring wrapper = "lua_wrapper_" ~ mangleClass (class_name) ~ "_ctor_" ~ int2string (line_number); 
     297 
     298    return cast(istring) (`` 
    300299        ~ `{` 
    301300        ~ `  extern (C) static int ` ~ wrapper ~ ` (lua_State *L)` 
     
    312311        ~ `      auto f = new LuaForwardException (state, e, "` ~ class_name ~ `.this", __FILE__, __LINE__);` 
    313312        ~ `      LuaForwardException.exceptions[cast (void*) f] = f;` 
    314         ~ `      return luaL_error (L, lua.utils.toStringz ("LFE=" ~ lua.mixins.int2string (cast (ulong) cast(void*)  f) ~ ";"));` 
     313        ~ `      return luaL_error (L, lua.utils.toStringz ("LFE=" ~ lua.mixins.int2string (cast (size_t) cast(void*)  f) ~ ";"));` 
    315314        ~ `    }` 
    316315        ~ `  }` 
    317316        ~ `  ` ~ lua_state ~ `.registerFunction ("` ~ lua_function ~ `", cast (int function (lua_State *L)) &` ~ wrapper ~ `, ` ~ lua_library ~ `);` 
    318         ~ `}`
     317        ~ `}`)
    319318} 
    320319 
     
    351350*******************************************************************************/ 
    352351 
    353 public static char[] mixinLuaRegisterConstructor (char[] lua_state, char[] class_name, char[] lua_library_dot_name) 
    354 { 
    355     return `mixin (mixinLuaRegisterConstructorAtLine ("` ~ lua_state ~ `", "` ~ class_name ~ `", "` ~ lua_library_dot_name ~ `", __LINE__));`
    356 } 
     352public static istring mixinLuaRegisterConstructor (cstring lua_state, cstring class_name, cstring lua_library_dot_name) 
     353{ 
     354    return cast(istring) (`mixin (mixinLuaRegisterConstructorAtLine ("` ~ lua_state ~ `", "` ~ class_name ~ `", "` ~ lua_library_dot_name ~ `", __LINE__));`)
     355} 
  • trunk/lua/state.d

    r314 r324  
    1 /******************************************************************************* 
    2  
    3     copyright:      Copyright (c) 2008 Matthias Walter. All rights reserved 
    4  
    5     authors:        Matthias Walter, Andreas Hollandt, Clemens Hofreither 
     1/******************************************************************************* 
     2 
     3    copyright: Copyright (c) 2008 Matthias Walter. All rights reserved 
     4 
     5   authors:    Matthias Walter, Andreas Hollandt, Clemens Hofreither 
    66 
    77*******************************************************************************/ 
     
    99module lua.state; 
    1010 
     11private import lua.common; 
    1112private import lua.lua, lua.lualib, lua.lauxlib; 
    1213private import lua.buffer, lua.mixins, lua.error, lua.data, lua.utils; 
     
    1617    private import tango.stdc.stdio : fputs, stdout; 
    1718} 
    18  
    19 version (Phobos) 
     19else 
    2020{ 
    21     private import std.string : fputs, stdout; 
     21   private import std.string : fputs, stdout; 
    2222} 
    2323 
     
    3434public enum LuaStandardLibraries : int 
    3535{ 
    36     BASE = 0, 
    37     TABLE = 1, 
    38     STRING = 2, 
    39     MATH = 4, 
    40     OS = 8, 
    41     IO = 16, 
    42     DEBUG = 32, 
    43     PACKAGE = 64, 
    44     SAFE = BASE | TABLE | STRING | MATH | OS | PACKAGE, 
    45     ALL = BASE | TABLE | STRING | MATH | OS | PACKAGE | IO | DEBUG 
     36   BASE = 0, 
     37   TABLE = 1, 
     38   STRING = 2, 
     39   MATH = 4, 
     40   OS = 8, 
     41   IO = 16, 
     42   DEBUG = 32, 
     43   PACKAGE = 64, 
     44   SAFE = BASE | TABLE | STRING | MATH | OS | PACKAGE, 
     45   ALL = BASE | TABLE | STRING | MATH | OS | PACKAGE | IO | DEBUG 
    4646} 
    4747 
     
    5454public enum LuaType : int 
    5555{ 
    56     NONE = LUA_TNONE, 
    57     NIL = LUA_TNIL, 
    58     NUMBER = LUA_TNUMBER, 
    59     BOOL = LUA_TBOOLEAN, 
    60     STRING = LUA_TSTRING, 
    61     TABLE = LUA_TTABLE, 
    62     FUNCTION = LUA_TFUNCTION, 
    63     USERDATA = LUA_TUSERDATA, 
    64     THREAD = LUA_TTHREAD, 
    65     LIGHTUSERDATA = LUA_TLIGHTUSERDATA 
     56   NONE = LUA_TNONE, 
     57   NIL = LUA_TNIL, 
     58   NUMBER = LUA_TNUMBER, 
     59   BOOL = LUA_TBOOLEAN, 
     60   STRING = LUA_TSTRING, 
     61   TABLE = LUA_TTABLE, 
     62   FUNCTION = LUA_TFUNCTION, 
     63   USERDATA = LUA_TUSERDATA, 
     64   THREAD = LUA_TTHREAD, 
     65   LIGHTUSERDATA = LUA_TLIGHTUSERDATA 
    6666} 
    6767 
     
    7575public enum LuaGarbageCollectorCommand : int 
    7676{ 
    77     STOP = LUA_GCSTOP, 
    78     RESTART = LUA_GCRESTART, 
    79     COLLECT = LUA_GCCOLLECT, 
    80     COUNT = LUA_GCCOUNT, 
    81     STEP = LUA_GCSTEP, 
    82     SET_PAUSE = LUA_GCSETPAUSE, 
    83     SET_STEP_MULTIPLIER = LUA_GCSETSTEPMUL 
     77   STOP = LUA_GCSTOP, 
     78   RESTART = LUA_GCRESTART, 
     79   COLLECT = LUA_GCCOLLECT, 
     80   COUNT = LUA_GCCOUNT, 
     81   STEP = LUA_GCSTEP, 
     82   SET_PAUSE = LUA_GCSETPAUSE, 
     83   SET_STEP_MULTIPLIER = LUA_GCSETSTEPMUL 
    8484} 
    8585 
     
    100100struct LuaRegistry 
    101101{ 
    102     char[] name; 
    103     LuaCFunction cfunction; 
    104     int category; 
     102   istring name; 
     103   LuaCFunction cfunction; 
     104   int category; 
    105105} 
    106106 
    107107/// Delegate type for redirecting Lua's stdout to the D host program. 
    108108 
    109 alias void delegate (char[] output) LuaPrint; 
     109alias void delegate (cstring output) LuaPrint; 
    110110 
    111111/******************************************************************************* 
     
    140140{ 
    141141    /// Wrapper Lua state 
    142     private lua_State* state_; 
    143  
    144     /// Writer delegate, the Lua stdout 
    145     private LuaPrint write_; 
    146      
    147     /// Whether the LuaState was created as a sub-thread of another state by calling newThread(). 
     142   private lua_State* state_; 
     143 
     144   /// Writer delegate, the Lua stdout 
     145   private LuaPrint write_; 
     146     
     147   /// Whether the LuaState was created as a sub-thread of another state by calling newThread(). 
    148148    private bool is_thread_state_; 
    149149 
    150     /// Constant to pass instead of a number of expected results, if this number is unknown. 
    151     public const int MULTIPLE_RETURN_VALUES = LUA_MULTRET; 
    152  
    153     /******************************************************************************* 
     150   /// Constant to pass instead of a number of expected results, if this number is unknown. 
     151   public const int MULTIPLE_RETURN_VALUES = LUA_MULTRET; 
     152 
     153   /******************************************************************************* 
    154154 
    155155        Constructs a state with an optional printer delegate. If the latter is 
     
    162162        Replaces lua_open, lua_newstate and luaL_newstate. 
    163163 
    164     *******************************************************************************/ 
    165  
    166     public this (LuaPrint write = null) 
    167    
    168       this.state_ = lua_open (); 
    169       this.write_ = (write is null) ? &writeDefault : write; 
    170  
    171       openLibraries (LuaStandardLibraries.BASE); 
    172  
    173       LuaState.states[this.state_] = this; 
    174    
    175  
    176     /******************************************************************************* 
     164    *******************************************************************************/ 
     165 
     166   public this (LuaPrint write = null) 
     167   
     168      this.state_ = lua_open (); 
     169      this.write_ = (write is null) ? &writeDefault : write; 
     170 
     171      openLibraries (LuaStandardLibraries.BASE); 
     172 
     173      LuaState.states[this.state_] = this; 
     174   
     175 
     176   /******************************************************************************* 
    177177 
    178178        Internal Constructor for Lua thread creation. 
     
    182182        state = Lua state 
    183183 
    184     *******************************************************************************/ 
    185  
    186     private this (LuaPrint write, lua_State* state) 
    187    
     184   *******************************************************************************/ 
     185 
     186   private this (LuaPrint write, lua_State* state) 
     187   
    188188        this.write_ = write; 
    189189        this.state_ = state; 
    190190 
    191191        LuaState.states[this.state_] = this; 
    192    
    193  
    194     /******************************************************************************* 
     192   
     193 
     194   /******************************************************************************* 
    195195 
    196196        Destructor 
     
    199199        Replaces lua_close. 
    200200 
    201     *******************************************************************************/ 
    202  
    203     private ~this () 
    204    
    205       LuaState.states.remove (this.state_); 
    206  
    207       // bugfix by Clemens: 
    208       // states which represent child threads may not be destroyed 
     201   *******************************************************************************/ 
     202 
     203   private ~this () 
     204   
     205      LuaState.states.remove (this.state_); 
     206 
     207      // bugfix by Clemens: 
     208      // states which represent child threads may not be destroyed 
    209209        if (!is_thread_state_) 
    210210        { 
    211211            lua_close (this.state_); 
    212212        } 
    213    
    214  
    215     /******************************************************************************* 
     213   
     214 
     215   /******************************************************************************* 
    216216 
    217217        Returns: 
     
    222222        most functionality there should be a corresponding wrapper function. 
    223223 
    224     *******************************************************************************/ 
    225  
    226     public lua_State* state () 
    227    
    228       return this.state_; 
    229    
    230  
    231     /******************************************************************************* 
     224   *******************************************************************************/ 
     225 
     226   public lua_State* state () 
     227   
     228      return this.state_; 
     229   
     230 
     231   /******************************************************************************* 
    232232 
    233233        Opens the specified standard libraries and adds their functionality to this state. 
     
    240240        Replaces luaL_openlibs. 
    241241 
    242     *******************************************************************************/ 
    243  
    244     public LuaState openLibraries (LuaStandardLibraries categories = LuaStandardLibraries.ALL) 
    245    
     242   *******************************************************************************/ 
     243 
     244   public LuaState openLibraries (LuaStandardLibraries categories = LuaStandardLibraries.ALL) 
     245   
    246246        static LuaRegistry[] lualibs = [ 
    247             { "", &luaopen_base, LuaStandardLibraries.BASE }, 
    248             { LUA_TABLIBNAME, &luaopen_table, LuaStandardLibraries.TABLE }, 
    249             { LUA_IOLIBNAME, &luaopen_io, LuaStandardLibraries.IO }, 
    250             { LUA_OSLIBNAME, &luaopen_os, LuaStandardLibraries.OS }, 
    251             { LUA_STRLIBNAME, &luaopen_string, LuaStandardLibraries.STRING }, 
    252             { LUA_MATHLIBNAME, &luaopen_math, LuaStandardLibraries.MATH }, 
    253             { LUA_DBLIBNAME, &luaopen_debug, LuaStandardLibraries.DEBUG }, 
    254             { LUA_LOADLIBNAME, &luaopen_package, LuaStandardLibraries.PACKAGE } 
     247            { "", &luaopen_base, LuaStandardLibraries.BASE }, 
     248            { LUA_TABLIBNAME, &luaopen_table, LuaStandardLibraries.TABLE }, 
     249            { LUA_IOLIBNAME, &luaopen_io, LuaStandardLibraries.IO }, 
     250            { LUA_OSLIBNAME, &luaopen_os, LuaStandardLibraries.OS }, 
     251            { LUA_STRLIBNAME, &luaopen_string, LuaStandardLibraries.STRING }, 
     252            { LUA_MATHLIBNAME, &luaopen_math, LuaStandardLibraries.MATH }, 
     253            { LUA_DBLIBNAME, &luaopen_debug, LuaStandardLibraries.DEBUG }, 
     254            { LUA_LOADLIBNAME, &luaopen_package, LuaStandardLibraries.PACKAGE } 
    255255        ]; 
    256256 
     
    260260 
    261261        return this; 
    262    
    263  
    264     /******************************************************************************* 
     262   
     263 
     264   /******************************************************************************* 
    265265 
    266266        Opens all of the given libraries, which match the given categories bits, 
     
    271271        categories = Choice to open. Default is -1, which opens all. 
    272272 
    273     *******************************************************************************/ 
    274  
    275     public LuaState openLibraries (LuaRegistry[] libraries, int categories = -1) 
    276    
     273   *******************************************************************************/ 
     274 
     275   public LuaState openLibraries (LuaRegistry[] libraries, int categories = -1) 
     276   
    277277        foreach (LuaRegistry reg; libraries) 
    278       { 
    279             if (reg.category == 0 || (reg.category & categories) != 0) 
    280            
    281                 openLibrary (reg.name, reg.cfunction); 
    282            
    283        
    284         return this; 
    285    
    286  
    287     /******************************************************************************* 
     278      { 
     279           if (reg.category == 0 || (reg.category & categories) != 0) 
     280           
     281               openLibrary (reg.name, reg.cfunction); 
     282           
     283       
     284        return this; 
     285   
     286 
     287   /******************************************************************************* 
    288288 
    289289        Opens one library, adding its functionality to this state. The 
     
    295295        registration_function = C-linkage function to call for registration 
    296296 
    297     ******************************************************************************/ 
    298  
    299     public LuaState openLibrary (char[] library_name, LuaCFunction registration_function) 
    300    
     297   ******************************************************************************/ 
     298 
     299   public LuaState openLibrary (cstring library_name, LuaCFunction registration_function) 
     300   
    301301        pushCFunction (registration_function); 
    302302        pushString (library_name); 
     
    304304 
    305305        return this; 
    306    
    307  
    308     /******************************************************************************* 
     306   
     307 
     308   /******************************************************************************* 
    309309 
    310310        Internal method to pass the given data to the writer delegate. 
     
    313313        data = Output to write. 
    314314 
    315     ******************************************************************************/ 
    316  
    317     private void write (char[] data) 
    318    
    319         this.write_ (data); 
    320    
    321  
    322     /******************************************************************************* 
     315   ******************************************************************************/ 
     316 
     317   private void write (cstring data) 
     318   
     319       this.write_ (data); 
     320   
     321 
     322   /******************************************************************************* 
    323323 
    324324        Standard writer function, if none is specified in Constructor. 
     
    327327        output = Output to write. 
    328328 
    329     ******************************************************************************/ 
    330  
    331     private void writeDefault (char[] output) 
    332    
    333       fputs (toStringz (output), stdout); 
    334    
    335  
    336     /******************************************************************************* 
     329   ******************************************************************************/ 
     330 
     331   private void writeDefault (cstring output) 
     332   
     333      fputs (toStringz (output), stdout); 
     334   
     335 
     336   /******************************************************************************* 
    337337 
    338338        Calls the C function with only one element in its stack, a LightUserdata, 
     
    349349        Replaces lua_cpcall. 
    350350 
    351     ******************************************************************************/ 
    352  
    353     public LuaState call (bool protection, LuaCFunction cfunction, void* userdata) 
    354    
    355       pushCFunction (cfunction); 
    356       pushLightUserdata (userdata); 
    357       call (protection, 1, 0); 
    358  
    359         return this; 
    360    
    361  
    362     /******************************************************************************* 
     351   ******************************************************************************/ 
     352 
     353   public LuaState call (bool protection, LuaCFunction cfunction, void* userdata) 
     354   
     355      pushCFunction (cfunction); 
     356      pushLightUserdata (userdata); 
     357      call (protection, 1, 0); 
     358 
     359        return this; 
     360   
     361 
     362   /******************************************************************************* 
    363363 
    364364        Method to call a Lua function, using the following protocol: 
     
    410410        Replaces lua_call and lua_pcall. 
    411411 
    412     ******************************************************************************/ 
    413  
    414     public LuaState call (bool protection, uint arguments = 0, int results = MULTIPLE_RETURN_VALUES) 
    415    
     412   ******************************************************************************/ 
     413 
     414   public LuaState call (bool protection, uint arguments = 0, int results = MULTIPLE_RETURN_VALUES) 
     415   
    416416        if (protection) 
    417417        { 
    418             int errors = lua_pcall (this.state_, arguments, results, 0); 
    419             if (errors != 0) 
    420            
    421                char[] error = popString (); 
     418           int errors = lua_pcall (this.state_, arguments, results, 0); 
     419           if (errors != 0) 
     420           
     421               istring error = popString (); 
    422422 
    423423                // parse the error string to extract the address of the exception 
    424                 char[] pointer_string = null; 
     424                istring pointer_string = null; 
    425425                for (int start = error.length-6; start >= 0; start--) 
    426426                { 
    427                     if (error[start .. start + 4] == "LFE=") 
    428                    
     427                   if (error[start .. start + 4] == "LFE=") 
     428                   
    429429                        for (int end = start+5; end < error.length; end++) 
    430430                        { 
    431                             if (error[end] == ';') 
    432                            
    433                               pointer_string = error[start+4 .. end]; 
    434                               break; 
    435                            
     431                           if (error[end] == ';') 
     432                           
     433                              pointer_string = error[start+4 .. end]; 
     434                              break; 
     435                           
    436436                        } 
    437437                        break; 
    438                    
     438                   
    439439                } 
    440440 
    441                 if (pointer_string != null) 
     441                if (pointer_string !is null) 
    442442                { 
    443                     void* p = cast (void*) string2int !(ulong) (pointer_string); 
    444                     LuaForwardException e = LuaForwardException.exceptions[p]; 
    445                     LuaForwardException.exceptions.remove (p); 
    446                     e.forward ("LuaState.call"); 
    447                     throw e; 
     443                   void* p = cast (void*) string2int !(size_t) (pointer_string); 
     444                   LuaForwardException e = LuaForwardException.exceptions[p]; 
     445                   LuaForwardException.exceptions.remove (p); 
     446                   e.forward ("LuaState.call"); 
     447                   throw e; 
    448448                } 
    449449                else 
    450450                { 
    451                     throw new LuaCodeException (error); 
     451                   throw new LuaCodeException (error, __FILE__, __LINE__); 
    452452                } 
    453            
     453           
    454454        } 
    455455        else 
    456456        { 
    457             lua_call (this.state_, arguments, results); 
     457           lua_call (this.state_, arguments, results); 
    458458        } 
    459459 
    460460        return this; 
    461    
    462  
    463     /******************************************************************************* 
     461   
     462 
     463   /******************************************************************************* 
    464464 
    465465        Loads and runs the given string. 
     
    475475        Replaces luaL_dostring. 
    476476 
    477     ******************************************************************************/ 
    478  
    479     public LuaState doString (bool protection, char[] code, uint arguments = 0, int results = MULTIPLE_RETURN_VALUES, char[] chunk_name = null) 
    480    
    481       load (code, chunk_name); 
    482  
    483       return call (protection, arguments, results); 
    484    
    485  
    486     /// ditto 
    487  
    488     public LuaState doString (bool protection, char[] code, char[] chunk_name, uint arguments = 0, int results = MULTIPLE_RETURN_VALUES) 
    489    
    490       return doString (protection, code, arguments, results, chunk_name); 
    491    
    492  
    493     /******************************************************************************* 
     477   ******************************************************************************/ 
     478 
     479   public LuaState doString (bool protection, cstring code, uint arguments = 0, int results = MULTIPLE_RETURN_VALUES, cstring chunk_name = null) 
     480   
     481      load (code, chunk_name); 
     482 
     483      return call (protection, arguments, results); 
     484   
     485 
     486   /// ditto 
     487 
     488   public LuaState doString (bool protection, cstring code, cstring chunk_name, uint arguments = 0, int results = MULTIPLE_RETURN_VALUES) 
     489   
     490      return doString (protection, code, arguments, results, chunk_name); 
     491   
     492 
     493   /******************************************************************************* 
    494494 
    495495        Loads and runs the given file. 
     
    504504        Replaces luaL_dofile. 
    505505 
    506     ******************************************************************************/ 
    507  
    508     public LuaState doFile (bool protection, char[] filename, uint arguments = 0, int results = MULTIPLE_RETURN_VALUES) 
    509    
     506   ******************************************************************************/ 
     507 
     508   public LuaState doFile (bool protection, cstring filename, uint arguments = 0, int results = MULTIPLE_RETURN_VALUES) 
     509   
    510510        loadFile (filename); 
    511511 
    512512        return call (protection, arguments, results); 
    513    
    514  
    515     /******************************************************************************* 
     513   
     514 
     515   /******************************************************************************* 
    516516 
    517517        If the object at the specified index has a metatable with the specified 
     
    524524        Replaces luaL_callmeta. 
    525525 
    526     ******************************************************************************/ 
    527  
    528     public bool callMeta (int index, char[] field) 
    529    
    530       return luaL_callmeta (this.state_, index, toStringz (field)) != 0; 
    531    
    532  
    533     /******************************************************************************* 
     526   ******************************************************************************/ 
     527 
     528   public bool callMeta (int index, cstring field) 
     529   
     530      return luaL_callmeta (this.state_, index, toStringz (field)) != 0; 
     531   
     532 
     533   /******************************************************************************* 
    534534 
    535535        If the function argument is number, returns this number cast to an int. 
     
    540540        Replaces luaL_optint, luaL_optlong and luaL_optinteger. 
    541541 
    542     ******************************************************************************/ 
    543  
    544     public LuaInteger optInteger (uint argument, LuaInteger default_value) 
    545    
    546       return luaL_optint (this.state_, argument, default_value); 
    547    
    548  
    549     /******************************************************************************* 
     542   ******************************************************************************/ 
     543 
     544   public LuaInteger optInteger (uint argument, LuaInteger default_value) 
     545   
     546      return luaL_optint (this.state_, argument, default_value); 
     547   
     548 
     549   /******************************************************************************* 
    550550 
    551551        If the function argument is number, returns this number. 
     
    556556        Replaces luaL_optnumber. 
    557557 
    558     ******************************************************************************/ 
     558   ******************************************************************************/ 
    559559 
    560560    public LuaNumber optNumber (uint argument, LuaNumber default_value) 
     
    563563    } 
    564564 
    565     /******************************************************************************* 
     565   /******************************************************************************* 
    566566 
    567567        If the function argument is a string, returns this string. If this 
     
    572572        Replaces luaL_optlstring and luaL_optstring. 
    573573 
    574     ******************************************************************************/ 
    575  
    576     public char[] optString (uint argument, char[] default_value) 
     574   ******************************************************************************/ 
     575 
     576    public istring optString (uint argument, cstring default_value) 
    577577    { 
    578578        size_t len; 
    579         char* ptr = luaL_optlstring (this.state_, argument, toStringz (default_value), &len); 
     579        ichar* ptr = luaL_optlstring (this.state_, argument, toStringz (default_value), &len); 
    580580 
    581581        return ptr[0 .. len]; 
    582582    } 
    583583 
    584     /******************************************************************************* 
     584   /******************************************************************************* 
    585585 
    586586        Checks whether the function argument is a string and searches for this 
     
    599599        Replaces luaL_checkoption. 
    600600 
    601     ******************************************************************************/ 
    602  
    603     public int checkOption (uint argument, char[][] value_list, char[] default_value = null) 
    604    
    605        char[] name = (default_value !is null) ? optString (argument, default_value) : checkString (argument); 
    606  
    607       foreach (i, s; value_list) 
    608       { 
    609           if (s == name) 
    610               return i; 
    611       } 
    612  
    613        throw new LuaCodeException ("Invalid option: '" ~ name ~ "'"); 
    614    
    615  
    616     /******************************************************************************* 
     601   ******************************************************************************/ 
     602 
     603   public int checkOption (uint argument, char[][] value_list, cstring default_value = null) 
     604   
     605       istring name = (default_value !is null) ? optString (argument, default_value) : checkString (argument); 
     606 
     607      foreach (i, s; value_list) 
     608      { 
     609          if (s == name) 
     610              return i; 
     611      } 
     612 
     613       throw new LuaCodeException ("Invalid option: '" ~ name ~ "'", __FILE__, __LINE__); 
     614   
     615 
     616   /******************************************************************************* 
    617617 
    618618        Raises a Lua error specified by the message argument. If the latter is 
     
    626626        Replaces lua_error and luaL_error. 
    627627 
    628     ******************************************************************************/ 
    629  
    630     public int raiseError (char[] message = null) 
    631    
     628   ******************************************************************************/ 
     629 
     630   public int raiseError (cstring message = null) 
     631   
    632632        if (message !is null) 
    633633        { 
    634             pushString (message); 
     634           pushString (message); 
    635635        } 
    636636        return lua_error (this.state_); 
    637    
    638  
    639     /******************************************************************************* 
     637   
     638 
     639   /******************************************************************************* 
    640640 
    641641        Raises a Lua error due to a bad function argument, where the function 
     
    653653        Replaces luaL_argerror. 
    654654 
    655     ******************************************************************************/ 
    656  
    657     public int argumentError (uint argument, char[] message) 
    658    
    659       return luaL_argerror (this.state_, argument, toStringz (message)); 
    660    
    661  
    662     /******************************************************************************* 
     655   ******************************************************************************/ 
     656 
     657   public int argumentError (uint argument, cstring message) 
     658   
     659      return luaL_argerror (this.state_, argument, toStringz (message)); 
     660   
     661 
     662   /******************************************************************************* 
    663663 
    664664        Raises an error with a message like the following: 
    665665 
    666       <loc>: bad argument <argument> to '<func>' (<typename> expected, got <rt>) 
     666      <loc>: bad argument <argument> to '<func>' (<typename> expected, got <rt>) 
    667667 
    668668        where loc is produced by LuaState.where, func is the name of the current 
     
    678678        Replaces luaL_typerror. 
    679679 
    680     ******************************************************************************/ 
    681  
    682     public int typeError (uint argument, char[] typename) 
    683    
    684       return luaL_typerror (this.state_, argument, toStringz (typename)); 
    685    
    686  
    687     /******************************************************************************* 
     680   ******************************************************************************/ 
     681 
     682   public int typeError (uint argument, cstring typename) 
     683   
     684      return luaL_typerror (this.state_, argument, toStringz (typename)); 
     685   
     686 
     687   /******************************************************************************* 
    688688 
    689689        Constructs a LuaBuffer and attaches it to this state. 
     
    692692        The constructed Lua buffer. 
    693693 
    694     *******************************************************************************/ 
    695  
    696     public LuaBuffer createBuffer () 
    697    
    698       return new LuaBuffer (this); 
    699    
    700  
    701     /******************************************************************************* 
     694   *******************************************************************************/ 
     695 
     696   public LuaBuffer createBuffer () 
     697   
     698      return new LuaBuffer (this); 
     699   
     700 
     701   /******************************************************************************* 
    702702 
    703703        Dumps a function as a binary chunk. Receives a Lua function on the top 
     
    717717        Replaces lua_dump. 
    718718 
    719     *******************************************************************************/ 
    720  
    721     public int dump (int delegate (char[] data) dg) 
    722    
    723       return lua_dump (this.state_, &writer, &dg); 
    724    
    725  
    726     /******************************************************************************* 
     719   *******************************************************************************/ 
     720 
     721   public int dump (int delegate (cstring data) dg) 
     722   
     723      return lua_dump (this.state_, &writer, &dg); 
     724   
     725 
     726   /******************************************************************************* 
    727727 
    728728        Dumps a function as a binary chunk. It works exactly like the above dump 
     
    730730        complete result in one character array. 
    731731 
    732     *******************************************************************************/ 
    733  
    734     public char[] dump () 
    735    
    736         char[] result = []; 
    737  
    738         int dumper (char[] data) 
     732   *******************************************************************************/ 
     733 
     734   public mstring dump () 
     735   
     736        mstring result = []; 
     737 
     738        int dumper (cstring data) 
    739739        { 
    740             result ~= data; 
    741             return 0; 
     740           result ~= data; 
     741           return 0; 
    742742        } 
    743743 
     
    745745 
    746746        return result; 
    747    
    748  
    749     /******************************************************************************* 
    750  
    751       Loads a Lua chunk. If there are no errors, load pushes the compiled 
    752       chunk as a Lua function on top of the stack. Otherwise, it raises 
    753       either a LuaCodeException, if the code cannot be compiled or a 
    754       LuaFatalException on other errors. 
     747   
     748 
     749   /******************************************************************************* 
     750 
     751      Loads a Lua chunk. If there are no errors, load pushes the compiled 
     752      chunk as a Lua function on top of the stack. Otherwise, it raises 
     753      either a LuaCodeException, if the code cannot be compiled or a 
     754      LuaFatalException on other errors. 
    755755 
    756756        This function only loads a chunk; it does not run it. It automatically 
     
    767767        auto L = new LuaState; 
    768768        L.doString (true, ` 
    769         function fac (n) 
    770           if n == 0 then  
    771             return 1; 
    772           else 
    773             return n * fac(n-1); 
    774           end 
    775         end 
    776         `); 
    777  
    778       L.getGlobal ("fac"); // put function onto stack 
    779         char[] data = L.dump (); // dump it 
    780       L.pop (); // pop it 
     769       function fac (n) 
     770          if n == 0 then 
     771           return 1; 
     772         else 
     773           return n * fac(n-1); 
     774         end 
     775       end 
     776       `); 
     777 
     778      L.getGlobal ("fac"); // put function onto stack 
     779       char[] data = L.dump (); // dump it 
     780      L.pop (); // pop it 
    781781        L.load (data, "foo"); // reload function as chunk 'foo' 
    782782        L.setGlobal ("fac2"); // save it as the global function fac2 
     
    790790        Replaces lua_load. 
    791791 
    792     *******************************************************************************/ 
    793  
    794     public LuaState load (char[] delegate () dg, char[] chunk_name = null) 
    795    
     792   *******************************************************************************/ 
     793 
     794   public LuaState load (cstring delegate () dg, cstring chunk_name = null) 
     795   
    796796        int errors = lua_load (this.state_, &reader, &dg, toStringz (chunk_name)); 
    797797 
    798798        if (errors != 0) 
    799799        { 
    800             if (errors == LUA_ERRSYNTAX) 
    801                throw new LuaCodeException ("Syntax error during pre-compilation: " ~ popString); 
    802             else 
    803                throw new LuaFatalException (errors); 
     800           if (errors == LUA_ERRSYNTAX) 
     801               throw new LuaCodeException ("Syntax error during pre-compilation: " ~ popString, __FILE__, __LINE__); 
     802           else 
     803               throw new LuaFatalException (errors, __FILE__, __LINE__); 
    804804        } 
    805805 
    806806        return this; 
    807    
    808  
    809     /******************************************************************************* 
     807   
     808 
     809   /******************************************************************************* 
    810810 
    811811        Loads a Lua chunk. It works exactly like the above dump method, but 
     
    820820        Replaces luaL_loadstring and luaL_loadbuffer. 
    821821 
    822     *******************************************************************************/ 
    823  
    824     public LuaState load (char[] data, char[] chunk_name = null) 
    825    
     822   *******************************************************************************/ 
     823 
     824   public LuaState load (cstring data, cstring chunk_name = null) 
     825   
    826826        bool done = false; 
    827827 
    828828        load ( 
    829               { 
     829             { 
    830830                  if (!done) 
    831831                  { 
    832                       done = true; 
     832                     done = true; 
    833833                  } 
    834834                  else 
    835835                  { 
    836                       data = ""; 
     836                     data = ""; 
    837837                  } 
    838838                  return data; 
    839               }, 
    840               chunk_name ); 
    841  
    842         return this; 
    843    
    844  
    845     /******************************************************************************* 
     839             }, 
     840             chunk_name ); 
     841 
     842        return this; 
     843   
     844 
     845   /******************************************************************************* 
    846846 
    847847        Loads a file as a Lua chunk. This function uses the load method to load 
     
    860860        Throws: 
    861861        LuaIOException, if an error occured while reading the file. 
     862        LuaCodeException, if an error occured during pre-compilation. 
    862863 
    863864        Remarks: 
    864865        Replaces luaL_loadfile. 
    865866 
    866     *******************************************************************************/ 
    867  
    868     public LuaState loadFile (char[] filename) 
    869     { 
    870         if (luaL_loadfile (this.state_, toStringz (filename)) != 0) 
    871             throw new LuaIOException ("I/O error: loadFile failed to read \"" ~ filename ~ "\"!"); 
    872  
    873         return this; 
    874     } 
    875  
    876     /******************************************************************************* 
     867    *******************************************************************************/ 
     868 
     869    public LuaState loadFile (cstring filename) 
     870    { 
     871        int errors = luaL_loadfile (this.state_, toStringz (filename)); 
     872        if (errors != 0) 
     873        { 
     874            if (errors == LUA_ERRSYNTAX) 
     875                throw new LuaCodeException ("Syntax error during pre-compilation: " ~ popString, __FILE__, __LINE__); 
     876            else if (errors == LUA_ERRFILE) 
     877                throw new LuaIOException ("I/O error: loadFile failed to read \"" ~ filename ~ "\"!", __FILE__, __LINE__); 
     878            else 
     879                throw new LuaFatalException (errors, __FILE__, __LINE__); 
     880        } 
     881        return this; 
     882    } 
     883 
     884    /******************************************************************************* 
    877885 
    878886        Controls the garbage collector. 
     
    881889        command parameter: 
    882890 
    883        * STOP: Stops the garbage collector. 
    884        * RESTART: Restarts the garbage collector. 
    885        * COLLECT: Performs a full garbage-collection cycle. 
    886        * COUNT: Returns the current amount of memory (in Kbytes) in use by Lua. 
    887        * STEP: Performs an incremental step of garbage collection. The step 
    888          "size" is controlled by data (larger values mean more steps) in a 
    889          non-specified way. If you want to control the step size you must 
    890          experimentally tune the value of data. The function returns 1 if the 
    891          step finished a garbage-collection cycle. 
    892        * SET_PAUSE: Sets data/100 as the new value for the pause of the 
    893          collector. The function returns the previous value of the pause. 
    894        * SET_STEP_MULTIPLIER: Sets data/100 as the new value for the step 
    895          multiplier of the collector. The function returns the previous 
    896          value of the step multiplier. 
     891       * STOP: Stops the garbage collector. 
     892       * RESTART: Restarts the garbage collector. 
     893       * COLLECT: Performs a full garbage-collection cycle. 
     894       * COUNT: Returns the current amount of memory (in Kbytes) in use by Lua. 
     895       * STEP: Performs an incremental step of garbage collection. The step 
     896         "size" is controlled by data (larger values mean more steps) in a 
     897         non-specified way. If you want to control the step size you must 
     898         experimentally tune the value of data. The function returns 1 if the 
     899         step finished a garbage-collection cycle. 
     900       * SET_PAUSE: Sets data/100 as the new value for the pause of the 
     901         collector. The function returns the previous value of the pause. 
     902       * SET_STEP_MULTIPLIER: Sets data/100 as the new value for the step 
     903         multiplier of the collector. The function returns the previous 
     904         value of the step multiplier. 
    897905 
    898906        Params: 
     
    903911        Replaces lua_gc. 
    904912 
    905     *******************************************************************************/ 
    906  
    907     public int gc (LuaGarbageCollectorCommand command, int data = 0) 
    908    
    909       return lua_gc (this.state_, command, data); 
    910    
    911  
    912     /******************************************************************************* 
     913   *******************************************************************************/ 
     914 
     915   public int gc (LuaGarbageCollectorCommand command, int data = 0) 
     916   
     917      return lua_gc (this.state_, command, data); 
     918   
     919 
     920   /******************************************************************************* 
    913921 
    914922        Returns true if the two values in acceptable indices a and b are 
     
    923931        Replaces lua_rawequal 
    924932 
    925     *******************************************************************************/ 
    926  
    927     public bool rawEqual (int a, int b) 
    928    
    929       return lua_rawequal (this.state_, a, b) != 0; 
    930    
    931  
    932     /******************************************************************************* 
     933   *******************************************************************************/ 
     934 
     935   public bool rawEqual (int a, int b) 
     936   
     937      return lua_rawequal (this.state_, a, b) != 0; 
     938   
     939 
     940   /******************************************************************************* 
    933941 
    934942        Similar to getTable, but does a raw access (i.e., without metamethods): 
     
    947955        Replaces lua_rawget 
    948956 
    949     *******************************************************************************/ 
    950  
    951     public LuaState rawGet (int index) 
    952    
     957   *******************************************************************************/ 
     958 
     959   public LuaState rawGet (int index) 
     960   
    953961        lua_rawget (this.state_, index); 
    954962 
    955963        return this; 
    956    
    957  
    958     /******************************************************************************* 
     964   
     965 
     966   /******************************************************************************* 
    959967 
    960968        Pushes onto the stack the value t[n], where t is the value at the given 
     
    968976        Replaces lua_rawgeti 
    969977 
    970     *******************************************************************************/ 
    971  
    972     public LuaState rawGetIndex (int index, int n) 
    973    
     978   *******************************************************************************/ 
     979 
     980   public LuaState rawGetIndex (int index, int n) 
     981   
    974982        lua_rawgeti (this.state_, index, n); 
    975983 
    976984        return this; 
    977    
    978  
    979     /******************************************************************************* 
     985   
     986 
     987   /******************************************************************************* 
    980988 
    981989        Similar to setTable, but does a raw assignment (i.e., without metamethods): 
     
    9941002        Replaces lua_rawset 
    9951003 
    996     *******************************************************************************/ 
    997  
    998     public LuaState rawSet (int index) 
    999    
     1004   *******************************************************************************/ 
     1005 
     1006   public LuaState rawSet (int index) 
     1007   
    10001008        lua_rawset (this.state_, index); 
    10011009 
    10021010        return this; 
    1003    
    1004  
    1005     /******************************************************************************* 
     1011   
     1012 
     1013   /******************************************************************************* 
    10061014 
    10071015        Does the equivalent of t[n] = v, where t is the value at the given 
     
    10181026        Replaces lua_rawseti 
    10191027 
    1020     *******************************************************************************/ 
    1021  
    1022     public LuaState rawSetIndex (int index, int n) 
    1023    
     1028   *******************************************************************************/ 
     1029 
     1030   public LuaState rawSetIndex (int index, int n) 
     1031   
    10241032        lua_rawseti (this.state_, index, n); 
    10251033 
    10261034        return this; 
    1027    
    1028  
    1029     /******************************************************************************* 
     1035   
     1036 
     1037   /******************************************************************************* 
    10301038 
    10311039        Checks whether condition is true. If not, calls argumentError 
     
    10391047        Replaces luaL_argcheck. 
    10401048 
    1041     *******************************************************************************/ 
    1042  
    1043     public LuaState checkArgument (bool condition, uint argument, char[] message) 
    1044    
     1049   *******************************************************************************/ 
     1050 
     1051   public LuaState checkArgument (bool condition, uint argument, cstring message) 
     1052   
    10451053        luaL_argcheck (this.state_, condition, argument, toStringz (message)); 
    10461054 
    10471055        return this; 
    1048    
    1049  
    1050     public alias checkArgument argCheck; 
    1051  
    1052     /******************************************************************************* 
     1056   
     1057 
     1058   public alias checkArgument argCheck; 
     1059 
     1060   /******************************************************************************* 
    10531061 
    10541062        Checks whether the function has an argument of any type (including nil) 
     
    10611069        Replaces luaL_checkany. 
    10621070 
    1063     *******************************************************************************/ 
    1064  
    1065     public LuaState checkAny (int argument) 
    1066    
     1071   *******************************************************************************/ 
     1072 
     1073   public LuaState checkAny (int argument) 
     1074   
    10671075        luaL_checkany (this.state_, argument); 
    10681076 
    10691077        return this; 
    1070    
    1071  
    1072     /******************************************************************************* 
     1078   
     1079 
     1080   /******************************************************************************* 
    10731081 
    10741082        Returns true if the given acceptable index is not valid (that is, it 
     
    10811089        Replaces lua_isnone. 
    10821090 
    1083     *******************************************************************************/ 
    1084  
    1085     public bool isNone (int index) 
    1086    
    1087       return lua_isnone (this.state_, index) != 0; 
    1088    
    1089  
    1090     /******************************************************************************* 
     1091    *******************************************************************************/ 
     1092 
     1093   public bool isNone (int index) 
     1094   
     1095      return lua_isnone (this.state_, index) != 0; 
     1096   
     1097 
     1098   /******************************************************************************* 
    10911099 
    10921100        Returns true if the value at the given acceptable index is nil, and 
     
    10991107        Replaces lua_isnil. 
    11001108 
    1101     *******************************************************************************/ 
    1102  
    1103     public bool isNil (int index) 
    1104    
    1105       return lua_isnil (this.state_, index) != 0; 
    1106    
    1107  
    1108     /******************************************************************************* 
     1109   *******************************************************************************/ 
     1110 
     1111   public bool isNil (int index) 
     1112   
     1113      return lua_isnil (this.state_, index) != 0; 
     1114   
     1115 
     1116   /******************************************************************************* 
    11091117 
    11101118        Returns true if the given acceptable index is not valid (that is, it 
     
    11181126        Replaces lua_isnoneornil. 
    11191127 
    1120     *******************************************************************************/ 
    1121  
    1122     public bool isNoneOrNil (int index) 
    1123    
    1124       return lua_isnoneornil (this.state_, index) != 0; 
    1125    
    1126  
    1127     /******************************************************************************* 
     1128   *******************************************************************************/ 
     1129 
     1130   public bool isNoneOrNil (int index) 
     1131   
     1132      return lua_isnoneornil (this.state_, index) != 0; 
     1133   
     1134 
     1135   /******************************************************************************* 
    11281136 
    11291137        Returns the "length" of the value at the given acceptable index: 
     
    11401148        Replaces lua_objlen. 
    11411149 
    1142     *******************************************************************************/ 
    1143  
    1144     public size_t objectLength (int index) 
    1145    
    1146       return lua_objlen (this.state_, index); 
    1147    
    1148  
    1149     /******************************************************************************* 
     1150   *******************************************************************************/ 
     1151 
     1152   public size_t objectLength (int index) 
     1153   
     1154      return lua_objlen (this.state_, index); 
     1155   
     1156 
     1157   /******************************************************************************* 
    11501158 
    11511159        Pushes a nil value onto the stack. 
     
    11541162        Replaces lua_pushnil. 
    11551163 
    1156     *******************************************************************************/ 
    1157  
    1158     public LuaState pushNil () 
    1159    
     1164   *******************************************************************************/ 
     1165 
     1166   public LuaState pushNil () 
     1167   
    11601168        lua_pushnil (this.state_); 
    11611169 
    11621170        return this; 
    1163    
    1164  
    1165     /******************************************************************************* 
     1171   
     1172 
     1173   /******************************************************************************* 
    11661174 
    11671175        Pushes a copy of the element at the given valid index onto the stack. 
     
    11701178        Replaces lua_pushvalue. 
    11711179 
    1172     *******************************************************************************/ 
    1173  
    1174     public LuaState pushValue (int index) 
    1175    
     1180   *******************************************************************************/ 
     1181 
     1182   public LuaState pushValue (int index) 
     1183   
    11761184        lua_pushvalue (this.state_, index); 
    11771185 
    11781186        return this; 
    1179    
    1180  
    1181     /******************************************************************************* 
     1187   
     1188 
     1189   /******************************************************************************* 
    11821190 
    11831191        Accepts any acceptable index, or 0, and sets the stack top to this index. 
     
    11911199        Replaces lua_settop. 
    11921200 
    1193     *******************************************************************************/ 
    1194  
    1195     public LuaState setTop (int index) 
    1196    
     1201   *******************************************************************************/ 
     1202 
     1203   public LuaState setTop (int index) 
     1204   
    11971205        lua_settop (this.state_, index); 
    11981206 
    11991207        return this; 
    1200    
    1201  
    1202     /******************************************************************************* 
     1208   
     1209 
     1210   /******************************************************************************* 
    12031211 
    12041212        Returns the index of the top element in the stack. Because indices 
     
    12091217        Replaces lua_gettop. 
    12101218 
    1211     *******************************************************************************/ 
    1212  
    1213     public int getTop () 
    1214    
    1215       return lua_gettop (this.state_); 
    1216    
    1217  
    1218     public alias getTop top; 
    1219  
    1220  
    1221     /******************************************************************************* 
     1219   *******************************************************************************/ 
     1220 
     1221   public int getTop () 
     1222   
     1223      return lua_gettop (this.state_); 
     1224   
     1225 
     1226   public alias getTop top; 
     1227 
     1228 
     1229   /******************************************************************************* 
    12221230 
    12231231        Grows the stack size to top + needed elements, raising an error if the 
     
    12321240        Replaces lua_checkstack and luaL_checkstack. 
    12331241 
    1234     *******************************************************************************/ 
    1235  
    1236     public LuaState checkStack (uint needed, char[] message = "") 
    1237    
    1238         if (lua_checkstack (this.state_, needed) == false) 
    1239             throw new LuaFatalException ("Fatal error: checkStack failed to grow stack! " ~ message); 
    1240  
    1241         return this; 
    1242    
    1243  
    1244     /******************************************************************************* 
     1242   *******************************************************************************/ 
     1243 
     1244   public LuaState checkStack (uint needed, cstring message = "") 
     1245   
     1246       if (lua_checkstack (this.state_, needed) == false) 
     1247           throw new LuaFatalException ("Fatal error: checkStack failed to grow stack! " ~ message, __FILE__, __LINE__); 
     1248 
     1249       return this; 
     1250   
     1251 
     1252   /******************************************************************************* 
    12451253 
    12461254        Pops amount elements from the stack. 
     
    12521260        Replaces lua_pop. 
    12531261 
    1254     *******************************************************************************/ 
    1255  
    1256     public LuaState pop (uint amount = 1) 
    1257    
     1262   *******************************************************************************/ 
     1263 
     1264   public LuaState pop (uint amount = 1) 
     1265   
    12581266        lua_pop (this.state_, amount); 
    12591267 
    12601268        return this; 
    1261    
    1262  
    1263     /******************************************************************************* 
     1269   
     1270 
     1271   /******************************************************************************* 
    12641272 
    12651273        Removes the element at the given valid index, shifting down the elements 
     
    12731281        Replaces lua_remove. 
    12741282 
    1275     *******************************************************************************/ 
    1276  
    1277     public LuaState remove (int index) 
    1278    
     1283   *******************************************************************************/ 
     1284 
     1285   public LuaState remove (int index) 
     1286   
    12791287        lua_remove (this.state_, index); 
    12801288 
    12811289        return this; 
    1282    
    1283  
    1284     /******************************************************************************* 
     1290   
     1291 
     1292   /******************************************************************************* 
    12851293 
    12861294        Moves the top element into the given position (and pops it), without 
     
    12931301        Replaces lua_replace. 
    12941302 
    1295     *******************************************************************************/ 
    1296  
    1297     public LuaState replace (int index) 
    1298    
     1303   *******************************************************************************/ 
     1304 
     1305   public LuaState replace (int index) 
     1306   
    12991307        lua_replace (this.state_, index); 
    13001308 
    13011309        return this; 
    1302    
    1303  
    1304     /******************************************************************************* 
     1310   
     1311 
     1312   /******************************************************************************* 
    13051313 
    13061314        Checks whether the function argument has the type. 
     
    13131321        Replaces luaL_checktype. 
    13141322 
    1315     *******************************************************************************/ 
    1316  
    1317     public LuaState checkType (int argument, LuaType type) 
    1318    
     1323   *******************************************************************************/ 
     1324 
     1325   public LuaState checkType (int argument, LuaType type) 
     1326   
    13191327        luaL_checktype (this.state_, argument, type); 
    13201328 
    13211329        return this; 
    1322    
    1323  
    1324     /******************************************************************************* 
     1330   
     1331 
     1332   /******************************************************************************* 
    13251333 
    13261334        Returns the type of the value in the given acceptable index, or 
     
    13341342        Replaces lua_type. 
    13351343 
    1336     *******************************************************************************/ 
    1337  
    1338     public LuaType type (int index) 
    1339    
    1340       return cast (LuaType) lua_type (this.state_, index); 
    1341    
    1342  
    1343     /******************************************************************************* 
     1344   *******************************************************************************/ 
     1345 
     1346   public LuaType type (int index) 
     1347   
     1348      return cast (LuaType) lua_type (this.state_, index); 
     1349   
     1350 
     1351   /******************************************************************************* 
    13441352 
    13451353        Returns the name of the type encoded by the value type, which must be 
     
    13541362        of type 
    13551363 
    1356     *******************************************************************************/ 
    1357  
    1358     public char[] typeName (LuaType type) 
    1359    
    1360         char* string = lua_typename (this.state_, type); 
     1364   *******************************************************************************/ 
     1365 
     1366   public istring typeName (LuaType type) 
     1367   
     1368        ichar* string = lua_typename (this.state_, type); 
    13611369        return string [0 .. strlenz (string)]; 
    1362    
    1363  
    1364     /******************************************************************************* 
     1370   
     1371 
     1372   /******************************************************************************* 
    13651373 
    13661374        Checks whether the function argument argument is a number and returns 
     
    13731381        Replaces luaL_checkinteger, luaL_checkint and luaL_checklong. 
    13741382 
    1375     *******************************************************************************/ 
    1376  
    1377     public LuaInteger checkInteger (int argument) 
    1378    
    1379       return luaL_checkinteger (this.state_, argument); 
    1380    
    1381  
    1382     /******************************************************************************* 
     1383   *******************************************************************************/ 
     1384 
     1385   public LuaInteger checkInteger (int argument) 
     1386   
     1387      return luaL_checkinteger (this.state_, argument); 
     1388   
     1389 
     1390   /******************************************************************************* 
    13831391 
    13841392        Converts the Lua value at the given acceptable index to the signed 
     
    13941402        Replaces lua_tointeger. 
    13951403 
    1396     *******************************************************************************/ 
    1397  
    1398     public LuaInteger toInteger (int index) 
    1399    
    1400       return lua_tointeger (this.state_, index); 
    1401    
    1402  
    1403     /******************************************************************************* 
     1404   *******************************************************************************/ 
     1405 
     1406   public LuaInteger toInteger (int index) 
     1407   
     1408      return lua_tointeger (this.state_, index); 
     1409   
     1410 
     1411   /******************************************************************************* 
    14041412 
    14051413        Pushes a number with the specified value onto the stack. 
     
    14111419        Replaces lua_pushinteger. 
    14121420 
    1413     *******************************************************************************/ 
    1414  
    1415     public LuaState pushInteger (LuaInteger value) 
    1416    
     1421   *******************************************************************************/ 
     1422 
     1423   public LuaState pushInteger (LuaInteger value) 
     1424   
    14171425        lua_pushinteger (this.state_, value); 
    14181426 
    14191427        return this; 
    1420    
    1421  
    1422     /******************************************************************************* 
     1428   
     1429 
     1430   /******************************************************************************* 
    14231431 
    14241432        Checks whether the function argument is a number and returns this number. 
     
    14301438        Replaces luaL_checknumber. 
    14311439 
    1432     *******************************************************************************/ 
    1433  
    1434     public LuaNumber checkNumber (int index) 
    1435    
    1436       return luaL_checknumber (this.state_, index); 
    1437    
    1438  
    1439     /******************************************************************************* 
     1440   *******************************************************************************/ 
     1441 
     1442   public LuaNumber checkNumber (int index) 
     1443   
     1444      return luaL_checknumber (this.state_, index); 
     1445   
     1446 
     1447   /******************************************************************************* 
    14401448 
    14411449        Converts the Lua value at the given acceptable index to the type LuaNumber. 
     
    14491457        Replaces lua_tonumber. 
    14501458 
    1451     *******************************************************************************/ 
    1452  
    1453     public LuaNumber toNumber (int index) 
    1454    
    1455       return lua_tonumber (this.state_, index); 
    1456    
    1457  
    1458     /******************************************************************************* 
     1459   *******************************************************************************/ 
     1460 
     1461   public LuaNumber toNumber (int index) 
     1462   
     1463      return lua_tonumber (this.state_, index); 
     1464   
     1465 
     1466   /******************************************************************************* 
    14591467 
    14601468        Pushes a number with the specified value onto the stack. 
     
    14661474        Replaces lua_pushnumber. 
    14671475 
    1468     *******************************************************************************/ 
    1469  
    1470     public LuaState pushNumber (LuaNumber value) 
    1471    
     1476   *******************************************************************************/ 
     1477 
     1478   public LuaState pushNumber (LuaNumber value) 
     1479   
    14721480        lua_pushnumber (this.state_, value); 
    14731481 
    14741482        return this; 
    1475    
    1476  
    1477     /******************************************************************************* 
     1483   
     1484 
     1485   /******************************************************************************* 
    14781486 
    14791487        Returns true if the value at the given acceptable index is a number or 
     
    14861494        Replaces lua_isnumber. 
    14871495 
    1488     *******************************************************************************/ 
    1489  
    1490     public bool isNumber (int index) 
    1491    
    1492       return lua_isnumber (this.state_, index) != 0; 
    1493    
    1494  
    1495     /******************************************************************************* 
     1496   *******************************************************************************/ 
     1497 
     1498   public bool isNumber (int index) 
     1499   
     1500      return lua_isnumber (this.state_, index) != 0; 
     1501   
     1502 
     1503   /******************************************************************************* 
    14961504 
    14971505        Returns true if the value at the given acceptable index has type 
     
    15041512        Replaces lua_isboolean. 
    15051513 
    1506     *******************************************************************************/ 
    1507  
    1508     public bool isBool (int index) 
    1509    
    1510       return lua_isboolean (this.state_, index) != 0; 
    1511    
    1512  
    1513     /******************************************************************************* 
     1514   *******************************************************************************/ 
     1515 
     1516   public bool isBool (int index) 
     1517   
     1518      return lua_isboolean (this.state_, index) != 0; 
     1519   
     1520 
     1521   /******************************************************************************* 
    15141522 
    15151523        Pushes a boolean with the specified value onto the stack. 
     
    15211529        Replaces lua_pushboolean. 
    15221530 
    1523     *******************************************************************************/ 
    1524  
    1525     public LuaState pushBool (bool value) 
    1526    
     1531   *******************************************************************************/ 
     1532 
     1533   public LuaState pushBool (bool value) 
     1534   
    15271535        lua_pushboolean (this.state_, value); 
    15281536 
    15291537        return this; 
    1530    
    1531  
    1532     /******************************************************************************* 
     1538   
     1539 
     1540   /******************************************************************************* 
    15331541 
    15341542        Converts the Lua value at the given acceptable index to a bool value. 
     
    15441552        Replaces lua_toboolean. 
    15451553 
    1546     *******************************************************************************/ 
    1547  
    1548     public bool toBool (int index) 
    1549    
    1550       return lua_toboolean (this.state_, index) != 0; 
    1551    
    1552  
    1553     /******************************************************************************* 
     1554   *******************************************************************************/ 
     1555 
     1556   public bool toBool (int index) 
     1557   
     1558      return lua_toboolean (this.state_, index) != 0; 
     1559   
     1560 
     1561   /******************************************************************************* 
    15541562 
    15551563        Checks whether the function argument is a string and returns this string. 
     
    15611569        Replaces luaL_checkstring. 
    15621570 
    1563     *******************************************************************************/ 
    1564  
    1565     public char[] checkString (int index) 
    1566    
    1567       uint len; 
    1568         char* str = luaL_checklstring (this.state_, index, &len); 
    1569         return str[0 .. len]; 
    1570    
    1571  
    1572     /******************************************************************************* 
     1571   *******************************************************************************/ 
     1572 
     1573   public istring checkString (int index) 
     1574   
     1575      uint len; 
     1576       ichar* str = luaL_checklstring (this.state_, index, &len); 
     1577       return str[0 .. len]; 
     1578   
     1579 
     1580   /******************************************************************************* 
    15731581 
    15741582        Returns true if the value at the given acceptable index is a string or 
     
    15811589        Replaces lua_isstring. 
    15821590 
    1583     *******************************************************************************/ 
    1584  
    1585     public bool isString (int index) 
    1586    
    1587       return lua_isstring (this.state_, index) != 0; 
    1588    
    1589  
    1590     /******************************************************************************* 
     1591   *******************************************************************************/ 
     1592 
     1593   public bool isString (int index) 
     1594   
     1595      return lua_isstring (this.state_, index) != 0; 
     1596   
     1597 
     1598   /******************************************************************************* 
    15911599 
    15921600        Pushes the string onto the stack. Lua makes (or reuses) an internal copy 
     
    16001608        Replaces lua_pushstring, lua_pushliteral and lua_pushlstring. 
    16011609 
    1602     *******************************************************************************/ 
    1603  
    1604     public LuaState pushString (char[] string) 
    1605    
    1606         lua_pushlstring (this.state_, string.ptr, string.length); 
    1607  
    1608         return this; 
    1609    
    1610  
    1611     /******************************************************************************* 
     1610   *******************************************************************************/ 
     1611 
     1612   public LuaState pushString (cstring string) 
     1613   
     1614       lua_pushlstring (this.state_, string.ptr, string.length); 
     1615 
     1616       return this; 
     1617   
     1618 
     1619   /******************************************************************************* 
    16121620 
    16131621        Converts the Lua value at the given acceptable index to a string. The Lua 
     
    16301638        Replaces lua_tostring and lua_tolstring. 
    16311639 
    1632     *******************************************************************************/ 
    1633  
    1634     public char[] toString (int index) 
    1635    
    1636         uint len; 
    1637         char* str = lua_tolstring (this.state_, index, &len); 
    1638         return str[0 .. len]; 
    1639    
    1640  
    1641     /******************************************************************************* 
     1640   *******************************************************************************/ 
     1641 
     1642   public istring toString (int index) 
     1643   
     1644       uint len; 
     1645       ichar* str = lua_tolstring (this.state_, index, &len); 
     1646       return str[0 .. len]; 
     1647   
     1648 
     1649   /******************************************************************************* 
    16421650 
    16431651        Returns the same as toString(-1) and pops the value afterwards. 
    16441652 
    1645     *******************************************************************************/ 
    1646  
    1647     public char[] popString () 
    1648    
    1649         char[] result = toString (-1); 
    1650         pop (); 
    1651         return result; 
    1652    
    1653  
    1654     /******************************************************************************* 
     1653   *******************************************************************************/ 
     1654 
     1655   public istring popString () 
     1656   
     1657       istring result = toString (-1); 
     1658       pop (); 
     1659       return result; 
     1660   
     1661 
     1662   /******************************************************************************* 
    16551663 
    16561664        Returns true if the value at the given acceptable index is a function 
     
    16631671        Replaces lua_isfunction. 
    16641672 
    1665     *******************************************************************************/ 
    1666  
    1667     public bool isFunction (int index) 
    1668    
    1669       return lua_isfunction (this.state_, index) != 0; 
    1670    
    1671  
    1672     /******************************************************************************* 
     1673   *******************************************************************************/ 
     1674 
     1675   public bool isFunction (int index) 
     1676   
     1677      return lua_isfunction (this.state_, index) != 0; 
     1678   
     1679 
     1680   /******************************************************************************* 
    16731681 
    16741682        Converts a value at the given acceptable index to a C function. That 
     
    16811689        Replaces lua_tocfunction. 
    16821690 
    1683     *******************************************************************************/ 
    1684  
    1685     public LuaCFunction toCFunction (int index) 
    1686    
    1687       return lua_tocfunction (this.state_, index); 
    1688    
    1689  
    1690     /******************************************************************************* 
     1691   *******************************************************************************/ 
     1692 
     1693   public LuaCFunction toCFunction (int index) 
     1694   
     1695      return lua_tocfunction (this.state_, index); 
     1696   
     1697 
     1698   /******************************************************************************* 
    16911699 
    16921700        Pushes a new C closure onto the stack. 
     
    17081716        Replaces lua_pushcclosure and lua_pushcfunction. 
    17091717 
    1710     *******************************************************************************/ 
    1711  
    1712     public LuaState pushCClosure (LuaCFunction cfunction, int upvalues = 0) 
    1713    
    1714       lua_pushcclosure (this.state_, cfunction, upvalues); 
    1715  
    1716       return this; 
    1717    
    1718     public alias pushCClosure pushCFunction; 
    1719  
    1720     /******************************************************************************* 
     1718   *******************************************************************************/ 
     1719 
     1720   public LuaState pushCClosure (LuaCFunction cfunction, int upvalues = 0) 
     1721   
     1722      lua_pushcclosure (this.state_, cfunction, upvalues); 
     1723 
     1724      return this; 
     1725   
     1726   public alias pushCClosure pushCFunction; 
     1727 
     1728   /******************************************************************************* 
    17211729 
    17221730        Returns true if the value at the given acceptable index is a C or D 
     
    17291737        Replaces lua_iscfunction. 
    17301738 
    1731     *******************************************************************************/ 
    1732  
    1733     public bool isCFunction (int index) 
    1734    
    1735       return lua_iscfunction (this.state_, index) != 0; 
    1736    
    1737  
    1738     /******************************************************************************* 
     1739   *******************************************************************************/ 
     1740 
     1741   public bool isCFunction (int index) 
     1742   
     1743      return lua_iscfunction (this.state_, index) != 0; 
     1744   
     1745 
     1746   /******************************************************************************* 
    17391747 
    17401748        Pushes onto the stack the environment table of the value at the given index. 
     
    17461754        Replaces lua_getfenv. 
    17471755 
    1748     *******************************************************************************/ 
    1749  
    1750     public LuaState getFunctionEnvironment (int index) 
    1751    
     1756   *******************************************************************************/ 
     1757 
     1758   public LuaState getFunctionEnvironment (int index) 
     1759   
    17521760        lua_getfenv (this.state_, index); 
    17531761 
    17541762        return this; 
    1755    
    1756  
    1757     /******************************************************************************* 
     1763   
     1764 
     1765   /******************************************************************************* 
    17581766 
    17591767        Pops a table from the stack and sets it as the new environment for the 
     
    17671775        Replaces lua_setfenv. 
    17681776 
    1769     *******************************************************************************/ 
    1770  
    1771     public LuaState setFunctionEnvironment (int index) 
    1772    
    1773       if (lua_setfenv (this.state_, index) == 0) 
    1774            throw new LuaCodeException ("Cannot set function environment for " ~ typeName (type (index))); 
    1775  
    1776         return this; 
    1777    
    1778  
    1779     /******************************************************************************* 
     1777   *******************************************************************************/ 
     1778 
     1779   public LuaState setFunctionEnvironment (int index) 
     1780   
     1781      if (lua_setfenv (this.state_, index) == 0) 
     1782           throw new LuaCodeException ("Cannot set function environment for " ~ typeName (type (index)), __FILE__, __LINE__); 
     1783 
     1784        return this; 
     1785   
     1786 
     1787   /******************************************************************************* 
    17801788 
    17811789        Returns true if the value at the given acceptable index is a table, 
     
    17881796        Replaces lua_istable. 
    17891797 
    1790     *******************************************************************************/ 
    1791  
    1792     public bool isTable (int index) 
    1793    
    1794       return lua_istable (this.state_, index) != 0; 
    1795    
    1796  
    1797     /******************************************************************************* 
     1798   *******************************************************************************/ 
     1799 
     1800   public bool isTable (int index) 
     1801   
     1802      return lua_istable (this.state_, index) != 0; 
     1803   
     1804 
     1805   /******************************************************************************* 
    17981806 
    17991807        Creates a new empty table and pushes it onto the stack. The new table 
     
    18081816        Replaces lua_createtable and lua_newtable. 
    18091817 
    1810     *******************************************************************************/ 
    1811  
    1812     public LuaState createTable (uint array_elements = 0, uint record_elements = 0) 
    1813    
    1814       lua_createtable (this.state_, array_elements, record_elements); 
    1815  
    1816       return this; 
    1817    
    1818  
    1819     public alias createTable newTable; 
    1820  
    1821     /******************************************************************************* 
     1818   *******************************************************************************/ 
     1819 
     1820   public LuaState createTable (uint array_elements = 0, uint record_elements = 0) 
     1821   
     1822      lua_createtable (this.state_, array_elements, record_elements); 
     1823 
     1824      return this; 
     1825   
     1826 
     1827   public alias createTable newTable; 
     1828 
     1829   /******************************************************************************* 
    18221830 
    18231831        Does the equivalent to t[k] = v, where t is the value at the given valid 
     
    18341842        Replaces lua_settable. 
    18351843 
    1836     *******************************************************************************/ 
    1837  
    1838     public LuaState setTable (int index) 
    1839    
    1840       lua_settable (this.state_, index); 
    1841  
    1842       return this; 
    1843    
    1844  
    1845     /******************************************************************************* 
     1844   *******************************************************************************/ 
     1845 
     1846   public LuaState setTable (int index) 
     1847   
     1848      lua_settable (this.state_, index); 
     1849 
     1850      return this; 
     1851   
     1852 
     1853   /******************************************************************************* 
    18461854 
    18471855        Pushes onto the stack the value t[k], where t is the value at the given 
     
    18581866        Replaces lua_gettable. 
    18591867 
    1860     *******************************************************************************/ 
    1861  
    1862     public LuaState getTable (int index) 
    1863    
    1864       lua_gettable (this.state_, index); 
    1865  
    1866       return this; 
    1867    
    1868  
    1869     /******************************************************************************* 
     1868   *******************************************************************************/ 
     1869 
     1870   public LuaState getTable (int index) 
     1871   
     1872      lua_gettable (this.state_, index); 
     1873 
     1874      return this; 
     1875   
     1876 
     1877   /******************************************************************************* 
    18701878 
    18711879        Pops a key from the stack, and pushes a key-value pair from the table at the 
     
    18821890            L.pop (); 
    18831891        } 
    1884         --- 
     1892        --- 
    18851893 
    18861894        While traversing a table, do not call toString directly on a key, unless you 
     
    18941902        Replaces lua_next. 
    18951903 
    1896     *******************************************************************************/ 
    1897  
    1898     public bool next (int index) 
    1899    
    1900       return lua_next (this.state_, index) != 0; 
    1901    
    1902  
    1903     /******************************************************************************* 
     1904   *******************************************************************************/ 
     1905 
     1906   public bool next (int index) 
     1907   
     1908      return lua_next (this.state_, index) != 0; 
     1909   
     1910 
     1911   /******************************************************************************* 
    19041912 
    19051913        Creates and returns a reference, in the table at index t, for the object 
     
    19221930        Replaces luaL_ref. 
    19231931 
    1924     *******************************************************************************/ 
    1925  
    1926     public int createReference (int index) 
    1927    
    1928       return luaL_ref (this.state_, index); 
    1929    
    1930  
    1931     /******************************************************************************* 
     1932   *******************************************************************************/ 
     1933 
     1934   public int createReference (int index) 
     1935   
     1936      return luaL_ref (this.state_, index); 
     1937   
     1938 
     1939   /******************************************************************************* 
    19321940 
    19331941        Releases reference ref from the table at index t (see createReference). 
     
    19441952        Replaces luaL_unref. 
    19451953 
    1946     *******************************************************************************/ 
    1947  
    1948     public LuaState releaseReference (int table_index, int reference) 
    1949    
    1950       luaL_unref (this.state_, table_index, reference); 
    1951  
    1952       return this; 
    1953    
    1954  
    1955     /******************************************************************************* 
     1954   *******************************************************************************/ 
     1955 
     1956   public LuaState releaseReference (int table_index, int reference) 
     1957   
     1958      luaL_unref (this.state_, table_index, reference); 
     1959 
     1960      return this; 
     1961   
     1962 
     1963   /******************************************************************************* 
    19561964 
    19571965        Pushes onto the stack the value t[k], where t is the value at the given 
     
    19661974        Replaces lua_getfield. 
    19671975 
    1968     *******************************************************************************/ 
    1969  
    1970     public LuaState getField (int index, char[] key) 
    1971    
    1972       lua_getfield (this.state_, index, toStringz (key)); 
    1973  
    1974       return this; 
    1975    
    1976  
    1977     /******************************************************************************* 
     1976   *******************************************************************************/ 
     1977 
     1978   public LuaState getField (int index, cstring key) 
     1979   
     1980      lua_getfield (this.state_, index, toStringz (key)); 
     1981 
     1982      return this; 
     1983   
     1984 
     1985   /******************************************************************************* 
    19781986 
    19791987        Does the equivalent to t[k] = v, where t is the value at the given valid 
     
    19901998        Replaces lua_setfield. 
    19911999 
    1992     *******************************************************************************/ 
    1993  
    1994     public LuaState setField (int index, char[] key) 
    1995    
     2000   *******************************************************************************/ 
     2001 
     2002   public LuaState setField (int index, cstring key) 
     2003   
    19962004        lua_setfield (this.state_, index, toStringz (key)); 
    19972005 
    19982006        return this; 
    1999    
    2000  
    2001     /******************************************************************************* 
     2007   
     2008 
     2009   /******************************************************************************* 
    20022010 
    20032011        Pops a value from the stack and sets it as the new value of global name. 
     
    20102018        Replaces lua_setglobal. 
    20112019 
    2012     *******************************************************************************/ 
    2013  
    2014     public LuaState setGlobal (char[] name) 
    2015    
    2016         lua_setfield (this.state_, LUA_GLOBALSINDEX, toStringz (name)); 
    2017  
    2018         return this; 
    2019    
    2020  
    2021     /******************************************************************************* 
     2020   *******************************************************************************/ 
     2021 
     2022   public LuaState setGlobal (cstring name) 
     2023   
     2024       lua_setfield (this.state_, LUA_GLOBALSINDEX, toStringz (name)); 
     2025 
     2026       return this; 
     2027   
     2028 
     2029   /******************************************************************************* 
    20222030 
    20232031        Pushes onto the stack the value of the global name. 
     
    20292037        Replaces lua_getglobal. 
    20302038 
    2031     *******************************************************************************/ 
    2032  
    2033     public LuaState getGlobal (char[] key) 
    2034    
     2039   *******************************************************************************/ 
     2040 
     2041   public LuaState getGlobal (cstring key) 
     2042   
    20352043        int last_dot = -1; 
    20362044        foreach (i, c; key) 
    20372045        { 
    2038             if (c == '.') 
    2039            
     2046           if (c == '.') 
     2047           
    20402048                if (last_dot < 0) 
    20412049                { 
    2042                     lua_getfield (this.state_, LUA_GLOBALSINDEX, (key[0 .. i] ~ '\0').ptr); 
    2043                     last_dot = i; 
     2050                   lua_getfield (this.state_, LUA_GLOBALSINDEX, (key[0 .. i] ~ '\0').ptr); 
     2051                   last_dot = i; 
    20442052                } 
    20452053                else 
    20462054                { 
    2047                     lua_getfield (this.state_, -1, (key[last_dot + 1 .. i] ~ '\0').ptr); 
    2048                     lua_remove (this.state_, -2); 
    2049                     last_dot = i; 
     2055                   lua_getfield (this.state_, -1, (key[last_dot + 1 .. i] ~ '\0').ptr); 
     2056                   lua_remove (this.state_, -2); 
     2057                   last_dot = i; 
    20502058                } 
    2051            
     2059           
    20522060        } 
    20532061 
    20542062        if (last_dot < 0) 
    2055             lua_getfield (this.state_, LUA_GLOBALSINDEX, toStringz (key)); 
     2063           lua_getfield (this.state_, LUA_GLOBALSINDEX, toStringz (key)); 
    20562064        else 
    20572065        { 
    2058             lua_getfield (this.state_, -1, (key[last_dot + 1 .. $] ~ '\0').ptr); 
    2059             lua_remove (this.state_, -2); 
     2066           lua_getfield (this.state_, -1, (key[last_dot + 1 .. $] ~ '\0').ptr); 
     2067           lua_remove (this.state_, -2); 
    20602068        } 
    20612069 
    2062         return this; 
    2063    
    2064  
    2065     /******************************************************************************* 
     2070       return this; 
     2071   
     2072 
     2073   /******************************************************************************* 
    20662074 
    20672075        If the registry already has the key name, returns false. Otherwise, 
     
    20782086        Replaces luaL_newmetatable. 
    20792087 
    2080     *******************************************************************************/ 
    2081  
    2082     public bool newMetatable (char[] name) 
    2083    
     2088   *******************************************************************************/ 
     2089 
     2090   public bool newMetatable (cstring name) 
     2091   
    20842092        return luaL_newmetatable (this.state_, toStringz (name)) != 0; 
    2085    
    2086  
    2087     /******************************************************************************* 
     2093   
     2094 
     2095   /******************************************************************************* 
    20882096 
    20892097        Pushes onto the stack the metatable of the value at the given acceptable 
     
    20982106        Replaces lua_getmetatable. 
    20992107 
    2100     *******************************************************************************/ 
    2101  
    2102     public bool getMetatable (int index) 
    2103    
     2108   *******************************************************************************/ 
     2109 
     2110   public bool getMetatable (int index) 
     2111   
    21042112        return lua_getmetatable (this.state_, index) != 0; 
    2105    
    2106  
    2107     /******************************************************************************* 
     2113   
     2114 
     2115   /******************************************************************************* 
    21082116 
    21092117        Pushes onto the stack the metatable associated with name in the registry. 
     
    21152123        Replaces luaL_getmetatable. 
    21162124 
    2117     *******************************************************************************/ 
    2118  
    2119     public LuaState getMetatable (char[] name) 
    2120    
     2125   *******************************************************************************/ 
     2126 
     2127   public LuaState getMetatable (cstring name) 
     2128   
    21212129        luaL_getmetatable (this.state_, toStringz (name)); 
    21222130 
    21232131        return this; 
    2124    
    2125  
    2126     /******************************************************************************* 
     2132   
     2133 
     2134   /******************************************************************************* 
    21272135 
    21282136        Pops a table from the stack and sets it as the new metatable for the 
     
    21352143        Replaces lua_setmetatable. 
    21362144 
    2137     *******************************************************************************/ 
    2138  
    2139     public LuaState setMetatable (int index) 
    2140    
     2145   *******************************************************************************/ 
     2146 
     2147   public LuaState setMetatable (int index) 
     2148   
    21412149        lua_setmetatable (this.state_, index); 
    21422150 
    21432151        return this; 
    2144    
    2145  
    2146     /******************************************************************************* 
     2152   
     2153 
     2154   /******************************************************************************* 
    21472155 
    21482156        Pushes onto the stack the field from the metatable of the object at the 
     
    21572165        Replaces luaL_getmetafield. 
    21582166 
    2159     *******************************************************************************/ 
    2160  
    2161     public int getMetafield (int index, char[] field) 
    2162    
    2163       return luaL_getmetafield (this.state_, index, toStringz (field)); 
    2164    
    2165  
    2166     /******************************************************************************* 
     2167   *******************************************************************************/ 
     2168 
     2169   public int getMetafield (int index, cstring field) 
     2170   
     2171      return luaL_getmetafield (this.state_, index, toStringz (field)); 
     2172   
     2173 
     2174   /******************************************************************************* 
    21672175 
    21682176        This function allocates a new block of memory with the given size, pushes 
     
    21852193        Replaces lua_newuserdata. 
    21862194 
    2187     *******************************************************************************/ 
    2188  
    2189     public void* newUserdata (uint size) 
    2190    
    2191       return lua_newuserdata (this.state_, size); 
    2192    
    2193  
    2194     /******************************************************************************* 
     2195   *******************************************************************************/ 
     2196 
     2197   public void* newUserdata (uint size) 
     2198   
     2199      return lua_newuserdata (this.state_, size); 
     2200   
     2201 
     2202   /******************************************************************************* 
    21952203 
    21962204        If the value at the given acceptable index is a full userdata, returns 
     
    22042212        Replaces lua_touserdata. 
    22052213 
    2206     ******************************************************************************/ 
    2207  
    2208     public void* toUserdata (int index) 
    2209    
    2210       return lua_touserdata (this.state_, index); 
    2211    
    2212  
    2213     /******************************************************************************* 
     2214   ******************************************************************************/ 
     2215 
     2216   public void* toUserdata (int index) 
     2217   
     2218      return lua_touserdata (this.state_, index); 
     2219   
     2220 
     2221   /******************************************************************************* 
    22142222 
    22152223        Returns true if the value at the given acceptable index is a userdata 
     
    22222230        Replaces lua_isuserdata. 
    22232231 
    2224     ******************************************************************************/ 
    2225  
    2226     public bool isUserdata (int index) 
    2227    
    2228       return lua_isuserdata (this.state_, index) != 0; 
    2229    
    2230  
    2231     /******************************************************************************* 
     2232   ******************************************************************************/ 
     2233 
     2234   public bool isUserdata (int index) 
     2235   
     2236      return lua_isuserdata (this.state_, index) != 0; 
     2237   
     2238 
     2239   /******************************************************************************* 
    22322240 
    22332241        Checks whether the function argument is a userdata of the type name. 
     
    22392247        Replaces luaL_checkudata. 
    22402248 
    2241     ******************************************************************************/ 
    2242  
    2243     public void* checkUserdata (int argument, char[] name) 
    2244    
    2245         return luaL_checkudata (this.state_, argument, toStringz (name)); 
    2246    
    2247  
    2248     /******************************************************************************* 
     2249   ******************************************************************************/ 
     2250 
     2251   public void* checkUserdata (int argument, cstring name) 
     2252   
     2253       return luaL_checkudata (this.state_, argument, toStringz (name)); 
     2254   
     2255 
     2256   /******************************************************************************* 
    22492257 
    22502258        Returns true if the value at the given acceptable index is a light 
     
    22572265        Replaces lua_islightuserdata. 
    22582266 
    2259     *******************************************************************************/ 
    2260  
    2261     public bool isLightUserdata (int index) 
    2262    
    2263         return lua_islightuserdata (this.state_, index) != 0; 
    2264    
    2265  
    2266     /******************************************************************************* 
     2267   *******************************************************************************/ 
     2268 
     2269   public bool isLightUserdata (int index) 
     2270   
     2271       return lua_islightuserdata (this.state_, index) != 0; 
     2272   
     2273 
     2274   /******************************************************************************* 
    22672275 
    22682276        Pushes a light userdata onto the stack. 
     
    22792287        Replaces lua_pushlightuserdata. 
    22802288 
    2281     *******************************************************************************/ 
    2282  
    2283     public LuaState pushLightUserdata (void* pointer) 
    2284    
    2285         lua_pushlightuserdata (this.state_, pointer); 
    2286  
    2287         return this; 
    2288    
    2289  
    2290     /******************************************************************************* 
     2289   *******************************************************************************/ 
     2290 
     2291   public LuaState pushLightUserdata (void* pointer) 
     2292   
     2293       lua_pushlightuserdata (this.state_, pointer); 
     2294 
     2295       return this; 
     2296   
     2297 
     2298   /******************************************************************************* 
    22912299 
    22922300        Moves the top element into the given valid index, shifting up the 
     
    23002308        Replaces lua_insert. 
    23012309 
    2302     *******************************************************************************/ 
    2303  
    2304     public LuaState insert (int index) 
    2305    
     2310   *******************************************************************************/ 
     2311 
     2312   public LuaState insert (int index) 
     2313   
    23062314        lua_insert (this.state_, index); 
    23072315 
    23082316        return this; 
    2309    
    2310  
    2311     /******************************************************************************* 
     2317   
     2318 
     2319   /******************************************************************************* 
    23122320 
    23132321        Concatenates the amount values at the top of the stack, pops them, and 
     
    23232331        Replaces lua_concat. 
    23242332 
    2325     *******************************************************************************/ 
    2326  
    2327     public LuaState concat (uint amount) 
    2328    
     2333   *******************************************************************************/ 
     2334 
     2335   public LuaState concat (uint amount) 
     2336   
    23292337        lua_concat (this.state_, amount); 
    23302338 
    23312339        return this; 
    2332    
    2333  
    2334     /******************************************************************************* 
     2340   
     2341 
     2342   /******************************************************************************* 
    23352343 
    23362344        Returns true if the two values in acceptable indices a and b are equal, 
     
    23462354        Replaces lua_equal. 
    23472355 
    2348     *******************************************************************************/ 
    2349  
    2350     public bool equal (int a, int b) 
    2351    
    2352       return lua_equal (this.state_, a, b) != 0; 
    2353    
    2354  
    2355     /******************************************************************************* 
     2356   *******************************************************************************/ 
     2357 
     2358   public bool equal (int a, int b) 
     2359   
     2360      return lua_equal (this.state_, a, b) != 0; 
     2361   
     2362 
     2363   /******************************************************************************* 
    23562364 
    23572365        Returns true if the value at acceptable index a is smaller than the value 
     
    23672375        Replaces lua_lessthan. 
    23682376 
    2369     *******************************************************************************/ 
    2370  
    2371     public bool lessthan (int a, int b) 
    2372    
    2373       return lua_lessthan (this.state_, a, b) != 0; 
    2374    
    2375  
    2376     /******************************************************************************* 
     2377   *******************************************************************************/ 
     2378 
     2379   public bool lessthan (int a, int b) 
     2380   
     2381      return lua_lessthan (this.state_, a, b) != 0; 
     2382   
     2383 
     2384   /******************************************************************************* 
    23772385 
    23782386        Converts the value at the given acceptable index to a Lua thread 
     
    23862394        Replaces lua_tothread. 
    23872395 
    2388     *******************************************************************************/ 
    2389  
    2390     public LuaState toThread (int index) 
    2391    
    2392       lua_State* state = lua_tothread (this.state_, index); 
    2393       if (state is null) 
    2394           return null; 
    2395       else 
    2396       { 
    2397           auto thread = new LuaState (this.write_, state); 
     2396   *******************************************************************************/ 
     2397 
     2398   public LuaState toThread (int index) 
     2399   
     2400      lua_State* state = lua_tothread (this.state_, index); 
     2401      if (state is null) 
     2402          return null; 
     2403      else 
     2404      { 
     2405          auto thread = new LuaState (this.write_, state); 
    23982406            thread.is_thread_state_ = true; 
    23992407            return thread; 
    24002408        } 
    2401    
    2402  
    2403     /******************************************************************************* 
     2409   
     2410 
     2411   /******************************************************************************* 
    24042412 
    24052413        Returns true if the value at the given acceptable index is a thread, 
     
    24122420        Replaces lua_isthread. 
    24132421 
    2414     *******************************************************************************/ 
    2415  
    2416     public bool isThread (int index) 
    2417    
    2418       return lua_isthread (this.state_, index) != 0; 
    2419    
    2420  
    2421     /******************************************************************************* 
     2422   *******************************************************************************/ 
     2423 
     2424   public bool isThread (int index) 
     2425   
     2426      return lua_isthread (this.state_, index) != 0; 
     2427   
     2428 
     2429   /******************************************************************************* 
    24222430 
    24232431        Creates a new thread, pushes it on the stack, and returns a LuaState that 
     
    24322440        Replaces lua_newthread. 
    24332441 
    2434     *******************************************************************************/ 
    2435  
    2436     public LuaState newThread () 
    2437    
    2438       auto thread = new LuaState (this.write_, lua_newthread (this.state_)); 
     2442   *******************************************************************************/ 
     2443 
     2444   public LuaState newThread () 
     2445   
     2446      auto thread = new LuaState (this.write_, lua_newthread (this.state_)); 
    24392447        thread.is_thread_state_ = true; 
    24402448        return thread; 
    2441    
    2442  
    2443     /******************************************************************************* 
     2449   
     2450 
     2451   /******************************************************************************* 
    24442452 
    24452453        Pushes the thread represented by the argument onto the stack. Returns 
     
    24492457        Replaces lua_pushthread. 
    24502458 
    2451     *******************************************************************************/ 
    2452  
    2453     public bool pushThread (LuaState thread) 
    2454    
    2455       return lua_pushthread (thread.state_) == 1; 
    2456    
    2457  
    2458     /******************************************************************************* 
     2459   *******************************************************************************/ 
     2460 
     2461   public bool pushThread (LuaState thread) 
     2462   
     2463      return lua_pushthread (thread.state_) == 1; 
     2464   
     2465 
     2466   /******************************************************************************* 
    24592467 
    24602468        Yields a coroutine. 
     
    24632471        function, as follows: 
    24642472        --- 
    2465       return L.yield (result_number); 
    2466       --- 
     2473      return L.yield (result_number); 
     2474      --- 
    24672475 
    24682476        When a function calls yield in that way, the running coroutine suspends 
     
    24772485        Replaces lua_yield. 
    24782486 
    2479     *******************************************************************************/ 
    2480  
    2481     public int yield (int results) 
    2482    
    2483       return lua_yield (this.state_, results); 
    2484    
    2485  
    2486     /******************************************************************************* 
     2487   *******************************************************************************/ 
     2488 
     2489   public int yield (int results) 
     2490   
     2491      return lua_yield (this.state_, results); 
     2492   
     2493 
     2494   /******************************************************************************* 
    24872495 
    24882496        Starts and resumes a coroutine in a given thread. 
     
    25052513        Replaces lua_resume. 
    25062514 
    2507     *******************************************************************************/ 
    2508  
    2509     public bool resume (uint arguments) 
    2510    
    2511       int errors = lua_resume (this.state_, arguments); 
     2515   *******************************************************************************/ 
     2516 
     2517   public bool resume (uint arguments) 
     2518   
     2519      int errors = lua_resume (this.state_, arguments); 
    25122520        if (errors == 0) 
    2513             return false; 
     2521           return false; 
    25142522        else if (errors == LUA_YIELD) 
    2515             return true; 
     2523           return true; 
    25162524        else 
    2517             throw new LuaFatalException (errors); 
    2518    
    2519  
    2520     /******************************************************************************* 
     2525           throw new LuaFatalException (errors, __FILE__, __LINE__); 
     2526   
     2527 
     2528   /******************************************************************************* 
    25212529 
    25222530        Returns the status of the thread. 
     
    25282536        Replaces lua_status. 
    25292537 
    2530     *******************************************************************************/ 
    2531  
    2532     public bool status () 
    2533    
     2538   *******************************************************************************/ 
     2539 
     2540   public bool status () 
     2541   
    25342542        int errors = lua_status (this.state_); 
    25352543        if (errors == 0) 
    2536             return false; 
     2544           return false; 
    25372545        else if (errors == LUA_YIELD) 
    2538             return true; 
     2546           return true; 
    25392547        else 
    2540             throw new LuaFatalException (errors); 
    2541    
    2542  
    2543     /******************************************************************************* 
     2548           throw new LuaFatalException (errors, __FILE__, __LINE__); 
     2549   
     2550 
     2551   /******************************************************************************* 
    25442552 
    25452553        Exchange values between different threads of the same global state. 
     
    25512559        Replaces lua_xmove. 
    25522560 
    2553     *******************************************************************************/ 
    2554  
    2555     public static void xmove (LuaState from_thread, LuaState to_thread, int amount) 
    2556    
    2557       lua_xmove (from_thread.state_, to_thread.state_, amount); 
    2558    
    2559  
    2560     /******************************************************************************* 
     2561   *******************************************************************************/ 
     2562 
     2563   public static void xmove (LuaState from_thread, LuaState to_thread, int amount) 
     2564   
     2565      lua_xmove (from_thread.state_, to_thread.state_, amount); 
     2566   
     2567 
     2568   /******************************************************************************* 
    25612569 
    25622570        Converts the value at the given acceptable index to a generic pointer 
     
    25732581        Replaces lua_xmove. 
    25742582 
    2575     *******************************************************************************/ 
    2576  
    2577     public void* toPointer (int index) 
    2578    
    2579       return lua_topointer (this.state_, index); 
    2580    
    2581  
    2582     /******************************************************************************* 
     2583   *******************************************************************************/ 
     2584 
     2585   public void* toPointer (int index) 
     2586   
     2587      return lua_topointer (this.state_, index); 
     2588   
     2589 
     2590   /******************************************************************************* 
    25832591 
    25842592        Returns the Activation Record of a given level. It contains information 
     
    25962604        Replaces lua_getstack. 
    25972605 
    2598     *******************************************************************************/ 
    2599  
    2600     public LuaActivationRecord getActivationRecord (uint level) 
    2601    
    2602       lua_Debug record; 
    2603  
    2604       if (lua_getstack (this.state_, level, &record)) 
    2605           return new LuaActivationRecord (this.state_, &record); 
    2606       else 
    2607           return null; 
    2608    
    2609  
    2610     /******************************************************************************* 
     2606   *******************************************************************************/ 
     2607 
     2608   public LuaActivationRecord getActivationRecord (uint level) 
     2609   
     2610      lua_Debug record; 
     2611 
     2612      if (lua_getstack (this.state_, level, &record)) 
     2613          return new LuaActivationRecord (this.state_, &record); 
     2614      else 
     2615          return null; 
     2616   
     2617 
     2618   /******************************************************************************* 
    26112619 
    26122620        Returns the current Call Trace which contains all Activation Records. 
    26132621 
    2614     *******************************************************************************/ 
    2615  
    2616     public LuaCallTrace getCallTrace () 
    2617    
    2618       return new LuaCallTrace (this); 
    2619    
    2620  
    2621     /******************************************************************************* 
     2622   *******************************************************************************/ 
     2623 
     2624   public LuaCallTrace getCallTrace () 
     2625   
     2626      return new LuaCallTrace (this); 
     2627   
     2628 
     2629   /******************************************************************************* 
    26222630 
    26232631        Returns the current Stack Trace which contains all Objects on the stack. 
    26242632 
    2625     *******************************************************************************/ 
    2626  
    2627     public LuaStackTrace getStackTrace () 
    2628    
    2629       return new LuaStackTrace (this); 
    2630    
    2631  
    2632     /******************************************************************************* 
     2633   *******************************************************************************/ 
     2634 
     2635   public LuaStackTrace getStackTrace () 
     2636   
     2637      return new LuaStackTrace (this); 
     2638   
     2639 
     2640   /******************************************************************************* 
    26332641 
    26342642        Returns a LuaObject (more precisely a subclass of it) of the value at 
     
    26392647        This is useful for stack traces (see getStackTrace) and to save a Lua 
    26402648        value (or whole tables) in a binary format. See LuaObject's methods. 
     2649 
     2650        Example: 
    26412651        --- 
    26422652        auto L = new LuaState; 
    26432653        L.pushNil (); 
    2644       L.pushNumber (2.0); 
    2645       L.pushInteger (3); 
    2646        
    2647        Stdout.formatln ("{} {} {}", L.getObject (1), L.getObject (2), L.getObject (3)); 
    2648         --- 
    2649  
    2650     *******************************************************************************/ 
    2651  
    2652     // TODO: Support Lua functions (They should be dumped / loaded) 
    2653  
    2654     public LuaObject getObject (int index) 
    2655    
    2656       LuaType type = type (index); 
    2657       switch (type) 
    2658       { 
    2659           case LuaType.NIL: return new LuaNilObject (); 
    2660           case LuaType.NUMBER: return new LuaNumberObject (toNumber (index)); 
    2661           case LuaType.BOOL: return new LuaBoolObject (toBool (index)); 
    2662           case LuaType.STRING: return new LuaStringObject (toString (index)); 
    2663           case LuaType.USERDATA: return new LuaUserdataObject (toUserdata (index), false); 
    2664           case LuaType.LIGHTUSERDATA: return new LuaUserdataObject (toUserdata (index), true); 
    2665           case LuaType.FUNCTION: return new LuaFunctionObject (toCFunction (index)); 
    2666           case LuaType.TABLE: return new LuaTableObject (this, index); 
    2667           default: return null; 
    2668       } 
    2669    
    2670  
    2671     /******************************************************************************* 
     2654      L.pushNumber (2.0); 
     2655      L.pushInteger (3); 
     2656       
     2657       Stdout.formatln ("{} {} {}", L.getObject (-3), L.getObject (-2), L.getObject (-1)); 
     2658       --- 
     2659 
     2660   *******************************************************************************/ 
     2661 
     2662   // TODO: Support Lua functions (They should be dumped / loaded) 
     2663 
     2664   public LuaObject getObject (int index) 
     2665   
     2666      LuaType type = type (index); 
     2667      switch (type) 
     2668      { 
     2669          case LuaType.NIL: return new LuaNilObject (); 
     2670          case LuaType.NUMBER: return new LuaNumberObject (toNumber (index)); 
     2671          case LuaType.BOOL: return new LuaBoolObject (toBool (index)); 
     2672          case LuaType.STRING: return new LuaStringObject (toString (index)); 
     2673          case LuaType.USERDATA: return new LuaUserdataObject (toUserdata (index), false); 
     2674          case LuaType.LIGHTUSERDATA: return new LuaUserdataObject (toUserdata (index), true); 
     2675          case LuaType.FUNCTION: return new LuaFunctionObject (toCFunction (index)); 
     2676          case LuaType.TABLE: return new LuaTableObject (this, index); 
     2677          default: return null; 
     2678      } 
     2679   
     2680 
     2681   /******************************************************************************* 
    26722682 
    26732683        Pushes onto the stack the given object. 
     
    26762686        This does not work for plain Userdata and Lua function! 
    26772687 
    2678     *******************************************************************************/ 
    2679  
    2680     public void pushObject (LuaObject obj) 
    2681    
    2682       obj.push (this); 
    2683    
    2684  
    2685     /******************************************************************************* 
     2688   *******************************************************************************/ 
     2689 
     2690   public void pushObject (LuaObject obj) 
     2691   
     2692      obj.push (this); 
     2693   
     2694 
     2695   /******************************************************************************* 
    26862696 
    26872697        Pushes onto the stack a string identifying the current position of the 
     
    26892699        the following format: 
    26902700 
    2691       chunkname:currentline: 
     2701      chunkname:currentline: 
    26922702 
    26932703        Level 0 is the running function, level 1 is the function that called the 
     
    27022712        Replaces luaL_where. 
    27032713 
    2704     *******************************************************************************/ 
    2705  
    2706     public LuaState where (int level) 
    2707    
     2714   *******************************************************************************/ 
     2715 
     2716   public LuaState where (int level) 
     2717   
    27082718        luaL_where (this.state_, level); 
    27092719 
    27102720        return this; 
    2711    
    2712  
    2713     /******************************************************************************* 
     2721   
     2722 
     2723   /******************************************************************************* 
    27142724 
    27152725        Registers all functions from the given list under the given Lua library 
     
    27212731        categories = Bit-mask to select the functions to register, default is to select all. 
    27222732 
    2723     *******************************************************************************/ 
    2724  
    2725     public LuaState registerLibrary (LuaRegistry[] functions, char[] library_name = null, int categories = -1) 
    2726    
    2727       foreach (LuaRegistry reg; functions) 
    2728        
    2729             if (reg.category == 0 || (reg.category & categories) != 0) 
    2730            
    2731               registerFunction (reg.name, reg.cfunction, library_name); 
    2732            
    2733        
    2734  
    2735       return this; 
    2736    
    2737  
    2738     /******************************************************************************* 
     2733   *******************************************************************************/ 
     2734 
     2735   public LuaState registerLibrary (LuaRegistry[] functions, cstring library_name = null, int categories = -1) 
     2736   
     2737      foreach (LuaRegistry reg; functions) 
     2738       
     2739           if (reg.category == 0 || (reg.category & categories) != 0) 
     2740           
     2741              registerFunction (reg.name, reg.cfunction, library_name); 
     2742           
     2743       
     2744 
     2745      return this; 
     2746   
     2747 
     2748   /******************************************************************************* 
    27392749 
    27402750        Registers a C function as a global function in the given Lua library. 
     
    27482758        Together with registerMethod, replaces lua_register and luaL_register. 
    27492759 
    2750     *******************************************************************************/ 
    2751  
    2752     public LuaState registerFunction (char[] name, LuaCFunction cfunction, char[] library_name = null) 
    2753    
     2760   *******************************************************************************/ 
     2761 
     2762   public LuaState registerFunction (cstring name, LuaCFunction cfunction, cstring library_name = null) 
     2763   
    27542764        if (library_name is null) 
    27552765        { 
    2756             lua_register (this.state_, toStringz (name), cast (lua_CFunction) cfunction); 
     2766           lua_register (this.state_, toStringz (name), cast (lua_CFunction) cfunction); 
    27572767        } 
    27582768        else 
    27592769        { 
    2760             extern (C) static luaL_reg[] reg = [ { null, null }, {null, null} ]; 
    2761             reg[0].name = toStringz (name); 
    2762             reg[0].func = cast (lua_CFunction) cfunction; 
    2763  
    2764             luaL_register (this.state_, toStringz (library_name), reg.ptr); 
    2765             pop (); 
     2770           extern (C) static luaL_reg[] reg = [ { null, null }, {null, null} ]; 
     2771           reg[0].name = toStringz (name); 
     2772           reg[0].func = cast (lua_CFunction) cfunction; 
     2773 
     2774           luaL_register (this.state_, toStringz (library_name), reg.ptr); 
     2775           pop (); 
    27662776        } 
    27672777 
    27682778        return this; 
    2769    
    2770  
    2771     /******************************************************************************* 
     2779   
     2780 
     2781   /******************************************************************************* 
    27722782 
    27732783        Registers a C function as a method of the table ontop of the stack. 
     
    27802790        Together with registerFunction, replaces luaL_register. 
    27812791 
    2782     *******************************************************************************/ 
    2783  
    2784     public LuaState registerMethod (char[] name, LuaCFunction cfunction) 
    2785    
     2792   *******************************************************************************/ 
     2793 
     2794   public LuaState registerMethod (cstring name, LuaCFunction cfunction) 
     2795   
    27862796        extern (C) static luaL_reg[] reg = [ { null, null }, {null, null} ]; 
    27872797 
     
    27922802 
    27932803        return this; 
    2794     } 
    2795      
    2796     /******************************************************************************* 
    2797  
    2798         A helper method for wrapClass. 
    2799  
    2800         Params: 
    2801         instance = Class instance to wrap 
    2802         type_name = Name of the class type  
    2803  
    2804     *******************************************************************************/ 
     2804    } 
    28052805     
    2806     public LuaState wrapClass_ (Object instance, char[] type_name) 
    2807     { 
    2808         auto ptr = cast (Object *) newUserdata ( (Object *).sizeof); 
    2809         *ptr = instance; 
    2810         loadClassMetatable (type_name); 
    2811         setMetatable (-2); 
    2812  
    2813         return this; 
    2814     } 
    2815  
    2816     /******************************************************************************* 
     2806    /******************************************************************************* 
    28172807 
    28182808        Wraps a D class instance, whose class type must be registered first, in 
     
    28262816        Together with registerFunction, replaces luaL_register. 
    28272817 
    2828     *******************************************************************************/ 
    2829  
    2830     public LuaState wrapClass (T) (T instance) 
    2831     { 
    2832         return wrapClass_ (instance, typeid (T).toString); 
    2833     } 
    2834  
    2835     /******************************************************************************* 
     2818    *******************************************************************************/ 
     2819 
     2820    public LuaState wrapClass (T) (T instance) 
     2821    { 
     2822        wrapClassHelper (instance, typeid (T).toString); 
     2823        return this; 
     2824    } 
     2825 
     2826    /******************************************************************************* 
     2827 
     2828        Imagine you register a lot of classes. 
     2829        This helper method for wrapClass reduces the size of generated wrapClass methods. 
     2830 
     2831        Params: 
     2832        instance = Class instance to wrap 
     2833        typeString = Name of the class type  
     2834 
     2835    *******************************************************************************/ 
     2836     
     2837    private void wrapClassHelper (Object instance, cstring typeString) 
     2838    { 
     2839        auto ptr = cast (Object *) newUserdata ( (Object *).sizeof); 
     2840        *ptr = instance; 
     2841 
     2842        loadClassMetatable (typeString); // leaves the metatable on the stack 
     2843        setMetatable (-2); // pops table and sets it as metatable of the userdata 
     2844    } 
     2845 
     2846    /******************************************************************************* 
    28362847 
    28372848        Unwraps a userdata at a given index into a D class instance, whose class 
     
    28412852        index = Index to unwrap. 
    28422853 
    2843     *******************************************************************************/ 
    2844  
    2845     public T unwrapClass (T) (int index) 
    2846    
     2854   *******************************************************************************/ 
     2855 
     2856   public T unwrapClass (T) (int index) 
     2857   
    28472858        void* userdata = checkUserdata (index, mangleClass (typeid (T).toString)); 
    28482859 
    28492860        if (userdata is null) 
    2850             throw new LuaFatalException ("Error in LuaState.wrapClass: Cannot unwrap userdata to class " ~ typeid (T).toString ~ "! It is not registered for this LuaState!"); 
     2861           throw new LuaFatalException ("Error in LuaState.unwrapClass: Cannot unwrap userdata to class " ~ typeid (T).toString ~ "! It is not registered for this LuaState!", __FILE__, __LINE__); 
    28512862 
    28522863        T instance = * (cast (T *) userdata); 
    28532864 
    28542865        return instance; 
    2855    
    2856  
    2857     /******************************************************************************* 
     2866   
     2867 
     2868   /******************************************************************************* 
    28582869 
    28592870        Loads a class Metatable and creates it, if it does not exist. 
    2860  
    2861     *******************************************************************************/ 
    2862  
    2863     public LuaState loadClassMetatable (char[] class_name) 
    2864     { 
    2865         class_name = mangleClass (class_name); 
    2866         getMetatable (class_name); 
    2867         if (isNil (-1)) 
     2871        Leaves the metatable on the stack. 
     2872 
     2873    *******************************************************************************/ 
     2874 
     2875    public LuaState loadClassMetatable (cstring class_name) 
     2876    { 
     2877        class_name = mangleClass (class_name); 
     2878        getMetatable (class_name); 
     2879        if (isNil (-1)) // if the metatable hasn't been loaded yet, create it 
    28682880        { 
    2869             pop (); 
    2870             newMetatable (class_name); 
    2871             pushString ("__index"); 
    2872             pushValue (-2); 
    2873             setTable (-3); 
    2874       } 
    2875  
    2876         return this; 
    2877    
    2878  
    2879      
    2880     /******************************************************************************* 
     2881            pop (); // remove the nil 
     2882            newMetatable (class_name); // create a new metatable t, push it and assoc. it with class_name in the registry 
     2883            pushString ("__index"); // table index 
     2884            pushValue (-2); // pushes the metatable 
     2885            setTable (-3); // metatable.__index = metatable 
     2886      } 
     2887 
     2888        return this; 
     2889   
     2890 
     2891     
     2892   /******************************************************************************* 
    28812893 
    28822894        Registers a D class in Lua, creating its metatable. The template parameter 
    28832895        must be the class. 
    28842896 
    2885     *******************************************************************************/ 
    2886  
    2887     public LuaState registerClass (T) () 
    2888    
    2889       loadClassMetatable (typeid (T).toString ()); 
    2890       pop (); 
    2891  
    2892         return this; 
    2893    
    2894  
    2895     /******************************************************************************* 
     2897   *******************************************************************************/ 
     2898 
     2899   public LuaState registerClass (T) () 
     2900   
     2901      loadClassMetatable (typeid (T).toString ()); 
     2902      pop (); 
     2903 
     2904        return this; 
     2905   
     2906 
     2907   /******************************************************************************* 
    28962908 
    28972909        Internal print function for Lua, which prints to the writer delegate 
     
    29012913        lua_state = Internal Lua state pointer 
    29022914 
    2903     *******************************************************************************/ 
    2904  
    2905     private extern (C) static int print (lua_State *lua_state) 
    2906    
    2907       LuaState L = states[lua_state]; 
    2908  
    2909         int argc = L.getTop (); 
    2910         L.getGlobal ("tostring"); 
    2911         for (int i = 1; i <= argc; i++) 
    2912        
    2913             L.pushValue (-1); 
    2914             L.pushValue (i); 
    2915             L.call (false, 1, 1); 
    2916             char[] s = L.toString (-1); 
    2917             if (s is null) 
    2918            
    2919                 return L.raiseError ("'tostring' must return a string to 'print'"); 
    2920            
    2921             if (i > 1) 
    2922            
    2923                 L.write ("\t"); 
    2924            
    2925             L.write (s); 
    2926             L.pop (1); 
    2927        
    2928         L.write ("\n"); 
    2929         return 0; 
    2930    
    2931  
    2932     /******************************************************************************* 
     2915   *******************************************************************************/ 
     2916 
     2917   private extern (C) static int print (lua_State *lua_state) 
     2918   
     2919      LuaState L = states[lua_state]; 
     2920 
     2921       int argc = L.getTop (); 
     2922       L.getGlobal ("tostring"); 
     2923       for (int i = 1; i <= argc; i++) 
     2924       
     2925           L.pushValue (-1); 
     2926           L.pushValue (i); 
     2927           L.call (false, 1, 1); 
     2928           istring s = L.toString(-1); 
     2929           if (s is null) 
     2930           
     2931               return L.raiseError ("'tostring' must return a string to 'print'"); 
     2932           
     2933           if (i > 1) 
     2934           
     2935               L.write ("\t"); 
     2936           
     2937           L.write (s); 
     2938           L.pop (1); 
     2939       
     2940       L.write ("\n"); 
     2941       return 0; 
     2942   
     2943 
     2944   /******************************************************************************* 
    29332945 
    29342946        Internal writer function, wrapping Writer delegates for the dump family. 
     
    29402952        userdata = Userdata containing the delegate pointer 
    29412953 
    2942     *******************************************************************************/ 
    2943  
    2944     private extern (C) static int writer (lua_State* lua_state, void* ptr, uint size, void* userdata) 
    2945    
    2946        return ( * (cast (int    delegate (char[] data) *) userdata )) ((cast (char*) ptr)[0 .. size]); 
    2947    
    2948  
    2949     /******************************************************************************* 
     2954   *******************************************************************************/ 
     2955 
     2956   private extern (C) static int writer (lua_State* lua_state, void* ptr, uint size, void* userdata) 
     2957   
     2958       return ( * (cast (int delegate (char[] data) *) userdata )) ((cast (char*) ptr)[0 .. size]); 
     2959   
     2960 
     2961   /******************************************************************************* 
    29502962 
    29512963        Internal reader function, wrapping Reader delegates for the load family. 
     
    29562968        psize = Return-parameter for the read size. 
    29572969 
    2958     *******************************************************************************/ 
    2959  
    2960     private extern (C) static char* reader (lua_State* lua_state, void* userdata, size_t* psize) 
    2961    
     2970   *******************************************************************************/ 
     2971 
     2972   private extern (C) static char* reader (lua_State* lua_state, void* userdata, size_t* psize) 
     2973   
    29622974        char[] data = ( * (cast (char[] delegate () *) userdata )) (); 
    29632975 
    29642976        *psize = data.length; 
    29652977        return data.ptr; 
    2966    
    2967  
    2968     /// Associative array which maps C states to D state classes 
    2969     private static LuaState[lua_State*] states; 
     2978   
     2979 
     2980   /// Associative array which maps C states to D state classes 
     2981   private static LuaState[lua_State*] states; 
    29702982} 
  • trunk/lua/utils.d

    r314 r324  
    1 /******************************************************************************* 
     1/******************************************************************************* 
    22 
    33    copyright:      Copyright (c) 2008 Matthias Walter. All rights reserved 
     
    1313 
    1414module lua.utils; 
     15private import lua.common; 
     16private import lua.error; 
    1517 
    1618/******************************************************************************* 
     
    7577*******************************************************************************/ 
    7678 
    77 public static char[] int2string (T) (T i, int radix = 10) 
     79public static istring int2string (T) (T i, int radix = 10) 
    7880{ 
    7981    if (i < 0) 
     
    109111*******************************************************************************/ 
    110112 
    111 public static T parseInt (T) (char[] str, out int read, uint radix = 10) 
     113public static T parseInt (T) (cstring str, out int read, uint radix = 10) 
    112114{ 
    113115    read = 0; 
     
    175177*******************************************************************************/ 
    176178 
    177 public static T string2int (T = long) (char[] str, uint radix = 10) 
     179public static T string2int (T = long) (cstring str, uint radix = 10) 
    178180{ 
    179181    int read; 
     
    182184        return result; 
    183185    else if (read < 0) 
    184         throw new Exception ("Parse error in '" ~ str ~ "': Integer overflow."); 
     186        throw new ExtendedException (cast(istring) ("Parse error in '" ~ str ~ "': Integer overflow."), __FILE__, __LINE__); 
    185187    else 
    186         throw new Exception ("Parse error in '" ~ str ~ "' at position " ~ int2string (read)); 
     188        throw new ExtendedException (cast(istring) ("Parse error in '" ~ str ~ "' at position " ~ int2string (read)), __FILE__, __LINE__); 
    187189} 
    188190 
     
    230232*******************************************************************************/ 
    231233 
    232 public static int find (char[] str, char c) 
     234public static int find (cstring str, char c) 
    233235{ 
    234236    foreach (int i, char ch; str) 
     
    249251*******************************************************************************/ 
    250252 
    251 public static int rfind (char[] str, char c) 
     253public static int rfind (cstring str, char c) 
    252254{ 
    253255    foreach_reverse (int i, char ch; str) 
     
    265267*******************************************************************************/ 
    266268 
    267 public static char* toStringz (char[] s) 
     269public static char* toStringz (cstring s) 
    268270{ 
    269271    if (s.ptr) 
     
    272274            s = s ~ '\0'; 
    273275    } 
    274     return s.ptr; 
     276    return cast(char*) s.ptr; 
    275277} 
    276278 
     
    281283*******************************************************************************/ 
    282284 
    283 public static size_t strlenz (char* s) 
     285public static size_t strlenz (cchar* s) 
    284286{ 
    285287    size_t i; 
     
    294296 
    295297 
    296 public static char[] ltrim (char[] str, char[] chars) 
     298public static cstring ltrim (cstring str, cstring chars) 
    297299{ 
    298300    foreach (i, c; str)