Differences From
Artifact [101fec1406]:
34 34 impl _can_inherit_from_file() -> bool { return true; };
35 35
36 36 impl _handles_global_class_type(string t) -> bool { return false; };
37 37 impl _get_type() -> string {
38 38 gd_string s = {};
39 39 _t(string).newWithUtf8Chars(&s, "JanetScriptText");
40 40 return s;
41 + };
42 + impl _get_public_functions() -> array[dictionary] {
43 + gd_array list;
44 + _t(array).empty(&list, nullptr);
45 + return list;
46 + };
47 + impl _get_public_constants() -> dictionary {
48 + gd_dictionary consts;
49 + _t(dictionary).empty(&consts, nullptr);
50 + return consts;
51 + };
52 + impl _get_public_annotations() -> array[dictionary] {
53 + gd_array list;
54 + _t(array).empty(&list, nullptr);
55 + return list;
41 56 };
42 57 impl _get_recognized_extensions() -> packed-string-array {
43 58 gd_packedStringArray r = {};
44 59 _t(packedStringArray).empty(&r, nullptr);
45 60 _gdu_array_string_pushLit(&r, "janet");
46 61 _gdu_array_string_pushLit(&r, "jimage");
47 62 return r;
................................................................................
183 198 return dict;
184 199 };
185 200 };
186 201
187 202 class JanetScript is ScriptExtension {
188 203 var as string: path;
189 204 var JanetTable*: env;
205 + var pstr: id;
206 + var pstr: exportID;
207 + var pstr: uid;
208 + var pstr: doc;
209 + var pstr: inherit;
190 210
211 + var as array[dictionary]: methodBinds;
212 +
213 + use "vm.h";
214 +
191 215 new {
192 216 _t(string).empty(&me -> path, nullptr);
193 217 me -> env = nullptr;
218 +
219 + _t(array).empty(&me -> methodBinds, nullptr);
220 + me -> id = (pstr){};
221 + me -> exportID = (pstr){};
222 + me -> uid = (pstr){};
223 + me -> doc = (pstr){};
224 + me -> inherit = (pstr){};
194 225 };
195 226 del {
196 227 _t(string).dtor(&me -> path);
228 + _t(array).dtor(&me -> methodBinds);
197 229 if (me -> env) janet_gcunroot(janet_wrap_table(me -> env));
230 + _drop(me -> id);
231 + _drop(me -> exportID);
232 + _drop(me -> uid);
233 + _drop(me -> doc);
234 + _drop(me -> inherit);
235 +
198 236 };
199 237
200 238 class BaseInstance is Object {
201 239 var as ref JanetScript: script;
202 240 del {
203 241 gd_refCounted_unreference(me -> script);
204 242 printf("del script instance\n");
................................................................................
239 277 impl _get_base_script() -> ref Script {
240 278 return nullptr;
241 279 };
242 280 impl _has_static_method(string-name method) -> bool {
243 281 return false;
244 282 };
245 283 impl _is_tool() -> bool { return false; }; (* FIXME *)
246 - impl _get_global_name(string-name id) -> string-name {
284 + impl _get_global_name() -> string-name {
285 + if (me -> exportID.v)
286 + return gdu_internp(me -> exportID);
247 287 return gdu_sym_null();
248 288 };
249 289 impl _is_abstract() -> bool {
250 290 return false; (* TODO abuse for non-class scripts? *)
251 291 };
252 292 impl _get_instance_base_type() -> string-name {
253 - return _gdu_intern("ScriptExtension");
293 + return gdu_internp(me -> inherit);
254 294 };
255 295 impl _is_valid() -> bool {
256 296 return true;
257 297 };
258 298 impl _get_documentation() -> array[dictionary] {
259 299 gd_array dox;
260 300 _t(array).empty(&dox, nullptr);
261 301 auto empty = gdu_sym_null();
262 302 _t(array).setTyped(&dox,
263 303 GDEXTENSION_VARIANT_TYPE_DICTIONARY, &empty, &empty);
264 304 _t(stringName).dtor(&empty);
265 305 return dox;
266 306 };
307 +
308 + use {
309 + static pstr
310 + classParam
311 + ( JanetTable* env,
312 + const char* sym,
313 + pstr dflt
314 + ) {
315 + Janet v = janet_table_rawget(env, janet_csymbolv(sym));
316 + if (janet_type(v) != JANET_TABLE) return dflt;
317 +
318 + Janet s = janet_table_rawget(janet_unwrap_table(v),
319 + janet_ckeywordv("value"));
320 + if (janet_type(s) == JANET_NIL) return dflt;
321 +
322 + JanetString str = janet_unwrap_string(s);
323 + return (pstr) {
324 + .v = (char*)str,
325 + .sz = janet_string_length(str),
326 + };
327 + }
328 + };
329 + impl _reload(bool keepState) -> int {
330 + gd_array_clear(&me -> methodBinds);
331 + /* parse the class environment */
332 + JanetTable* const env = me -> env;
333 + printf("core reload\n");
334 +
335 + pstr id = classParam(env, "@id", (pstr){});
336 + pstr gdid = classParam(env, "@gd-id", (pstr){});
337 + pstr inherit = classParam(env, "@inherit", _pstrLit("RefCounted"));
338 + pstr doc = classParam(env, "@doc", (pstr){});
339 +
340 + if (gdid.v) me -> exportID = pstrDup(gdid);
341 + else me -> exportID = pstrDup(id);
342 + if (id.v) me -> id = pstrDup(id);
343 +
344 + if (doc.v) me -> doc = pstrDup(doc);
345 + if (inherit.v) me -> inherit = pstrDup(inherit);
346 +
347 + Janet wenv = janet_wrap_table(env);
348 + /* scan for bindings */
349 + for (Janet key = janet_next(wenv, janet_wrap_nil());
350 + janet_type(key) != JANET_NIL;
351 + key = janet_next(wenv, key)) {
352 +
353 + Janet val = janet_table_rawget(env, key);
354 +
355 + if (!janet_checktypes(key, JANET_TFLAG_BYTES)) continue;
356 + printf(" * consider val id %s (%s)\n",
357 + janet_unwrap_string(key),
358 + janet_type_names[janet_type(val)]);
359 + if (!janet_checktypes(val, JANET_TFLAG_DICTIONARY)) continue;
360 + JanetTable* v = janet_unwrap_table(val);
361 + Janet ty;
362 + const bool priv = gdjn_vm_metaFlag(v, "private");
363 + JanetString jkey = janet_unwrap_string(key);
364 +
365 + if (gdjn_vm_metaKey(v, "method", &ty)) {
366 + /* && janet_type(ty) == JANET_TABLE) { */
367 + printf(" * is method %s\n",
368 + janet_type_names[janet_type(ty)]);
369 + JanetTable* tspec = janet_unwrap_table(ty);
370 + /* janet_unwrap_function() */
371 + gd_dictionary meta;
372 + _t(dictionary).empty(&meta, nullptr);
373 + gdu_setKey_str(&meta, _pstrLit("name"),
374 + (pstr) {
375 + .sz = janet_string_length(jkey),
376 + .v = (char*)jkey,
377 + });
378 +
379 + /* build arg array */
380 + gd_array argList;
381 + _t(array).empty(&argList, nullptr);
382 + for (size_t j = 0; j < tspec -> count; ++j) {
383 + /*
384 + gd_dictionary
385 + gdu_array_append(&argList_, )
386 + */
387 + }
388 +
389 + {gd_variant tv = gd_variant_of_array(argList);
390 + gdu_setKey(&meta, _pstrLit("args"), &tv);}
391 +
392 +
393 + {gd_variant tv = gd_variant_of_dictionary(meta);
394 + gd_array_append(&me -> methodBinds, &tv);}
395 +
396 + _t(array).dtor(&argList);
397 + _t(dictionary).dtor(&meta);
398 + } else if (gdjn_vm_metaKey(v, "prop", &ty)) {
399 + } else if (gdjn_vm_metaKey(v, "const", &ty)) {
400 + } else if (gdjn_vm_metaFlag(v, "subclass")) {
401 + };
402 + /* else: the value is not meaningful to godot; skip over */
403 + }
404 + return gd_Error_ok;
405 + };
267 406
268 407 (*
269 408 impl _update_exports() {
270 409
271 410 };
272 411 impl _placeholder_instance_create
273 412 (ref Object forObj) -> ref Object {
................................................................................
322 461 if (e == 0) {
323 462 me -> super.env = cls;
324 463 } else {
325 464 _err("janet module could not be loaded");
326 465 errorCode = gd_Error_errParseError;
327 466 janet_gcunroot(janet_wrap_table(cls));
328 467 }
468 + if (errorCode != gd_Error_ok) return errorCode;
329 469
330 - return errorCode;
470 + /* invoke super by static dispatch */
471 + return gdjn_class_JanetScript_method__reload(&me -> super, keepState);
331 472 };
332 473 };
333 474
334 475 import {
335 476 typedef struct gdjn_janet_image {
336 477 size_t sz;
337 478 uint8_t* buf;