-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Added YueScript support #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,6 +351,51 @@ static godot_pluginscript_language_desc lps_language_desc = { | |
}, | ||
}; | ||
|
||
static godot_pluginscript_language_desc lps_yue_language_desc = { | ||
.name = "YueScript", | ||
.type = "YueScript", | ||
.extension = "yue", | ||
.recognized_extensions = (const char *[]){ "yue", NULL }, | ||
.init = &lps_language_init, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Godot will call this init function twice, once for each language, so that 2 |
||
.finish = &lps_language_finish, | ||
.reserved_words = (const char *[]){ | ||
// Lua keywords | ||
"and", "break", "do", "else", "elseif", | ||
"false", "for", "if", "in", | ||
"local", "nil", "not", "or", "return", | ||
"then", "true", "until", "while", | ||
// Other remarkable identifiers | ||
"self", "_G", "_VERSION", | ||
// YueScript specific keywords | ||
"@", "@@", "continue", "class", "extends", | ||
gilzoide marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"export", "switch", "super", "unless", | ||
"when", "with", | ||
#if LUA_VERSION_NUM >= 502 | ||
"_ENV", | ||
#endif | ||
Comment on lines
+373
to
+375
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
"bool", "int", "float", | ||
NULL | ||
}, | ||
.comment_delimiters = (const char *[]){ "--", NULL }, | ||
.string_delimiters = (const char *[]){ "' '", "\" \"", "[[ ]]", "[=[ ]=]", NULL }, | ||
.has_named_classes = false, | ||
.supports_builtin_mode = false, | ||
.add_global_constant = &lps_language_add_global_constant, | ||
|
||
.script_desc = { | ||
.init = &lps_script_init, | ||
.finish = &lps_script_finish, | ||
.instance_desc = { | ||
.init = &lps_instance_init, | ||
.finish = &lps_instance_finish, | ||
.set_prop = &lps_instance_set_prop, | ||
.get_prop = &lps_instance_get_prop, | ||
.call_method = &lps_instance_call_method, | ||
.notification = &lps_instance_notification, | ||
}, | ||
}, | ||
}; | ||
|
||
#define PREFIX_SYMBOL(s) lps_ ## s | ||
|
||
// GDNative functions | ||
|
@@ -365,6 +410,7 @@ GDN_EXPORT void PREFIX_SYMBOL(gdnative_init)(godot_gdnative_init_options *option | |
in_editor = options->in_editor; | ||
if (in_editor) { | ||
lps_register_in_editor_callbacks(&lps_language_desc); | ||
lps_register_in_editor_callbacks(&lps_yue_language_desc); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The editor callbacks implemented ("validate", "get_template_source_code" and "make_function") should probably have a specific implementation for Yuescript, since the language is quite different. |
||
} | ||
|
||
#ifdef LUAJIT_DYNAMICALLY_LINKED | ||
|
@@ -386,6 +432,7 @@ GDN_EXPORT void PREFIX_SYMBOL(gdnative_init)(godot_gdnative_init_options *option | |
#endif | ||
|
||
hgdn_pluginscript_api->godot_pluginscript_register_language(&lps_language_desc); | ||
hgdn_pluginscript_api->godot_pluginscript_register_language(&lps_yue_language_desc); | ||
gilzoide marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
GDN_EXPORT void PREFIX_SYMBOL(gdnative_terminate)(godot_gdnative_terminate_options *options) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
-- 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. | ||
|
||
local lps_scripts = {} | ||
local lps_instances = setmetatable({}, weak_k) | ||
|
||
|
@@ -97,6 +98,14 @@ pluginscript_callbacks.script_init = wrap_callback(function(manifest, path, sour | |
manifest = ffi_cast('godot_pluginscript_script_manifest *', manifest) | ||
path = tostring(ffi_cast('godot_string *', path)) | ||
source = tostring(ffi_cast('godot_string *', source)) | ||
local is_yue = path:sub(-4) == '.yue' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to fix tabbing on this as well (or most of the code rather). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding specific extra code for Yuescript in |
||
|
||
if is_yue then | ||
local yue = require('yue') | ||
local codes, err, globals = yue.to_lua(source) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the file is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'd better compile and/or distribute the Yuescript shared library to end users, since it will be needed in runtime for the game/app. If the code would be compiled ahead-of-time as part of the build process, for example, than it would be more ok (although still somewhat annoying) to ask devs for obtaining it by themselves. |
||
source = codes | ||
end | ||
|
||
err = ffi_cast('godot_error *', err) | ||
|
||
lps_callstack:push('script_load', '@', string_quote(path)) | ||
|
@@ -114,14 +123,28 @@ pluginscript_callbacks.script_init = wrap_callback(function(manifest, path, sour | |
return | ||
end | ||
lps_coroutine_pool:release(co) | ||
|
||
if type(script) ~= 'table' then | ||
api.godot_print_error('Script must return a table', path, path, -1) | ||
return | ||
end | ||
|
||
if is_yue then | ||
if script.__base ~= nil then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case we detect a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite like these |
||
script = script.__base | ||
end | ||
end | ||
|
||
local known_properties = {} | ||
for k, v in pairs(script) do | ||
if k == 'class_name' then | ||
if is_yue and ( | ||
k == '__class' or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a simple ignore for the values of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, maybe ignoring anything that starts with |
||
k == '__index' or | ||
k == '__base' | ||
) | ||
then | ||
|
||
elseif k == 'class_name' then | ||
manifest.name = ffi_gc(StringName(v), nil) | ||
elseif k == 'is_tool' then | ||
manifest.is_tool = bool(v) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,9 @@ function export(metadata) | |
return prop | ||
end | ||
|
||
-- Another alias for `export` since it's a reserved keyword in | ||
-- YueScript | ||
exp = export | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a small alias for I could also add an macro for this in YueScript so I can just use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
local Signal = {} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a specific
lps_yue_language_desc
for custom names, extension and reserved keywords.Turns out you can just register multiple language in one GDNative binding! Super cool :)
Since all of the functions are the same, it means changes / improvements on the Lua side will automatically be available for YueScript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah! Not only that, if we had any NativeScript classes or anything else we could add in the same library as well =]