summaryrefslogtreecommitdiff
path: root/src/04-thread/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/04-thread/main.cpp')
-rw-r--r--src/04-thread/main.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/04-thread/main.cpp b/src/04-thread/main.cpp
index e69de29..56b5066 100644
--- a/src/04-thread/main.cpp
+++ b/src/04-thread/main.cpp
@@ -0,0 +1,78 @@
+#include "../configure.h"
+#if BUILD_TEST == TEST_4
+
+#include <windows.h>
+#include <time.h>
+#include <conio.h>
+
+static int l_GetTime(lua_State* L)
+{
+ float second = (double)clock() / CLOCKS_PER_SEC;
+ lua_pushnumber(L, second);
+ return 1;
+}
+
+static int l_Sleep(lua_State* L)
+{
+ float t = lua_tonumber(L, 1);
+ Sleep(t * 1000);
+ return 0;
+}
+
+static int l_Kbhit(lua_State* L)
+{
+ int c = _kbhit();
+ lua_pushboolean(L, c);
+ return 1;
+}
+
+static int l_GetChar(lua_State* L)
+{
+ char str[2] = { 0,0 };
+ str[0] = _getch();
+ lua_pushstring(L, str);
+ return 1;
+}
+
+luaL_reg fns[] = {
+ {"GetTime", l_GetTime } ,
+ {"Sleep", l_Sleep } ,
+ {"Kbhit", l_Kbhit },
+ {"GetChar", l_GetChar },
+ {0, 0}
+};
+
+void openlibs(lua_State* L)
+{
+ luaL_openlibs(L);
+ ///luaL_register(L, NULL, fns);
+ luax_registerglobal(L, fns);
+}
+
+int f(int& a)
+{
+ a = 20;
+ return a;
+}
+
+int foo(int a, int b)
+{
+ return a + b;
+}
+
+int main(int args, char* argv[])
+{
+ int a = 10;
+ int r = foo(a, f(a));
+ printf("%d\n", r);
+
+ lua_State* L = luaL_newstate();
+ openlibs(L);
+
+ luaL_dofile(L, "04-thread/test.lua");
+
+ lua_close(L);
+ return 0;
+}
+
+#endif \ No newline at end of file