}
}
+ // When using "vim9script autoload" script-local items are prefixed but can
+ // be used with s:name.
+ if (SCRIPT_ID_VALID(current_sctx.sc_sid)
+ && name[0] == 's' && name[1] == ':')
+ {
+ scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
+
+ if (si->sn_autoload_prefix != NULL)
+ {
+ char_u *auto_name = concat_str(si->sn_autoload_prefix, name + 2);
+
+ if (auto_name != NULL)
+ {
+ ht = &globvarht;
+ ret = find_var_in_ht(ht, *name, auto_name, TRUE);
+ if (ret != NULL)
+ {
+ if (htp != NULL)
+ *htp = ht;
+ return ret;
+ }
+ }
+ vim_free(auto_name);
+ }
+ }
+
return NULL;
}
}
/*
- * Set variable "name" to value in "tv".
+ * Set variable "name" to value in "tv_arg".
* When "sid" is non-zero "name" is in the script with this ID.
* If the variable already exists and "is_const" is FALSE the value is updated.
* Otherwise the variable is created.
enddef
" test using an auto-loaded function and variable
-def Test_vim9_autoload()
+def Test_vim9_autoload_full_name()
var lines =<< trim END
vim9script
def some#gettest(): string
return 'test'
enddef
- export func GetMore()
- return Gettest() .. 'more'
+ export var name = 'name'
+
+ export func GetFunc()
+ return Gettest() .. 'more' .. s:name
endfunc
- export var name = 'name'
+ export def GetDef(): string
+ return Gettest() .. 'more' .. name
+ enddef
+
export final fname = 'final'
export const cname = 'const'
END
assert_equal('test', prefixed.Gettest())
assert_equal(1, g:prefixed_loaded)
- assert_equal('testmore', prefixed.GetMore())
+ assert_equal('testmorename', prefixed.GetFunc())
+ assert_equal('testmorename', prefixed.GetDef())
assert_equal('name', prefixed.name)
assert_equal('final', prefixed.fname)
assert_equal('const', prefixed.cname)
# can also get the items by autoload name
lines =<< trim END
call assert_equal('test', prefixed#Gettest())
- call assert_equal('testmore', prefixed#GetMore())
+ call assert_equal('testmorename', prefixed#GetFunc())
call assert_equal('name', prefixed#name)
call assert_equal('final', prefixed#fname)
call assert_equal('const', prefixed#cname)