+#ifdef HAVE_LUA
+ int is_lua = (file != NULL && strlen(file) > 3 && file[strlen(file)-3] == 'l' && file[strlen(file)-2] == 'u'
+ && file[strlen(file)-1] == 'a');
+#endif
+
+ surf_parse_init_callbacks();
+
+#ifdef HAVE_LUA
+ /* Check if file extension is "lua". If so, we will use
+ * the lua bindings to parse the platform file (since it is
+ * written in lua). If not, we will use the (old?) XML parser
+ */
+ if (is_lua) {
+ // NOTE: After executing the lua_pcall() below,
+ // sglua_get_maestro() will not be NULL, since the
+ // SimGrid module was loaded!
+ // C. Heinrich 01/2016: Not sure if this is still required after I
+ // ripped out most of that bloody Lua simulation stuff. We may
+ // want to check and maybe we can clean that up.
+ lua_State* L;
+
+ if (L == NULL) {
+ L = luaL_newstate();
+ }
+ luaL_openlibs(L);
+
+ luaL_loadfile(L, file); // This loads the file without executing it.
+
+ /* Run the script */
+ if (lua_pcall(L, 0, 0, 0)) {
+ XBT_ERROR("FATAL ERROR:\n %s: %s\n\n", "Lua call failed. Errormessage:", lua_tostring(L, -1));
+ xbt_die("Lua call failed. See Log");
+ }
+ }
+ else
+#endif
+ { // Use XML parser
+
+ int parse_status;
+
+ /* init the flex parser */
+ surfxml_buffer_stack_stack_ptr = 1;
+ surfxml_buffer_stack_stack[0] = 0;
+ after_config_done = 0;
+ surf_parse_open(file);
+
+ traces_set_list = xbt_dict_new_homogeneous(NULL);
+ trace_connect_list_host_avail = xbt_dict_new_homogeneous(free);
+ trace_connect_list_power = xbt_dict_new_homogeneous(free);
+ trace_connect_list_link_avail = xbt_dict_new_homogeneous(free);
+ trace_connect_list_bandwidth = xbt_dict_new_homogeneous(free);
+ trace_connect_list_latency = xbt_dict_new_homogeneous(free);
+
+ /* Init my data */
+ if (!surfxml_bufferstack_stack)
+ surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), NULL);
+
+ /* Do the actual parsing */
+ parse_status = surf_parse();
+
+ /* Free my data */
+ xbt_dict_free(&trace_connect_list_host_avail);
+ xbt_dict_free(&trace_connect_list_power);
+ xbt_dict_free(&trace_connect_list_link_avail);
+ xbt_dict_free(&trace_connect_list_bandwidth);
+ xbt_dict_free(&trace_connect_list_latency);
+ xbt_dict_free(&traces_set_list);
+ xbt_dict_free(&random_data_list);
+ xbt_dynar_free(&surfxml_bufferstack_stack);
+
+ surf_parse_close();
+
+ if (parse_status)
+ surf_parse_error("Parse error in %s", file);