LINUX.ORG.RU

История изменений

Исправление LINUX-ORG-RU, (текущая версия) :

Если в строке только число то при операциях с числом строка будет автоматически приведена к числу.

local struct = {}
struct['hello']="50";

print(struct.hello + 50)
print(struct.hello - 50)

print(50 + struct.hello)
print(50 - struct.hello)

if struct.hello == 50 then
  print('yes is 50')
end

if struct.hello == "50" then
  print('yes is 50')
end

if struct.hello+50 == "100" then
  print('yes is 100')
end

if 50+struct.hello == 100 then
  print('yes is 100')
end

if type(struct.hello) == 'number' then -- не исполнится
  print('no, it is not number')
end

if type(struct.hello) == 'string' then
  print('yess, struct.hello is string')
end

if type(struct.hello) ~= type(50) then
  print('yes it is different types')
end

print(type(struct.hello))
print(type(50))
dron@gnu:~$ lua test.lua
100
0
100
0
yes is 50
yes is 100
yess, struct.hello is string
yes is different types
string
number
dron@gnu:~$ 

Если ты конкатенируешь число со строкой то число будет приведено к строке.

print("50"+50)
print("50"..50)
dron@gnu:~$ lua test.lua
100
5050

Суть проста и гениальна. И то и то содержат одинаковый тип значения просто в разном представлении типов.

Конечно это не будет работать с видом "гы50"+50

Исправление LINUX-ORG-RU, :

Если в строке только число то при операциях с числом строка будет автоматически приведена к числу.

local struct = {}
struct['hello']="50";

print(struct.hello + 50)
print(struct.hello - 50)

print(50 + struct.hello)
print(50 - struct.hello)

if struct.hello == 50 then
  print('yes is 50')
end

if struct.hello == "50" then
  print('yes is 50')
end

if struct.hello+50 == "100" then
  print('yes is 100')
end

if 50+struct.hello == 100 then
  print('yes is 100')
end

if type(struct.hello) == 'number' then -- не исполнится
  print('no, it is not number')
end

if type(struct.hello) == 'string' then
  print('yess, struct.hello is string')
end

if type(struct.hello) ~= type(50) then
  print('yes it is different types')
end

print(type(struct.hello))
print(type(50))
dron@gnu:~$ lua test.lua
100
0
100
0
yes is 50
yes is 100
yess, struct.hello is string
yes is different types
string
number
dron@gnu:~$ 

Если ты конкатенируешь число со строкой то число будет приведено к строке.

print("50"+50)
print("50"..50)
dron@gnu:~$ lua test.lua
100
5050

Суть проста и гениальна. И то и то содержат одинаковый тип значения просто в разном представлении типов.

Исправление LINUX-ORG-RU, :

Если в строке только число то при операциях с числом строка будет автоматически приведена к числу.

local struct = {}
struct['hello']="50";

print(struct.hello + 50)
print(struct.hello - 50)

print(50 + struct.hello)
print(50 - struct.hello)

if struct.hello == 50 then
  print('yes is 50')
end

if struct.hello == "50" then
  print('yes is 50')
end

if struct.hello+50 == "100" then
  print('yes is 100')
end

if 50+struct.hello == 100 then
  print('yes is 100')
end

if type(struct.hello) == 'number' then -- не исполнится
  print('no, it is not number')
end

if type(struct.hello) == 'string' then
  print('yess, struct.hello is string')
end

if type(struct.hello) ~= type(50) then
  print('yes it is different types')
end

print(type(struct.hello))
print(type(50))
dron@gnu:~$ lua test.lua
100
0
100
0
yes is 50
yes is 100
yess, struct.hello is string
yes is different types
string
number
dron@gnu:~$ 

Если ты конкатенируешь число со строкой то число будет приведено к строке.

print("50"+50)
print("50"..50)
dron@gnu:~$ lua test.lua
100
5050

Суть проста и гениальна. И то и то содержат одинаковый тип значения просто в разном представлении.

Исправление LINUX-ORG-RU, :

Если в строке только число то при операциях с числом строка будет автоматически приведена к числу.

local struct = {}
struct['hello']="50";

print(struct.hello + 50)
print(struct.hello - 50)

print(50 + struct.hello)
print(50 - struct.hello)

if struct.hello == 50 then
  print('yes is 50')
end

if struct.hello == "50" then
  print('yes is 50')
end

if struct.hello+50 == "100" then
  print('yes is 100')
end

if 50+struct.hello == 100 then
  print('yes is 100')
end

if type(struct.hello) == 'number' then -- не исполнится
  print('no, it is not number')
end

if type(struct.hello) == 'string' then
  print('yess, struct.hello is string')
end

if type(struct.hello) ~= type(50) then
  print('yes it is different types')
end

print(type(struct.hello))
print(type(50))
dron@gnu:~$ lua test.lua
100
0
100
0
yes is 50
yes is 100
yess, struct.hello is string
yes is different types
string
number
dron@gnu:~$ 

Если ты конкатенируешь число со строкой то число будет приведено к строке.

print("50"+50)
print("50"..50)
dron@gnu:~$ lua test.lua
100
5050

Суть проста. И то и то содержат одинаковый тип значения просто в разном представлении.

Исправление LINUX-ORG-RU, :

Если в строке только число то при операциях с числом строка будет автоматически приведена к числу.

local struct = {}
struct['hello']="50";

print(struct.hello + 50)
print(struct.hello - 50)

print(50 + struct.hello)
print(50 - struct.hello)

if struct.hello == 50 then
  print('yes is 50')
end

if struct.hello == "50" then
  print('yes is 50')
end

if struct.hello+50 == "100" then
  print('yes is 100')
end

if 50+struct.hello == 100 then
  print('yes is 100')
end

if type(struct.hello) == 'number' then -- не исполнится
  print('no, it is not number')
end

if type(struct.hello) == 'string' then
  print('yess, struct.hello is string')
end

if type(struct.hello) ~= type(50) then
  print('yes it is different types')
end

print(type(struct.hello))
print(type(50))
dron@gnu:~$ lua test.lua
100
0
100
0
yes is 50
yes is 100
yess, struct.hello is string
yes is different types
string
number
dron@gnu:~$ 

Если ты конкатенируешь число со строкой то число будет приведено к строке.

print("50"+50)
print("50"..50)
dron@gnu:~$ lua test.lua
100
5050

Исправление LINUX-ORG-RU, :

Если в строке только число то при операциях с числом строка будет автоматически приведена к числу.

local struct = {}
struct['hello']="50";

print(struct.hello + 50)
print(struct.hello - 50)

print(50 + struct.hello)
print(50 - struct.hello)

if struct.hello == 50 then
  print('yes is 50')
end

if struct.hello == "50" then
  print('yes is 50')
end

if struct.hello+50 == "100" then
  print('yes is 100')
end

if 50+struct.hello == 100 then
  print('yes is 100')
end

if type(struct.hello) == 'number' then
  print('no, it is not number')
end

if type(struct.hello) == 'string' then
  print('yess, struct.hello is string')
end

if type(struct.hello) ~= type(50) then
  print('yes it is different types')
end

print(type(struct.hello))
print(type(50))
dron@gnu:~$ lua test.lua
100
0
100
0
yes is 50
yes is 100
yess, struct.hello is string
yes is different types
string
number
dron@gnu:~$ 

Если ты конкатенируешь число со строкой то число будет приведено к строке.

print("50"+50)
print("50"..50)
dron@gnu:~$ lua test.lua
100
5050

Исходная версия LINUX-ORG-RU, :

Если в строке только число то при операциях с числом строка будет автоматически приведена к числу.

local struct = {}
struct['hello']="50";

print(struct.hello + 50)
print(struct.hello - 50)

print(50 + struct.hello)
print(50 - struct.hello)

if struct.hello == 50 then
  print('yes is 50')
end

if struct.hello == "50" then
  print('yes is 50')
end

if struct.hello+50 == "100" then
  print('yes is 100')
end

if 50+struct.hello == 100 then
  print('yes is 100')
end

if type(struct.hello) == 'number' then
  print('no, it is not number')
end

if type(struct.hello) == 'string' then
  print('yess, struct.hello is string')
end

if type(struct.hello) ~= type(50) then
  print('yes it is different types')
end

print(type(struct.hello))
print(type(50))
dron@gnu:~$ lua test.lua
100
0
100
0
yes is 50
yes is 100
yess, struct.hello is string
yes is different types
string
number
dron@gnu:~$