28 #include "pinocchio/parsers/lua/lua_tables.hpp" 42 #define get_current_dir _getcwd 45 #define get_current_dir getcwd 48 #if defined(WIN32) || defined (_WIN32) 49 #define DIRECTORY_SEPARATOR "\\" 50 #elif defined(linux) || defined (__linux) || defined(__linux__) || defined(__APPLE__) 51 #define DIRECTORY_SEPARATOR "/" 53 #error Platform not supported! 58 std::string get_file_directory (
const char* filename)
60 string name (filename);
61 string result =
name.substr(0,
name.find_last_of (DIRECTORY_SEPARATOR) + 1);
65 #if defined (WIN32) || defined (_WIN32) 66 #warning get_file_directory() not yet tested under Windows! 67 else if (result.substr(1,2) !=
":\\")
68 result =
string(
".\\") + result;
70 else if (result.substr(0,
string(DIRECTORY_SEPARATOR).size()) != DIRECTORY_SEPARATOR && result[0] !=
'.')
71 result = string(
"./") + result;
79 const char serialize_std[] = {
81 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x6c,
82 0x69, 0x73, 0x74, 0x20, 0x28, 0x74, 0x29, 0x0a,
83 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x74, 0x65, 0x6d, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x3d,
85 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d,
86 0x20, 0x6e, 0x69, 0x6c, 0x0a,
87 0x09, 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x70, 0x61, 0x69, 0x72, 0x73, 0x28,
88 0x74, 0x29, 0x20, 0x64, 0x6f, 0x0a,
89 0x09, 0x09, 0x69, 0x74, 0x65, 0x6d, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x74, 0x65, 0x6d,
90 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x2b, 0x20, 0x31, 0x0a,
91 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20,
92 0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
93 0x09, 0x09, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x79, 0x70,
94 0x65, 0x28, 0x76, 0x29, 0x0a,
95 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
96 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x6c, 0x61,
97 0x73, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76,
98 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20,
99 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72,
100 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22,
101 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28,
102 0x76, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65,
104 0x09, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a,
105 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
107 0x09, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x79, 0x70, 0x65,
108 0x28, 0x76, 0x29, 0x0a,
109 0x09, 0x65, 0x6e, 0x64, 0x0a,
110 0x09, 0x69, 0x66, 0x20, 0x69, 0x74, 0x65, 0x6d, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x23,
111 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
112 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a,
113 0x09, 0x65, 0x6e, 0x64, 0x0a,
114 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a,
115 0x65, 0x6e, 0x64, 0x0a,
116 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x6d, 0x70,
117 0x5f, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x69, 0x63, 0x20, 0x28, 0x61, 0x2c, 0x20,
119 0x09, 0x69, 0x66, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, 0x28, 0x61, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x73,
120 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x62, 0x29,
121 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x79,
122 0x70, 0x65, 0x28, 0x61, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20,
123 0x61, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x62, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6e, 0x75,
124 0x6d, 0x62, 0x65, 0x72, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
125 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x61, 0x20, 0x3c, 0x20, 0x62, 0x0a,
126 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a,
127 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x61, 0x29, 0x20, 0x3c,
128 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x62, 0x29, 0x0a,
129 0x09, 0x65, 0x6e, 0x64, 0x0a,
130 0x65, 0x6e, 0x64, 0x0a,
131 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x67, 0x65, 0x6e,
132 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x6e, 0x64, 0x69, 0x63, 0x65, 0x73, 0x20, 0x28,
134 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x6e, 0x64,
135 0x69, 0x63, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a,
136 0x09, 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x20, 0x69, 0x6e, 0x20, 0x70, 0x61, 0x69, 0x72, 0x73, 0x20, 0x28, 0x74,
137 0x29, 0x20, 0x64, 0x6f, 0x0a,
138 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x20, 0x28, 0x6f, 0x72,
139 0x64, 0x65, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x6e, 0x64, 0x69, 0x63, 0x65, 0x73, 0x2c, 0x20, 0x6b, 0x29, 0x0a,
140 0x09, 0x65, 0x6e, 0x64, 0x0a,
141 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, 0x73, 0x6f, 0x72, 0x74, 0x20, 0x28, 0x6f, 0x72, 0x64, 0x65, 0x72,
142 0x65, 0x64, 0x5f, 0x69, 0x6e, 0x64, 0x69, 0x63, 0x65, 0x73, 0x2c, 0x20, 0x63, 0x6d, 0x70, 0x5f, 0x61, 0x6c,
143 0x70, 0x68, 0x61, 0x6e, 0x75, 0x6d, 0x65, 0x72, 0x69, 0x63, 0x29, 0x0a,
144 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x6e,
145 0x64, 0x69, 0x63, 0x65, 0x73, 0x0a,
146 0x65, 0x6e, 0x64, 0x0a,
147 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x72, 0x64,
148 0x65, 0x72, 0x65, 0x64, 0x5f, 0x6e, 0x65, 0x78, 0x74, 0x20, 0x28, 0x74, 0x2c, 0x20, 0x73, 0x74, 0x61, 0x74,
150 0x09, 0x69, 0x66, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, 0x74,
151 0x68, 0x65, 0x6e, 0x0a,
152 0x09, 0x09, 0x74, 0x2e, 0x5f, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x49, 0x6e, 0x64, 0x69, 0x63,
153 0x65, 0x73, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x6e, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x5f, 0x69,
154 0x6e, 0x64, 0x69, 0x63, 0x65, 0x73, 0x20, 0x28, 0x74, 0x29, 0x0a,
155 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x3d, 0x20, 0x74, 0x2e, 0x5f, 0x5f,
156 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x49, 0x6e, 0x64, 0x69, 0x63, 0x65, 0x73, 0x5b, 0x31, 0x5d, 0x0a,
157 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6b, 0x65, 0x79, 0x2c, 0x20, 0x74, 0x5b, 0x6b, 0x65,
159 0x09, 0x65, 0x6e, 0x64, 0x0a,
160 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x0a,
161 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x31, 0x2c, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e,
162 0x67, 0x65, 0x74, 0x6e, 0x28, 0x74, 0x2e, 0x5f, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x49, 0x6e,
163 0x64, 0x69, 0x63, 0x65, 0x73, 0x29, 0x20, 0x64, 0x6f, 0x0a,
164 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x2e, 0x5f, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x49, 0x6e,
165 0x64, 0x69, 0x63, 0x65, 0x73, 0x5b, 0x69, 0x5d, 0x20, 0x3d, 0x3d, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20,
166 0x74, 0x68, 0x65, 0x6e, 0x0a,
167 0x09, 0x09, 0x09, 0x6b, 0x65, 0x79, 0x20, 0x3d, 0x20, 0x74, 0x2e, 0x5f, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72,
168 0x65, 0x64, 0x49, 0x6e, 0x64, 0x69, 0x63, 0x65, 0x73, 0x5b, 0x69, 0x20, 0x2b, 0x20, 0x31, 0x5d, 0x0a,
169 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
170 0x09, 0x65, 0x6e, 0x64, 0x0a,
171 0x09, 0x69, 0x66, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
172 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6b, 0x65, 0x79, 0x2c, 0x20, 0x74, 0x5b, 0x6b, 0x65,
174 0x09, 0x65, 0x6e, 0x64, 0x0a,
175 0x09, 0x74, 0x2e, 0x5f, 0x5f, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x49, 0x6e, 0x64, 0x69, 0x63, 0x65,
176 0x73, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x0a,
177 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x0a,
178 0x65, 0x6e, 0x64, 0x0a,
179 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x72, 0x64,
180 0x65, 0x72, 0x65, 0x64, 0x5f, 0x70, 0x61, 0x69, 0x72, 0x73, 0x20, 0x28, 0x74, 0x29, 0x0a,
181 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x5f, 0x6e, 0x65,
182 0x78, 0x74, 0x2c, 0x20, 0x74, 0x2c, 0x20, 0x6e, 0x69, 0x6c, 0x0a,
183 0x65, 0x6e, 0x64, 0x0a,
184 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65,
185 0x20, 0x28, 0x6f, 0x2c, 0x20, 0x74, 0x61, 0x62, 0x73, 0x2c, 0x20, 0x73, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x29, 0x0a,
186 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x22,
188 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x61, 0x69, 0x72, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20,
189 0x3d, 0x20, 0x70, 0x61, 0x69, 0x72, 0x73, 0x0a,
190 0x09, 0x69, 0x66, 0x20, 0x73, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
191 0x09, 0x09, 0x70, 0x61, 0x69, 0x72, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x3d, 0x20, 0x6f, 0x72, 0x64,
192 0x65, 0x72, 0x65, 0x64, 0x5f, 0x70, 0x61, 0x69, 0x72, 0x73, 0x0a,
193 0x09, 0x65, 0x6e, 0x64, 0x0a,
195 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x3d, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, 0x74,
196 0x68, 0x65, 0x6e, 0x0a,
197 0x20, 0x20, 0x20, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a,
198 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
199 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6e,
200 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
201 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c,
202 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x6f, 0x29, 0x0a,
203 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29, 0x20, 0x3d,
204 0x3d, 0x20, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
205 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c,
206 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x6f, 0x29, 0x0a,
207 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29, 0x20, 0x3d,
208 0x3d, 0x20, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
209 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c,
210 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74,
211 0x28, 0x22, 0x25, 0x71, 0x22, 0x2c, 0x20, 0x6f, 0x29, 0x0a,
212 0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29, 0x20, 0x3d, 0x3d,
213 0x20, 0x22, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x69, 0x73, 0x6c, 0x69, 0x73,
214 0x74, 0x28, 0x6f, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
215 0x09, 0x09, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20,
216 0x2e, 0x2e, 0x20, 0x22, 0x7b, 0x22, 0x0a,
217 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x77, 0x61, 0x73, 0x5f, 0x73,
218 0x75, 0x62, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a,
219 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x69, 0x70, 0x61, 0x69, 0x72,
220 0x73, 0x28, 0x6f, 0x29, 0x20, 0x64, 0x6f, 0x0a,
221 0x09, 0x09, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x77, 0x61, 0x73, 0x5f, 0x73, 0x75, 0x62, 0x74, 0x61, 0x62,
222 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a,
223 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x22,
224 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
225 0x09, 0x09, 0x09, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x77, 0x61, 0x73, 0x5f, 0x73, 0x75, 0x62, 0x74, 0x61,
226 0x62, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a,
227 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72,
228 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74,
229 0x61, 0x62, 0x73, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x72,
230 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x28, 0x76, 0x2c, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e, 0x2e, 0x20,
231 0x22, 0x20, 0x20, 0x22, 0x2c, 0x20, 0x73, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22,
233 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a,
234 0x09, 0x09, 0x09, 0x09, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c,
235 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69,
236 0x6e, 0x67, 0x28, 0x76, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2c, 0x22, 0x0a,
237 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
238 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
239 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x77, 0x61, 0x73, 0x5f, 0x73, 0x75, 0x62, 0x74,
240 0x61, 0x62, 0x6c, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
241 0x09, 0x09, 0x09, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
242 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x61, 0x62, 0x73, 0x0a,
243 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
244 0x09, 0x09, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20,
245 0x2e, 0x2e, 0x20, 0x22, 0x7d, 0x22, 0x0a,
246 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29, 0x20, 0x3d,
247 0x3d, 0x20, 0x22, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
248 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x2e, 0x64, 0x6f, 0x6e, 0x74, 0x5f, 0x73, 0x65, 0x72, 0x69,
249 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x5f, 0x6d, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
250 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x7b, 0x7d, 0x22, 0x0a,
251 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
252 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c,
253 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x7b, 0x5c, 0x6e, 0x22, 0x0a,
254 0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x70, 0x61, 0x69,
255 0x72, 0x73, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x28, 0x6f, 0x29, 0x20, 0x64, 0x6f, 0x0a,
256 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x7e,
257 0x3d, 0x20, 0x22, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
258 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x20, 0x73, 0x75,
259 0x72, 0x65, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x65, 0x64, 0x20, 0x6b,
260 0x65, 0x79, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x6c, 0x79, 0x20, 0x61,
261 0x72, 0x65, 0x20, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x69, 0x66, 0x69, 0x65, 0x64, 0x0a,
262 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6b, 0x29,
263 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
264 0x09, 0x09, 0x09, 0x09, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x3d,
265 0x3d, 0x20, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
266 0x09, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20,
267 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e,
268 0x2e, 0x20, 0x22, 0x20, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x5b, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74,
269 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x6b, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x5d, 0x20, 0x3d,
270 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x76, 0x29, 0x20,
271 0x2e, 0x2e, 0x20, 0x22, 0x2c, 0x5c, 0x6e, 0x22, 0x0a,
272 0x09, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a,
273 0x09, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20,
274 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e,
275 0x2e, 0x20, 0x22, 0x20, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x5b, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74,
276 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x6b, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x5d, 0x20, 0x3d,
277 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x28, 0x76, 0x2c,
278 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x20, 0x22, 0x2c, 0x20, 0x73, 0x6f, 0x72,
279 0x74, 0x65, 0x64, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2c, 0x5c, 0x6e, 0x22, 0x0a,
280 0x09, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
281 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a,
282 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d,
283 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e, 0x2e,
284 0x20, 0x22, 0x20, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x6b, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x3d, 0x20,
285 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x28, 0x76, 0x2c, 0x20,
286 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x20, 0x22, 0x2c, 0x20, 0x73, 0x6f, 0x72, 0x74,
287 0x65, 0x64, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2c, 0x5c, 0x6e, 0x22, 0x0a,
288 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
289 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
290 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
291 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c,
292 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x7d, 0x22, 0x0a,
293 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a,
294 0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x22, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x65,
295 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x69, 0x6e, 0x67, 0x20, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x20, 0x6f, 0x66,
296 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29,
298 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
299 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x0a,
300 0x65, 0x6e, 0x64, 0x0a,
301 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x0a,
307 void bail(lua_State * L,
const char *msg)
309 std::cerr << msg << lua_tostring(L, -1) << endl;
313 void stack_print (
const char *file,
int line, lua_State * L)
315 cout << file <<
":" << line <<
": stack size: " << lua_gettop(L) << endl;
316 for (
int i = 1; i < lua_gettop(L) + 1; i++) {
317 cout << file <<
":" << line <<
": ";
319 if (lua_istable (L, i))
320 cout <<
" table" << endl;
321 else if (lua_isnumber (L, i))
322 cout <<
" number: " << lua_tonumber (L, i) << endl;
323 else if (lua_isuserdata (L, i)) {
324 void* userdata = (
void*) lua_touserdata (L, i);
325 cout <<
" userdata (" << userdata <<
")" << endl;
326 }
else if (lua_isstring (L, i))
327 cout <<
" string: " << lua_tostring(L, i) << endl;
328 else if (lua_isfunction (L, i))
329 cout <<
" function" << endl;
330 else if (lua_isnil (L, i))
331 cout <<
" nil" << endl;
333 cout <<
" unknown: " << lua_typename (L, lua_type (L, i)) << endl;
337 void l_push_LuaKey (lua_State * L,
const LuaKey & key)
339 if (key.type == LuaKey::Integer)
340 lua_pushnumber (L, key.int_value);
342 lua_pushstring(L, key.string_value.c_str());
345 bool query_key_stack (lua_State * L, std::vector<LuaKey> key_stack)
347 for (
int i = (
int)key_stack.size() - 1; i >= 0; i--) {
350 if (lua_gettop(L) == 0) {
351 lua_getglobal (L, key_stack[key_stack.size() - 1].string_value.c_str());
353 if (lua_isnil(L, -1)) {
360 l_push_LuaKey (L, key_stack[(
size_t) i]);
362 lua_gettable (L, -2);
365 if (lua_isnil(L, -1)) {
373 void create_key_stack (lua_State * L, std::vector<LuaKey> key_stack)
375 for (
size_t i = key_stack.size() - 1; i > 0; i--) {
378 if (lua_gettop(L) == 0) {
379 lua_getglobal (L, key_stack[key_stack.size() - 1].string_value.c_str());
381 if (lua_isnil(L, -1)) {
384 lua_pushvalue(L, -1);
385 lua_setglobal(L, key_stack[key_stack.size() - 1].string_value.c_str());
391 l_push_LuaKey (L, key_stack[i]);
393 lua_pushvalue (L, -1);
394 lua_gettable (L, -3);
396 if (lua_isnil(L, -1)) {
401 lua_pushvalue(L, -2);
402 lua_settable (L, -4);
410 std::vector<LuaKey> LuaTableNode::getKeyStack()
412 std::vector<LuaKey> result;
417 result.push_back (node_ptr->key);
418 node_ptr = node_ptr->parent;
419 }
while (node_ptr != NULL);
424 std::string LuaTableNode::keyStackToString()
426 std::vector<LuaKey> key_stack = getKeyStack();
428 ostringstream result_stream (
"");
429 for (
int i = (
int)key_stack.size() - 1; i >= 0; i--) {
430 if (key_stack[(
size_t) i].type == LuaKey::String)
431 result_stream <<
"[\"" << key_stack[(
size_t) i].string_value <<
"\"]";
433 result_stream <<
"[" << key_stack[(size_t) i].int_value <<
"]";
436 return result_stream.str();
439 bool LuaTableNode::stackQueryValue()
441 lua_State * L = luaTable->L;
442 stackTop = lua_gettop(L);
444 std::vector<LuaKey> key_stack = getKeyStack();
446 return query_key_stack (L, key_stack);
449 void LuaTableNode::stackCreateValue()
451 lua_State * L = luaTable->L;
452 stackTop = lua_gettop(L);
454 std::vector<LuaKey> key_stack = getKeyStack();
456 create_key_stack (L, key_stack);
459 LuaTable LuaTableNode::stackQueryTable()
461 lua_State * L = luaTable->L;
462 stackTop = lua_gettop(L);
464 std::vector<LuaKey> key_stack = getKeyStack();
466 if (!query_key_stack (L, key_stack)) {
467 std::cerr <<
"Error: could not query table " << key <<
"." << std::endl;
471 return LuaTable::fromLuaState (L);
474 LuaTable LuaTableNode::stackCreateLuaTable()
476 lua_State * L = luaTable->L;
477 stackTop = lua_gettop(L);
479 std::vector<LuaKey> key_stack = getKeyStack();
481 create_key_stack (L, key_stack);
484 lua_newtable(luaTable->L);
487 lua_pushvalue(luaTable->L, -2);
488 lua_settable(luaTable->L, -4);
490 return LuaTable::fromLuaState (L);
493 void LuaTableNode::stackPushKey()
495 l_push_LuaKey (luaTable->L, key);
498 void LuaTableNode::stackRestore()
500 lua_pop (luaTable->L, lua_gettop(luaTable->L) - stackTop);
503 bool LuaTableNode::exists()
507 if (!stackQueryValue())
515 void LuaTableNode::remove()
517 if (stackQueryValue()) {
518 lua_pop(luaTable->L, 1);
520 if (lua_gettop(luaTable->L) != 0) {
521 l_push_LuaKey (luaTable->L, key);
522 lua_pushnil (luaTable->L);
523 lua_settable (luaTable->L, -3);
525 lua_pushnil (luaTable->L);
526 lua_setglobal (luaTable->L, key.string_value.c_str());
533 size_t LuaTableNode::length()
537 if (stackQueryValue())
539 #ifdef PINOCCHIO_LUA_VERSION_GREATER_5_2 540 result = lua_rawlen(luaTable->L, -1);
542 result = lua_objlen(luaTable->L, -1);
551 std::vector<LuaKey> LuaTableNode::keys()
553 std::vector<LuaKey> result;
555 if (stackQueryValue()) {
557 lua_pushnil(luaTable->L);
558 while (lua_next(luaTable->L, -2) != 0) {
559 if (lua_isnumber(luaTable->L, -2)) {
560 double number = lua_tonumber (luaTable->L, -2);
562 if (modf (number, &frac) == 0) {
563 LuaKey key (static_cast<int>(number));
564 result.push_back (key);
566 }
else if (lua_isstring (luaTable->L, -2)) {
567 LuaKey key (lua_tostring(luaTable->L, -2));
568 result.push_back (key);
570 cerr <<
"Warning: invalid LuaKey type for key " << lua_typename(luaTable->L, lua_type(luaTable->L, -2)) <<
"!" << endl;
573 lua_pop(luaTable->L, 1);
583 template<>
bool LuaTableNode::getDefault<bool>(
const bool & default_value)
585 bool result = default_value;
587 if (stackQueryValue()) {
588 result = lua_toboolean (luaTable->L, -1);
596 template<>
float LuaTableNode::getDefault<float>(
const float & default_value)
598 float result = default_value;
600 if (stackQueryValue()) {
601 result =
static_cast<float>(lua_tonumber (luaTable->L, -1));
609 template<>
double LuaTableNode::getDefault<double>(
const double & default_value)
611 double result = default_value;
613 if (stackQueryValue()) {
614 result = lua_tonumber (luaTable->L, -1);
622 template<> std::string LuaTableNode::getDefault<std::string>(
const std::string & default_value)
624 std::string result = default_value;
626 if (stackQueryValue() && lua_isstring(luaTable->L, -1)) {
627 result = lua_tostring (luaTable->L, -1);
635 template<>
void LuaTableNode::set<bool>(
const bool & value)
639 l_push_LuaKey (luaTable->L, key);
640 lua_pushboolean(luaTable->L, value);
642 lua_settable (luaTable->L, -3);
647 template<>
void LuaTableNode::set<float>(
const float & value)
651 l_push_LuaKey (luaTable->L, key);
652 lua_pushnumber(luaTable->L, static_cast<double>(value));
654 lua_settable (luaTable->L, -3);
659 template<>
void LuaTableNode::set<double>(
const double & value)
663 l_push_LuaKey (luaTable->L, key);
664 lua_pushnumber(luaTable->L, value);
666 lua_settable (luaTable->L, -3);
671 template<>
void LuaTableNode::set<std::string>(
const std::string & value)
675 l_push_LuaKey (luaTable->L, key);
676 lua_pushstring(luaTable->L, value.c_str());
678 lua_settable (luaTable->L, -3);
686 LuaTable::~LuaTable()
688 if (deleteLuaState) {
694 int LuaTable::length()
696 if ((lua_gettop(L) == 0) || (lua_type (L, -1) != LUA_TTABLE)) {
697 cerr <<
"Error: cannot query table length. No table on stack!" << endl;
702 #ifdef PINOCCHIO_LUA_VERSION_GREATER_5_2 703 result = lua_rawlen(L, -1);
705 result = lua_objlen(L, -1);
713 if (
this != &luatable) {
714 if (deleteLuaState && L != luatable.L) {
715 lua_close (luatable.L);
717 filename = luatable.filename;
719 deleteLuaState = luatable.deleteLuaState;
725 LuaTable LuaTable::fromFile (
const char* _filename)
729 result.filename = _filename;
730 result.L = luaL_newstate();
731 result.deleteLuaState =
true;
732 luaL_openlibs(result.L);
735 result.addSearchPath(get_file_directory (_filename).c_str());
738 if (luaL_dofile (result.L, _filename)) {
739 bail (result.L,
"Error running file: ");
745 LuaTable LuaTable::fromLuaExpression (
const char* lua_expr)
749 result.L = luaL_newstate();
750 result.deleteLuaState =
true;
751 luaL_openlibs(result.L);
753 if (luaL_loadstring (result.L, lua_expr)) {
754 bail (result.L,
"Error compiling expression!");
757 if (lua_pcall (result.L, 0, LUA_MULTRET, 0)) {
758 bail (result.L,
"Error running expression!");
764 LuaTable LuaTable::fromLuaState (lua_State* L)
769 result.deleteLuaState =
false;
774 void LuaTable::addSearchPath(
const char* path)
777 cerr <<
"Error: Cannot add search path: Lua state is not initialized!" << endl;
781 lua_getglobal(L,
"package");
782 lua_getfield (L, -1,
"path");
783 if (lua_type(L, -1) != LUA_TSTRING) {
784 cerr <<
"Error: could not get package.path!" << endl;
788 string package_path = lua_tostring (L, -1);
789 package_path = package_path + string(path) +
"?.lua;";
791 lua_pushstring(L, package_path.c_str());
792 lua_setfield (L, -3,
"path");
797 std::string LuaTable::serialize()
801 int current_top = lua_gettop(L);
802 if (lua_gettop(L) != 0) {
803 if (luaL_loadstring(L, serialize_std)) {
804 bail (L,
"Error loading serialization function: ");
807 if (lua_pcall(L, 0, 0, 0)) {
808 bail (L,
"Error compiling serialization function: " );
811 lua_getglobal (L,
"serialize");
812 assert (lua_isfunction (L, -1));
813 lua_pushvalue (L, -2);
814 if (lua_pcall (L, 1, 1, 0)) {
815 bail (L,
"Error while serializing: ");
817 result = string(
"return ") + lua_tostring (L, -1);
819 cerr <<
"Cannot serialize global Lua state!" << endl;
823 lua_pop (L, lua_gettop(L) - current_top);
828 std::string LuaTable::orderedSerialize()
832 int current_top = lua_gettop(L);
833 if (lua_gettop(L) != 0) {
834 if (luaL_loadstring(L, serialize_std)) {
835 bail (L,
"Error loading serialization function: ");
838 if (lua_pcall(L, 0, 0, 0)) {
839 bail (L,
"Error compiling serialization function: " );
842 lua_getglobal (L,
"serialize");
843 assert (lua_isfunction (L, -1));
844 lua_pushvalue (L, -2);
845 lua_pushstring (L,
"");
846 lua_pushboolean (L,
true);
847 if (lua_pcall (L, 3, 1, 0)) {
848 bail (L,
"Error while serializing: ");
850 result = string(
"return ") + lua_tostring (L, -1);
852 cerr <<
"Cannot serialize global Lua state!" << endl;
856 lua_pop (L, lua_gettop(L) - current_top);
std::string name(const LieGroupGenericTpl< LieGroupCollection > &lg)
Visit a LieGroupVariant to get the name of it.