Skip to content

Add support for coroutines#955

Merged
vadi2 merged 7 commits intoMudlet:developmentfrom
ahmedcharles:luastate
May 28, 2017
Merged

Add support for coroutines#955
vadi2 merged 7 commits intoMudlet:developmentfrom
ahmedcharles:luastate

Conversation

@ahmedcharles
Copy link
Copy Markdown
Contributor

@ahmedcharles ahmedcharles commented Apr 25, 2017

This makes it easier to write functions which can be independent of
TLuaInterpreter.

Get Mudlet from this branch, test each function in a normal and a coroutine call, and if everything works tick if off this list. Here's a template for calling from inside a coroutine:

function foo()
  addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)
  print("coroutine call worked")
  coroutine.yield()
end

local co = coroutine.create(foo)

coroutine.resume(co)
  • addAreaName
  • addCustomLine
  • addMapEvent
  • addMapMenu
  • addRoom
  • addSpecialExit
  • addSupportedTelnetOption
  • appendBuffer
  • appendCmdLine
  • calcFontSize
  • centerview
  • clearAreaUserData
  • clearAreaUserDataItem
  • clearCmdLine
  • clearMapUserData
  • clearMapUserDataItem
  • clearRoomUserData
  • clearRoomUserDataItem
  • clearSpecialExits
  • clearUserWindow
  • clearWindow
  • closeMudlet
  • closeUserWindow
  • connectExitStub
  • connectToServer
  • copy
  • createBuffer
  • createButton
  • createLabel
  • createMapImageLabel
  • createMapLabel
  • createMapper
  • createMiniConsole
  • createRoomID
  • createStopWatch
  • deleteArea
  • deleteLine
  • deleteMapLabel
  • deleteRoom
  • denyCurrentSend
  • deselect
  • disableAlias
  • disableKey
  • disableTimer
  • disableTrigger
  • disconnect
  • downloadFile
  • echo
  • echoLink
  • echoPopup
  • echoUserWindow
  • enableAlias
  • enableKey
  • enableTimer
  • enableTrigger
  • exists
  • expandAlias
  • exportAreaImage
  • feedTriggers
  • getAllAreaUserData
  • getAllMapUserData
  • getAllRoomEntrances
  • getAllRoomUserData
  • getAreaExits
  • getAreaRooms
  • getAreaTable
  • getAreaTableSwap
  • getAreaUserData
  • getBgColor
  • getButtonState
  • getCmdLine
  • getColumnNumber
  • getCurrentLine
  • getCustomEnvColorTable
  • getCustomLines
  • getDoors
  • getExitStubs
  • getExitStubs1
  • getExitWeights
  • getFgColor
  • getLastLineNumber
  • getLineCount
  • getLineNumber
  • getLines
  • getMainConsoleWidth
  • getMainWindowSize
  • getMapEvents
  • getMapLabel
  • getMapLabels
  • getMapMenus
  • getMapUserData
  • getModulePath
  • getModulePriority
  • getMousePosition
  • getMudletHomeDir
  • getMudletLuaDefaultPaths
  • getMudletVersion
  • getNetworkLatency
  • getPath
  • getProfileName
  • getRoomArea
  • getRoomAreaName
  • getRoomChar
  • getRoomCoordinates
  • getRoomEnv
  • getRoomExits
  • getRoomIDbyHash
  • getRoomName
  • getRooms
  • getRoomsByPosition
  • getRoomUserData
  • getRoomUserDataKeys
  • getRoomWeight
  • getSpecialExits
  • getSpecialExitsSwap
  • getStopWatchTime
  • getTime
  • getTimestamp
  • gotoRoom
  • handleWindowResizeEvent
  • hasExitLock
  • hasFocus
  • hasSpecialExitLock
  • hideToolBar
  • hideWindow
  • highlightRoom
  • insertHTML
  • insertLink
  • insertPopup
  • insertText
  • installModule
  • installPackage
  • invokeFileDialog
  • isActive
  • isAnsiBgColor
  • isAnsiFgColor
  • isPrompt
  • killAlias
  • killTimer
  • killTrigger
  • loadMap
  • loadRawFile
  • lockExit
  • lockRoom
  • lockSpecialExit
  • lowerWindow
  • moveCursor
  • moveCursorEnd
  • moveWindow
  • openUrl
  • openUserWindow
  • openWebPage
  • paste
  • pasteWindow
  • permAlias
  • permBeginOfLineStringTrigger
  • permRegexTrigger
  • permSubstringTrigger
  • permTimer
  • playSoundFile
  • printCmdLine
  • raiseEvent
  • raiseGlobalEvent
  • raiseWindow
  • reconnect
  • registerAnonymousEventHandler
  • reloadModule
  • removeMapEvent
  • removeMapMenu
  • removeSpecialExit
  • replace
  • resetFormat
  • resetProfile
  • resetRoomArea
  • resetStopWatch
  • resizeWindow
  • roomExists
  • roomLocked
  • saveMap
  • saveProfile
  • searchAreaUserData
  • searchRoom
  • searchRoomUserData
  • selectCaptureGroup
  • selectCurrentLine
  • selectSection
  • selectString
  • send
  • sendATCP
  • sendGMCP
  • sendIrc
  • sendMSDP
  • sendSocket
  • sendTelnetChannel102
  • setAppStyleSheet
  • setAreaName
  • setAreaUserData
  • setBackgroundColor
  • setBackgroundImage
  • setBgColor
  • setBold
  • setBorderBottom
  • setBorderColor
  • setBorderLeft
  • setBorderRight
  • setBorderTop
  • setConsoleBufferSize
  • setCustomEnvColor
  • setDefaultAreaVisible
  • setDoor
  • setExit
  • setExitStub
  • setExitWeight
  • setFgColor
  • setGridMode
  • setItalics
  • setLabelClickCallback
  • setLabelOnEnter
  • setLabelOnLeave
  • setLabelReleaseCallback
  • setLabelStyleSheet
  • setLink
  • setMainWindowSize
  • setMapperView
  • setMapUserData
  • setMapZoom
  • setMergeTables
  • setMiniConsoleFontSize
  • setModulePriority
  • setPopup
  • setRoomArea
  • setRoomChar
  • setRoomCoordinates
  • setRoomEnv
  • setRoomIDbyHash
  • setRoomName
  • setRoomUserData
  • setRoomWeight
  • setStrikeOut
  • setTextFormat
  • setTriggerStayOpen
  • setUnderline
  • setWindowWrap
  • setWindowWrapIndent
  • showToolBar
  • showWindow
  • spawn
  • startLogging
  • startStopWatch
  • stopSounds
  • stopStopWatch
  • tempAlias
  • tempBeginOfLineTrigger
  • tempButton
  • tempButtonToolbar
  • tempColorTrigger
  • tempComplexRegexTrigger
  • tempExactMatchTrigger
  • tempLineTrigger
  • tempRegexTrigger
  • tempTimer
  • tempTrigger
  • unHighlightRoom
  • uninstallModule
  • uninstallPackage
  • updateMap
  • wrapLine

This makes it easier to write functions which can be independent of
TLuaInterpreter.

Fixes #947, #948.
@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Apr 25, 2017

Hey you might be implementing https://blueprints.launchpad.net/mudlet/+spec/coroutines-for-c-api with this. Gonna test.

@ahmedcharles
Copy link
Copy Markdown
Contributor Author

Yeah, unintentionally. My main reason for doing it is that I really want to split up the lua api functions into multiple files and doing that currently would be a huge pain.

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Apr 25, 2017

You did. The following test works:

selection_047

On a Mudlet that doesn't have this improvement, it just locks up.

Well this'll be super-awesome news to a super-small subset of people! I'm included so I'll be happy.

@ahmedcharles
Copy link
Copy Markdown
Contributor Author

Does 5.1's library functions support coroutines? Like, yielding in the comparator of a sort?

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Apr 25, 2017

We'll need to test this with all of Mudlets functions so expect the approval to take a bit - but it'll be my priority to do so, as this is a pretty great change. a) gets rid of the boilerplate and b) allows calling Mudlet API from coroutines.

@vadi2 vadi2 changed the title Store the host pointer in the lua registry. Add support for coroutines Apr 25, 2017
@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Apr 25, 2017

I've updated the title of the PR to better reflect the really awesome feature that's happening here.

@vadi2 vadi2 mentioned this pull request Apr 25, 2017
@@ -13723,3 +13439,19 @@ int TLuaInterpreter::startPermSubstringTrigger(const QString & name, const QStri

}

static int host_key = 0;

static void store_host_in_lua_state(lua_State* L, Host* h) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Would it be applicable to store/access any other data like this? What are the pros and cons of this technique?

If it works (and you must think it does) then 👍, it is just that the Lua-fu is not string in me so I cannot really judge... 😉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only do I think it works, I know it works.

The registry is explained: https://www.lua.org/manual/5.1/manual.html#3.5

Just run:

for k, v in pairs(debug.getregistry()) do print(k, v) end

Both before and after this change.

Copy link
Copy Markdown
Member

@SlySven SlySven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, I do not really understand it but I like it (which is why I cannot say yah or nay and have to leave it to others).

@ahmedcharles
Copy link
Copy Markdown
Contributor Author

Needed to resolve some merge conflicts.

@ahmedcharles ahmedcharles modified the milestone: 3.2 May 4, 2017
@vadi2
Copy link
Copy Markdown
Member

vadi2 commented May 8, 2017

The PR is ready but without any testing progress for two weeks which is unacceptable so I'll drop the idea of adding all tests to Squish as I go and just test functions on the fly.

I've updated the first comment to keep track of which functions have been tested. Help would be appreciated!

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented May 11, 2017

I've got #1006 while testing, but I can't reproduce it anymore, so just something to watch out for.

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented May 12, 2017

@SlySven while I am working through testing this, are you able to review it as well and give your tick?

@SlySven
Copy link
Copy Markdown
Member

SlySven commented May 15, 2017

Vadi2 wrote:

@ SlySven while I am working through testing this, are you able to review it as well and give your tick?

Um, see above, where I put:

I like this, I do not really understand it but I like it (which is why I cannot say yah or nay and have to leave it to others).

I really do not feel confident that I understand what is happening here - so I do not think I can offer any input - sorry... 😐

@vadi2 vadi2 self-assigned this May 25, 2017
@vadi2
Copy link
Copy Markdown
Member

vadi2 commented May 28, 2017

Merging in for the time being since all of the functionalty is fine and most of the time is spent improving our documentation instead I went through every function.

I'm not a fan of camelcasing too much but it is the C++ style and consistency is important!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants