~armagetronad-ct/armagetronad/0.2.8-armagetronad-sty+ct+lua

« back to all changes in this revision

Viewing changes to src/engine/ePlayer.h

yet another try to add scripting support

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#include "eNetGameObject.h"
44
44
#include "tCallbackString.h"
45
45
#include "nSpamProtection.h"
 
46
#include "tLuaScript.h"
46
47
 
47
48
#include <set>
48
49
#include <list>
545
546
    bool enabled;
546
547
    tSettingItem<bool> *conf;
547
548
    tColoredString cache;
 
549
 
 
550
    int nb_params;
 
551
    int top;
 
552
    std::vector<int> luaRefs;
548
553
public:
549
554
    eLadderLogWriter(char const *ID, bool enabledByDefault);
550
555
    ~eLadderLogWriter();
551
556
    //! append a field to the current message. Spaces are added automatically.
 
557
    // an almost useless non template version for strings to avoid wrong type propagation into PushData
 
558
    // all string types like char[] will work...
 
559
    eLadderLogWriter &operator<< (const char* s) {
 
560
        if(enabled) {
 
561
            cache << ' ' << s;
 
562
        }
 
563
        if (luaRefs.size()) {
 
564
            if (!nb_params) top=lua_gettop(LuaState::Instance);
 
565
            PushData<const char *>(LuaState::Instance, s);
 
566
            nb_params++;
 
567
        }
 
568
        return *this;
 
569
    }
552
570
    template<typename T> eLadderLogWriter &operator<<(T const &s) {
553
571
        if(enabled) {
554
572
            cache << ' ' << s;
555
573
        }
 
574
        if (luaRefs.size()) {
 
575
            if (!nb_params) top=lua_gettop(LuaState::Instance);
 
576
            PushData<T>(LuaState::Instance, s);
 
577
            nb_params++;
 
578
        }
556
579
        return *this;
557
580
    }
 
581
 
558
582
    void write(); //!< send to ladderlog and clear message
559
583
 
560
584
    bool isEnabled() { return enabled; } //!< check this if you're going to make expensive calculations for ladderlog output
561
585
 
562
586
    static void setAll(bool enabled); //!< enable or disable all writers
 
587
 
 
588
    // Lua References
 
589
    void clearLuaRefs();
 
590
    static void clearAllLuaRefs();
 
591
    static void addLuaRef(char const * id , int p_ref);
563
592
};
564
593
 
565
594
tColoredString & operator << (tColoredString &s,const ePlayer &p);