/*************************************************************************/ /* csharp_script.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "csharp_script.h" #include #include "os/file_access.h" #include "os/os.h" #include "os/thread.h" #include "project_settings.h" #ifdef TOOLS_ENABLED #include "editor/bindings_generator.h" #include "editor/csharp_project.h" #include "editor/editor_node.h" #include "editor/godotsharp_editor.h" #endif #include "godotsharp_dirs.h" #include "mono_gd/gd_mono_class.h" #include "mono_gd/gd_mono_marshal.h" #include "signal_awaiter_utils.h" #define CACHED_STRING_NAME(m_var) (CSharpLanguage::get_singleton()->string_names.m_var) static bool _create_project_solution_if_needed() { String sln_path = GodotSharpDirs::get_project_sln_path(); String csproj_path = GodotSharpDirs::get_project_csproj_path(); if (!FileAccess::exists(sln_path) || !FileAccess::exists(csproj_path)) { // A solution does not yet exist, create a new one CRASH_COND(GodotSharpEditor::get_singleton() == NULL); return GodotSharpEditor::get_singleton()->call("_create_project_solution"); } return true; } CSharpLanguage *CSharpLanguage::singleton = NULL; String CSharpLanguage::get_name() const { return "C#"; } String CSharpLanguage::get_type() const { return "CSharpScript"; } String CSharpLanguage::get_extension() const { return "cs"; } Error CSharpLanguage::execute_file(const String &p_path) { // ?? return OK; } #ifdef TOOLS_ENABLED void gdsharp_editor_init_callback() { EditorNode *editor = EditorNode::get_singleton(); editor->add_child(memnew(GodotSharpEditor(editor))); } #endif void CSharpLanguage::init() { gdmono = memnew(GDMono); gdmono->initialize(); #ifdef MONO_GLUE_DISABLED WARN_PRINT("This binary is built with `mono_glue=no` and cannot be used for scripting"); #endif #if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) if (gdmono->get_editor_tools_assembly() != NULL) { List cmdline_args = OS::get_singleton()->get_cmdline_args(); BindingsGenerator::handle_cmdline_args(cmdline_args); } #endif #ifdef TOOLS_ENABLED EditorNode::add_init_callback(&gdsharp_editor_init_callback); #endif } void CSharpLanguage::finish() { if (gdmono) { memdelete(gdmono); gdmono = NULL; } } void CSharpLanguage::get_reserved_words(List *p_words) const { static const char *_reserved_words[] = { // Reserved keywords "abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "forech", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "volatile", "void", "while", // Contextual keywords. Not reserved words, but I guess we should include // them because this seems to be used only for syntax highlighting. "add", "ascending", "by", "descending", "dynamic", "equals", "from", "get", "global", "group", "in", "into", "join", "let", "on", "orderby", "partial", "remove", "select", "set", "value", "var", "where", "yield", 0 }; const char **w = _reserved_words; while (*w) { p_words->push_back(*w); w++; } } void CSharpLanguage::get_comment_delimiters(List *p_delimiters) const { p_delimiters->push_back("//"); // single-line comment p_delimiters->push_back("/* */"); // delimited comment } void CSharpLanguage::get_string_delimiters(List *p_delimiters) const { p_delimiters->push_back("' '"); // character literal p_delimiters->push_back("\" \""); // regular string literal p_delimiters->push_back("@\" \""); // verbatim string literal } Ref