TestInt64.cs

  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using LuaInterface;
  5. using System.Collections.Generic;
  6. public class TestInt64 : MonoBehaviour
  7. {
  8. private string tips = "";
  9. string script =
  10. @"
  11. function TestInt64(x)
  12. x = x + 789
  13. assert(tostring(x) == '9223372036854775807')
  14. local low, high = int64.tonum2(x)
  15. print('x value is: '..tostring(x)..' low is: '.. low .. ' high is: '..high.. ' type is: '.. tolua.typename(x))
  16. local y = int64.new(1,2)
  17. local z = int64.new(1,2)
  18. if y == z then
  19. print('int64 equals is ok, value: '..int64.tostring(y))
  20. end
  21. x = int64.new(123)
  22. if int64.equals(x, 123) then
  23. print('int64 equals to number ok')
  24. else
  25. print('int64 equals to number failed')
  26. end
  27. x = int64.new('78962871035984074')
  28. print('int64 is: '..tostring(x))
  29. local str = tostring(int64.new(3605690779, 30459971))
  30. local n2 = int64.new(str)
  31. local l, h = int64.tonum2(n2)
  32. print(str..':'..tostring(n2)..' low:'..l..' high:'..h)
  33. print('----------------------------uint64-----------------------------')
  34. x = uint64.new('18446744073709551615')
  35. print('uint64 max is: '..tostring(x))
  36. l, h = uint64.tonum2(x)
  37. str = tostring(uint64.new(l, h))
  38. print(str..':'..tostring(x)..' low:'..l..' high:'..h)
  39. return y
  40. end
  41. ";
  42. void Start()
  43. {
  44. #if UNITY_5
  45. Application.logMessageReceived += ShowTips;
  46. #else
  47. Application.RegisterLogCallback(ShowTips);
  48. #endif
  49. new LuaResLoader();
  50. LuaState lua = new LuaState();
  51. lua.Start();
  52. lua.DoString(script, "TestInt64.cs");
  53. LuaFunction func = lua.GetFunction("TestInt64");
  54. func.BeginPCall();
  55. func.Push(9223372036854775807 - 789);
  56. func.PCall();
  57. long n64 = func.CheckLong();
  58. Debugger.Log("int64 return from lua is: {0}", n64);
  59. func.EndPCall();
  60. func.Dispose();
  61. func = null;
  62. lua.CheckTop();
  63. lua.Dispose();
  64. lua = null;
  65. }
  66. void ShowTips(string msg, string stackTrace, LogType type)
  67. {
  68. tips += msg;
  69. tips += "\r\n";
  70. }
  71. void OnDestroy()
  72. {
  73. #if UNITY_5
  74. Application.logMessageReceived -= ShowTips;
  75. #else
  76. Application.RegisterLogCallback(null);
  77. #endif
  78. }
  79. void OnGUI()
  80. {
  81. GUI.Label(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 150, 400, 300), tips);
  82. }
  83. }

?