Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.98 KB | None | 0 0
  1. 'function i register
  2. Public Function Print(ByVal lua_state As IntPtr) As Integer
  3.     Console.WriteLine(clua.GetString(-1))
  4. End Function
  5.  
  6. 'how i register a function
  7. clua.RegisterCfunction("print", AddressOf Print)
  8.  
  9. Public Sub RegisterCfunction(ByVal refname As String, ByVal func As LuaCFunction)
  10.     register(cLuaState, refname, func)
  11. End Sub
  12.  
  13. Friend Sub register(ByVal lua_state As IntPtr, ByVal name As String, ByVal func As LuaCFunction)
  14.     Dim top As Integer = lua_gettop(lua_state) 'upvalues
  15.     lua_pushcclosure(lua_state, func, top)
  16.     lua_setfield(lua_state, LUA_GLOBALSINDEX, name)
  17. End Sub
  18.  
  19. 'lua code
  20. function test(duration)
  21.     print('timer started: '..duration..' seconds')
  22.     local inittime = os.time()
  23.     local curtime = os.time()
  24.     while curtime - inittime < duration do
  25.         curtime = os.time()
  26.         coroutine.yield()
  27.     end
  28.     print('timer exited')
  29. end
  30.  
  31. co = coroutine.create(test)
  32. coroutine.resume(co,5)
  33. while coroutine.status(co) == 'suspended' do
  34. coroutine.resume(co)
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement