-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
lua_script_resource_formate_saver.cpp
68 lines (54 loc) · 2.1 KB
/
lua_script_resource_formate_saver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* This file is part of LuaScript
* https://github.com/perbone/luascrip/
*
* Copyright 2017-2024 Paulo Perbone
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
#include "lua_script_resource_formate_saver.h"
#include "constants.h"
#include "debug.h"
#include "lua_script.h"
LuaScriptResourceFormatSaver::LuaScriptResourceFormatSaver() {
print_debug("LuaScriptResourceFormatSaver::constructor");
}
LuaScriptResourceFormatSaver::~LuaScriptResourceFormatSaver() {
print_debug("LuaScriptResourceFormatSaver::destructor");
}
Error LuaScriptResourceFormatSaver::save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags) {
print_debug("LuaScriptResourceFormatSaver::save( p_path = " + p_path + " )");
Ref<LuaScript> script = p_resource;
if (script.is_null())
return ERR_INVALID_PARAMETER;
String source = script->get_source_code();
Error error;
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &error);
if (error != OK)
return error;
file->store_string(source);
if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
return ERR_CANT_CREATE;
}
return OK;
}
void LuaScriptResourceFormatSaver::get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const {
print_debug("LuaScriptResourceFormatSaver::get_recognized_extensions");
if (Object::cast_to<LuaScript>(*p_resource)) {
p_extensions->push_back(LUA_EXTENSION);
}
}
bool LuaScriptResourceFormatSaver::recognize(const Ref<Resource> &p_resource) const {
print_debug("LuaScriptResourceFormatSaver::recognize");
return Object::cast_to<LuaScript>(*p_resource) != nullptr;
}