Skip to content
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

Ссылки #8

Closed
ghost opened this issue Oct 1, 2012 · 3 comments
Closed

Ссылки #8

ghost opened this issue Oct 1, 2012 · 3 comments

Comments

@ghost
Copy link

ghost commented Oct 1, 2012

Ссылки на переменные, как в PHP (или, как в Си, наверное, когда переменная ссылается не на значение, а на адрес).

var a = 10;
var b = &a

b = (b + 1);

print(a, b);

Вернёт 11, 11.

Можно в противовес ключевому слову clone (используемое для объектов и массивов), как в D использовать слово ref

var a = 10;
var b = ref a

b = (b + 1);

print(a, b);

В том числе и для параметров функции

var a = 1;

function my(ref outter){
   outter = (outter + 1);
}

my(a);
print a; // 2

Порой это очень удобно.

@unitpoint
Copy link
Owner

введение ссылок сильно усложнит реализацию языка, пока не планирую

@Amorph
Copy link

Amorph commented Oct 3, 2012

В Lua значения можно оборачивать значения в контейнеры, возможно ли в OS такое?

local container = { a = 1 }

function my( val )
    val.a = val.a + 1

end

my(container)
print(container.a)

@unitpoint
Copy link
Owner

да, разумеется это будет работать

unitpoint pushed a commit that referenced this issue Feb 18, 2014
1.17.5-rc, fix 'for' loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants