supertux is using physfs now, this simplifies the code and generalises file handling
[supertux.git] / src / scripting / functions.cpp
1 #include <stdio.h>
2 #include <string>
3 #include <squirrel.h>
4 #include <sqstdio.h>
5 #include "textscroller.h"
6 #include "functions.h"
7 #include "script_interpreter.h"
8 #include "tinygettext/tinygettext.h"
9 #include "resources.h"
10 #include "gettext.h"
11
12 namespace Scripting
13 {
14
15 void set_wakeup_time(float seconds)
16 {
17   ScriptInterpreter::current()->set_wakeup_time(seconds);
18 }
19
20 std::string translate(const std::string& text)
21 {
22   return dictionary_manager.get_dictionary().translate(text);
23 }
24
25 void display_text_file(const std::string& filename)
26 {
27   std::string file 
28     = ScriptInterpreter::current()->get_working_directory() + filename;
29   ::display_text_file(file);
30 }
31
32 void import(HSQUIRRELVM v, const std::string& filename)
33 {
34   std::string file 
35     = ScriptInterpreter::current()->get_working_directory() + filename;
36   if(sqstd_loadfile(v, file.c_str(), true) < 0) {
37     std::cerr << "Warning couldn't load script '" << filename << "' ("
38       << file << ").\n";
39     return;
40   }
41
42   sq_push(v, -2);
43   if(sq_call(v, 1, false) < 0) {
44     std::cerr << "Couldn't execute script '" << filename << "' ("
45       << file << ").\n";
46     return;
47   }
48 }
49
50 }
51