Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Type TLuaThread
- Field ParentState:Byte Ptr
- Field State:Byte Ptr
- Field Code:String
- Field Thread:TThread
- Function RunThread:Object(LT:Object)
- Local LuaObject:TLuaThread = TLuaThread(LT)
- If LuaObject Then
- LuaObject.State = lua_newthread(LuaObject.ParentState)
- luaL_dostring LuaObject.State, LuaObject.Code
- Local Error:String = lua_tostring(LuaObject.State, -1)
- If Len(Error) > 0 Then Print "Error: "+Error
- EndIf
- EndFunction
- Method Run:TThread()
- Self.Thread = CreateThread(TLuaThread.RunThread, Self)
- EndMethod
- Method Create:TLuaThread(ParentState:Byte Ptr,Code:String)
- Self.ParentState = ParentState
- Self.Code = Code
- Self.Run()
- If Self.Thread Then Return Self
- EndMethod
- EndType
- Function lua_CreateThread(L:Byte Ptr)
- Local Code:String = luaL_checkstring(L, 1)
- If Len(Code) > 0 Then
- Local LuaThread:TLuaThread = New TLuaThread.Create(L, Code)
- If LuaThread Then
- Local Thread:TThread = LuaThread.Thread
- If Thread Then
- lua_pushinteger L, HandleFromObject(Thread)
- Return 1
- EndIf
- EndIf
- EndIf
- EndFunction
- Function lua_DetachThread(L:Byte Ptr)
- Local ThreadID = lua_tointeger(L, 1)
- If ThreadID Then
- Local ThreadObject:Object = HandleToObject(ThreadID)
- If ThreadObject Then
- Local Thread:TThread = TThread(ThreadObject)
- If Thread Then
- DetachThread Thread
- EndIf
- EndIf
- EndIf
- EndFunction
- Function lua_ThreadRunning(L:Byte Ptr)
- Local ThreadID = lua_tointeger(L, 1)
- If ThreadID Then
- Local ThreadObject:Object = HandleToObject(ThreadID)
- If ThreadObject Then
- Local Thread:TThread = TThread(ThreadObject)
- If Thread Then
- lua_pushboolean L, ThreadRunning(Thread)
- Return 1
- EndIf
- EndIf
- EndIf
- EndFunction
- Function lua_WaitThread(L:Byte Ptr)
- Local ThreadID = lua_tointeger(L, 1)
- If ThreadID Then
- Local ThreadObject:Object = HandleToObject(ThreadID)
- If ThreadObject Then
- Local Thread:TThread = TThread(ThreadObject)
- If Thread Then
- WaitThread Thread
- EndIf
- EndIf
- EndIf
- EndFunction
- Function luaopen_luamt(L:Byte Ptr)
- lua_register(L, "CreateThread", lua_CreateThread)
- lua_register(L, "DetachThread", lua_DetachThread)
- lua_register(L, "ThreadRunning", lua_ThreadRunning)
- lua_register(L, "WaitThread", lua_WaitThread)
- EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement