My Project
NPLHelper.h
1 #pragma once
2 #include "NPLWriter.h"
3 #include "NPLTable.h"
4 
5 namespace luabind
6 {
7  namespace adl{
8  class object;
9 
10  template<class Next>
11  class index_proxy;
12  }
13  using adl::object;
15 }
16 
17 namespace NPL
18 {
19  using namespace std;
20 
21  class NPLLex;
22  struct LexState;
23  struct STableStack;
24 
26  class PE_CORE_DECL NPLHelper
27  {
28  public:
29  NPLHelper(void);
30  ~NPLHelper(void);
31 
32  public:
33  static void DevideString(const string& input,string& str1,string&str2,char separator=';');
34 
35 
41  static bool IsSCodePureData(const char * sCode, int nCodeSize=-1);
42 
47  static bool IsPureData(const char * sCode, int nCodeSize=-1);
48 
53  static bool IsPureTable(const char * sCode, int nCodeSize=-1);
54 
66  template <typename StringType>
67  static bool SerializeToSCode(const char* sStorageVar, const luabind::object& input, StringType& sCode, int nCodeOffset = 0, STableStack* pRecursionTable = NULL, bool sort = false);
68 
69  template <typename StringType>
70  static bool SerializeToJson(const luabind::object& input, StringType& sCode, int nCodeOffset = 0, STableStack* pRecursionTable = NULL, bool bUseEmptyArray = false);
71 
72  static bool isControlCharacter(char ch);
73 
74  static bool containsControlCharacter(const char* str);
75 
77  static const char* LuaObjectToString(const luabind::object& input, int* pSize = NULL);
78 
81  static bool LuaObjectToString(const luabind::object& input, string& output);
82 
84  static int LuaObjectToInt(const luabind::object& input, int default_value=0);
85 
87  static float LuaObjectToFloat (const luabind::object& input, float default_value = 0.f);
88 
89  /* test if input is a table. */
90  static bool LuaObjectIsTable(const luabind::object& input);
91 
93  static double LuaObjectToDouble(const luabind::object& input, double default_value = 0.);
94 
96  static bool LuaObjectToBool(const luabind::object& input, bool default_value = false);
97 
99  static DWORD LuaObjectToColor(const luabind::object& pen, DWORD default_value = 0);
100 
108  static bool StringToLuaObject(const char* input,int nLen, luabind::object& output, lua_State* pState=NULL);
109  static bool StringToAnyObject(const char* input, int nLen, luabind::object& output, lua_State* pState = NULL);
110 
114  static bool MsgStringToLuaObject(const char* input,int nLen, lua_State* pState);
115 
119  static NPLObjectProxy StringToNPLTable(const char* input,int nLen=-1);
120 
124  static NPLObjectProxy MsgStringToNPLTable(const char* input,int nLen=-1);
125 
127  static bool LuaObjectToNPLObject(const luabind::object& input, NPLObjectProxy& out);
128 
133  template <typename StringType>
134  static bool SerializeNPLTableToString(const char* sStorageVar, NPLObjectProxy& input, StringType& sCode, int nCodeOffset=0);
135 
137  static bool NPLTableToString(const char* sStorageVar, NPLObjectProxy& input, std::string& sCode, int nCodeOffset=0);
138 
148  template <typename StringType>
149  static void EncodeStringInQuotation(StringType& output, int nOutputOffset, const char* input, int nInputSize);
150 
151  template <typename StringType>
152  static void EncodeStringInQuotation(StringType& output, int nOutputOffset, const std::string& input)
153  {
154  EncodeStringInQuotation(output, nOutputOffset, input.c_str(), (int)input.size());
155  }
156  template <typename StringType>
157  static void EncodeStringInQuotation(StringType& output, int nOutputOffset, const char* input)
158  {
159  EncodeStringInQuotation(output, nOutputOffset, input, (int)strlen(input));
160  }
161 
162 
163  template <typename StringType>
164  static void EncodeJsonStringInQuotation(StringType& output, int nOutputOffset, const char* input, int nInputSize);
165 
166  template <typename StringType>
167  static void EncodeJsonStringInQuotation(StringType& output, int nOutputOffset, const std::string& input)
168  {
169  EncodeJsonStringInQuotation(output, nOutputOffset, input.c_str(), (int)input.size());
170  }
171  template <typename StringType>
172  static void EncodeJsonStringInQuotation(StringType& output, int nOutputOffset, const char* input)
173  {
174  EncodeJsonStringInQuotation(output, nOutputOffset, input, (int)strlen(input));
175  }
176 
181  static bool CanEncodeStringInDoubleBrackets(const char* buffer, int nLength);
182  };
183 
185  struct STableStack
186  {
187  const luabind::object* m_pTableObj;
188  const STableStack* m_pParent;
189  };
190 }
191 
192 
only used internally
Definition: NPLHelper.h:185
define this to enable debugging of NPL code in visual studio
Definition: INPL.h:9
NPL object proxy.
Definition: NPLTable.h:73
Definition: NPLHelper.h:11
Definition: object.hpp:749
Definition: minilua.c:461
Definition: PEtypes.h:507
Definition: minilua.c:2241
a collection of helper functions.
Definition: NPLHelper.h:26