Browse Source

Initial release on http://luaforge.net

Jean-Francois Goulet 20 years ago
parent
commit
d477339eca
59 changed files with 7592 additions and 0 deletions
  1. 78 0
      LuaEdit/Tutorials/BindDllToLuaEdit/English/Intro_En.html
  2. 104 0
      LuaEdit/Tutorials/BindDllToLuaEdit/English/Page1_En.html
  3. 220 0
      LuaEdit/Tutorials/BindDllToLuaEdit/English/Page2_En.html
  4. 260 0
      LuaEdit/Tutorials/BindDllToLuaEdit/English/Page3_En.html
  5. 305 0
      LuaEdit/Tutorials/BindDllToLuaEdit/English/Page4_En.html
  6. 78 0
      LuaEdit/Tutorials/BindDllToLuaEdit/Francais/Intro_Fr.html
  7. 104 0
      LuaEdit/Tutorials/BindDllToLuaEdit/Francais/Page1_Fr.html
  8. 217 0
      LuaEdit/Tutorials/BindDllToLuaEdit/Francais/Page2_Fr.html
  9. 258 0
      LuaEdit/Tutorials/BindDllToLuaEdit/Francais/Page3_Fr.html
  10. 304 0
      LuaEdit/Tutorials/BindDllToLuaEdit/Francais/Page4_Fr.html
  11. 5 0
      LuaEdit/Tutorials/BindDllToLuaEdit/Tutorial.css
  12. 73 0
      LuaEdit/Tutorials/BindDllToLuaEdit/Welcome.html
  13. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/bin/Medias/01.wav
  14. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/bin/Medias/02.wav
  15. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/bin/Medias/03.wav
  16. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/bin/Medias/04.wav
  17. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/bin/Medias/SIMON.ICO
  18. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/bin/Simon.dll
  19. 14 0
      LuaEdit/Tutorials/BindDllToLuaEdit/bin/Simon.lpr
  20. 111 0
      LuaEdit/Tutorials/BindDllToLuaEdit/bin/Simon.lua
  21. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/bin/SimonExec.exe
  22. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/bin/lua.dll
  23. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/LuaDelphi007.lzh
  24. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/LuaUtils.dcu
  25. 1444 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/LuaUtils.pas
  26. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lauxlib.dcu
  27. 284 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lauxlib.pas
  28. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lua.dcu
  29. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lua.dll
  30. 571 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lua.pas
  31. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lualib.dcu
  32. 95 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lualib.pas
  33. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.dcu
  34. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.ddp
  35. 232 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.dfm
  36. 691 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.pas
  37. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.~ddp
  38. 231 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.~dfm
  39. 658 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.~pas
  40. 44 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.cfg
  41. 152 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.dof
  42. 26 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.dpr
  43. 528 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.drc
  44. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.res
  45. 26 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.~dpr
  46. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.dcu
  47. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.ddp
  48. 17 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.dfm
  49. 91 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.pas
  50. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.~ddp
  51. 17 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.~dfm
  52. 91 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.~pas
  53. 43 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.cfg
  54. 16 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.dfm
  55. 152 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.dof
  56. 14 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.dpr
  57. 24 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.pas
  58. BIN
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.res
  59. 14 0
      LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.~dpr

+ 78 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/English/Intro_En.html

@@ -0,0 +1,78 @@
+<html>	
+	<head>
+		  <title>
+		  		 Bind a Dll to LuaEdit (Tutorial) - Introduction
+		  </title>
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Introduction</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Lua homepage</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2">
+						  <hr size="1" color="#000000">
+						  <br>
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <p style="text-align:justify">
+						    Welcome in the "Bind a Dll to LuaEdit" tutorial. This tutorial will show you how to
+							bind LuaEdit to a dll file that export the LuaEdit's "Initializer" function (we will see
+							this in detail later) to allow runtime script debugging. This tutorial should take 1
+							to 2 hours for a beginner or a few minutes for an expert. No material is required
+							for this tutorial besides a computer (I guess this won't be such a problem!), the distributed
+							files with this tutorial and the 2.5 (or better) version of LuaEdit. (A free copy of LuaEdit is available <a href="http://luaforge.net/frs/?group_id=84">
+							here</a>) All the way through this tutorial you should always be able to locate "&lt;&lt; 
+							Previous" and "Next &gt;&gt;" links on the bottom of each page.	Also, look for any
+							<b>Hints</b> sections. They may be useful to you if you're not used to LuaEdit's
+							interface or if you wish to enlarge your knowledges. Good luck!
+						  </p>
+						  <br> 
+						  </font>
+					</td>
+				</tr> 
+				<tr> 
+					<td valign="bottom">													  
+						<font face="Tahoma" size="2">
+						<div align="left" valign="bottom">
+							<a href="..\Welcome.html">&lt;&lt; Previous</a>
+						</div>	
+					</td> 
+					<td>   
+						<font face="Tahoma" size="2">
+						<div align="right" valign="bottom">
+                             <a href=".\Page1_En.html">Next &gt;&gt;</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Bind a Dll to LuaEdit (Tutorial)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>
+

+ 104 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/English/Page1_En.html

@@ -0,0 +1,104 @@
+<html>	
+	<head>
+		  <title>
+		  		 Bind a Dll to LuaEdit (Tutorial) - Getting Started
+		  </title>
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Getting Started</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Lua homepage</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2">
+						  <hr size="1" color="#000000">
+						  <br>
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <p style="text-align:justify">
+						  	First of all, download LuaEdit <a href="http://luaforge.net/frs/?group_id=84&release_id=318">here</a>,
+							install it and start it. (If LuaEdit is already installed, simply start it)
+							Then, we need to create a new project which will contain a lua script file in it.
+							Once the new project is created, save it under [Tutorial]\Bin\Simon.lpr and save its lua script file
+							under [Tutorial]\Bin\Simon.lua where [Tutorial] represents the path where you unzipped this
+							tutorial. We need to do so to be able to set the "Initializer" property. This "Initializer"
+							property is in fact the path of a dll file wich MUST export the following function:
+							
+							<ul type="square"> 
+							  <li>Delphi: <b style="color: navy">&nbsp;LuaDebug_Initializer(L: PLua_State): Integer; cdecl;&nbsp;</b></li>
+							  <li>C/C++: <b style="color: navy">&nbsp;int LuaDebug_Initializer(lua_State *L);&nbsp;</b></li>
+							</ul>
+										   
+							This function will be called right before the execution of the script and its use may
+							vary from a project to another. In other words, this is a call back function in which you
+							may do anything useful with/without the Lua state before any scripts has been executed yet.
+							Only lua script files contained in a project can benefit of the "Initializer" property
+							since this property	is set in the project settings.	In our example in this tutorial, we will
+							assign the full path of [Tutorial]\Bin\simon.dll file. This file exports the function discuss
+							above to register functions to the Lua environement. Once this property set, save the project
+							again and let's get ready to talk about code.
+							<br>
+							<br>
+							<br>
+							<b>Hints:</b>
+							<ul type="square">						 
+								<li>To create a new project, click on the menu Files/New/Project</li>
+								<li>If you can't find the Project Tree window, this may be because it's hidden.
+									To show it, click on the View/Project Tree menu.</li>
+								<li>To set the initializer property of a project, right click on the project
+									file in the project tree, and click on the Project Settings menu. In the
+									Project Settings dialog, select Debug tab. Specify the path of a valid dll
+									file and press Ok when done.</li>
+								<li>You may want to change the project name to Simon in the project settings.
+									Changing this property has no effects but may help you when working with
+									LuaEdit.</li>
+							</ul>
+						  </p>
+						  <br> 
+						  </font>
+					</td>
+				</tr> 
+				<tr> 
+					<td valign="bottom">													  
+						<font face="Tahoma" size="2">
+						<div align="left" valign="bottom">
+							<a href=".\Intro_En.html">&lt;&lt; Previous</a>
+						</div>	
+					</td> 
+					<td>   
+						<font face="Tahoma" size="2">
+						<div align="right" valign="bottom">
+                             <a href=".\Page2_En.html">Next &gt;&gt;</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Bind a Dll to LuaEdit (Tutorial)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>

+ 220 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/English/Page2_En.html

@@ -0,0 +1,220 @@
+<html>	
+	<head>
+		  <title>
+		  		 Bind a Dll to LuaEdit (Tutorial) - Setup Code Bases
+		  </title>	 
+		  <link rel="stylesheet" href="..\Tutorial.css" type="text/css">
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Setup Code Bases</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Lua homepage</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2">
+						  <hr size="1" color="#000000">
+						  <br>
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <p style="text-align:justify">
+							Before starting programming logics of the Simon<sup>®</sup> game, there is actually some basics
+							code setups to do just like in any other script. Let's start by adding the following
+							variables at the begenning of script:
+						  </p>
+						  <br> 
+						  </font>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>	  
+							-- Set "constants" for Simon game<br>
+							local SIMON_NONE		= 0<br>
+							local SIMON_RED			= 1<br>
+							local SIMON_BLUE		= 2<br>
+							local SIMON_YELLOW		= 3<br>
+							local SIMON_GREEN		= 4
+						</blockquote>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>
+						  <p style="text-align:justify"> 
+						  	Those variables will actually be use "as if" they were constants since the concept
+							of constants does not really exists in Lua. This means that our code should never
+							modify their content. Next, we will add four "actual" variables (their content will
+							probably change during the execution of the script) to control the game's environment:
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>	  
+							-- Game handling variables<br>
+							local GameState = true<br>
+							local MainSequence = {}<br>
+							local SequenceCount = 0<br>
+							local UserSequenceCount = 0
+						</blockquote>
+					</td>						  
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>
+						  <p style="text-align:justify"> 
+						  	The GameState variable is a boolean wich contains false if the game is over or true if not. MainSequence is
+							a table wich contains the whole sequence since the begenning of the new game. The variable SequenceCount is
+							an integer containing the actual total sequence's length. Finally, UserSequenceCount is an integer
+							containing the user's sequence length so far. Next, we will need to add four functions in wich we will add
+							some code later. Those functions will be nested into the the table simon wich will be created by the game
+							engine (simon.dll) when the script will initialize through the Initializer function:
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							function simon:OnButtonClick(ButtonIndex)<br>
+							end<br><br>
+							
+							function simon:AddSequence(Sequence)<br>
+							end<br><br>
+							
+							function simon:PlaySequence(Sequence)<br>
+							end<br><br>
+							
+							function simon:Initialize()<br>
+							end<br>
+						</blockquote>
+					</td>						  
+				</tr>
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>
+						  <p style="text-align:justify"> 
+						  	The OnClick(ButtonIndex) function will be called every time the user
+							will click on a button. In this function we will validate the clicked
+							button in the current sequence.	The functions simon:AddSequence(Sequence), 
+							simon:PlaySequence(Sequence) and simon:Initialize() are functions that are going
+							to be called by our own script to handle different steps during the game.
+							One last thing remains before the end of this step: creating the game's
+							frame. To do so, a main loop at the end of the script will be required as
+							followed:
+						  </p> 
+						  <br>
+					</td>
+				</tr> 
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							simon.Create()<br><br>
+							
+							-- Main processing loop<br>
+							while simon.GetPowerStatus() == 1 do<br>
+							  &nbsp;&nbsp;&nbsp;&nbsp;-- Make sure the processor doesn't runs for no reason<br>
+							  &nbsp;&nbsp;&nbsp;&nbsp;Sleep(10)<br>
+							end<br><br>
+							
+							simon.Destroy()<br>
+						</blockquote>
+					</td>						  
+				</tr>
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>
+						  <p style="text-align:justify"> 
+						  	This loop will handle the game from the beginning up to the end. An iteration
+							in this loop will be executed many times per seconds when there is no need for
+							it. That's why the game engine (simon.dll) has exported a functions called Sleep()
+							wich tells to the processor to sleep for a certain amount of time in miliseconds.
+							In other words, by using this function we will ensure that the game isn't using 100% of the processor's resources
+							since we don't need it in this perticular case.	Also, as you probably noticed already, 
+							this code snipset include two function calls from the game engine: simon.Create() and
+							simon.Destroy(). The simon.Create() function create the Simon<sup>®</sup> game interface to interact
+							with the user when the simon.Destroy() function destroy this interface. In the next step, we
+							will add some code into the previously added functions.
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>	  
+					<td colspan="2">
+							<font face="Tahoma" size="2">
+							<b>Hints:</b>
+							<ul type="square">						 
+								<li>The reserved word "local" used in the variables declarations code above is not
+									necessary for the code to work since this script isn't supposed to be loaded
+									in any other scripts. In the other hand, since those variables are going to be
+									used ONLY in the script's global scope, it would be recommended, to avoid any
+									potential problems, to keep the "local" instruction even if not necessary. See
+									section 2.6 of Lua 5.0 documentation for more details. (Available in LuaEdit
+									Help menu)</li>
+								<li>The Create() function has an optional argument you can pass to. This argument
+									manage how the interface will be created. When this argument is worth 1, it creates
+									the interface in a sizeable regular window. When it's worth 2, it creates the
+									interface in a sizeable tool window. When the argument is worth anything else
+									than 1 or 2, it creates the interface without any borders. In our example, this
+									optional argument was worth nil since we didn't give any to this function call.</li>
+							</ul>
+						  </p> 
+					</td>
+				</tr>
+				<tr> 
+					<td valign="bottom">													  
+						<font face="Tahoma" size="2">
+						<div align="left" valign="bottom">
+							<a href=".\Page1_En.html">&lt;&lt; Previous</a>
+						</div>	
+					</td>
+					<td>   
+						<font face="Tahoma" size="2">
+						<div align="right" valign="bottom">
+                             <a href=".\Page3_En.html">Next &gt;&gt;</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Bind a Dll to LuaEdit (Tutorial)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>

+ 260 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/English/Page3_En.html

@@ -0,0 +1,260 @@
+<html>	
+	<head>
+		  <title>
+		  		 Bind a Dll to LuaEdit (Tutorial) - Managing the Game
+		  </title>	
+		  <link rel="stylesheet" href="..\Tutorial.css" type="text/css">
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Managing the Game</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Lua homepage</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2">
+						  <hr size="1" color="#000000">
+						  <br>
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <p style="text-align:justify">
+							Now, the script contains a solid basic frame/structure around which we will add
+							code to actually handle the game. This means sequence randomization algorythms,
+							key validations, point system logic, etc. Let's start by the game initialization
+							routine.
+						  </p>
+						  <br> 
+						  </font>
+					</td>
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <p style="text-align:justify"> 
+						  	The simon:Initialize() function previously added will be called right before a new game is
+							requested by the player. Our main goal in this function is to reset all of our game handling variables
+							previously created and intialize random logic. In the world of computers, generating
+							random is not an easy thing to achieve. Let's be realistic, it's impossible to recreate
+							exactly what random is by definition. On the other hand, we can generate something
+							so huge in terms of quantity of possibilities, that statistically and humanly speaking, we can
+							call this random. Lua's pseudo-random engine works the same way as in C++.
+							In fact, "behind the scene", Lua uses the C++ pseudo-random engine. This engine works
+							with seeds to generate "random" sequences of numbers. A seed is a number which will
+							be used to generate "random" numbers. In other words, two sequences using the same seed will
+							be identical. To avoid this problem, many scripts/programs use the system's current time
+							as the random seed, which pratically makes it impossible for the user to get or even remember
+							having the same sequence. Here is how the simon:Initialize() function should looks like:
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							-- Initialize the game<br>
+							function simon:Initialize()<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;-- Initalize variables<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;simon:SetScore(0)<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;GameState = true<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;UserSequenceCount = 0<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;SequenceCount = 0<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;MainSequence = {}<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;-- Initialize random engine<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;math.randomseed(os.time())<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;math.random()<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;math.random()<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;math.random()<br>
+							end<br>
+						</blockquote>
+					</td>						  
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	In this previous code example, math.random() function is called three times because under
+							some operating systems (at least in Windows 2k<sup>®</sup>) the first random number you get is not really
+							"randomized". (Source taken from the <a href="http://lua-users.org/wiki/MathLibraryTutorial">lua-users wiki</a> website)
+							 To get better pseudo-random numbers, we just pop some random numbers before using
+							them for real. The other lines of code in that previous example initialize the variables previously
+							declared in the <a href=".\Page2_En.html">step 2</a> of this tutorial. Next, let's add some code
+							in the simon:AddSequence(Sequence) function. The goal of this function is to append a new item to
+							the sequence that the player is going to have to reproduce later. To do so, we will increment by 1
+							the global variable SequenceCount and we will "randomize" a number from 1 to 4. That generated number
+							is going to represent the light to turn on in the sequence. Here is how the function should looks like:
+						  </p> 
+						  <br>
+					</td>
+				</tr>  
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							-- Add one more part to the game's sequence<br>
+							function simon:AddSequence()<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;SequenceCount = SequenceCount + 1<br>
+							    &nbsp;&nbsp;&nbsp;&nbsp;MainSequence[SequenceCount] = math.random(4)<br>
+							end<br>
+						</blockquote>
+					</td>						  
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	 Next, we will fill the simon:PlaySequence(Sequence) function. The main goal of
+							 this function is to play the sequence previously build via some calls to the
+							 Simon<sup>®</sup> game's engine exported functions. In this function, we should
+							 parse the sequence table item by item and turn on the light that this item is worth.
+							 Let's be more specific:
+						  </p> 
+						  <br>
+					</td>
+				</tr> 
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							-- Play the game's sequence<br>
+							function simon:PlaySequence(Sequence)<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;local v = nil<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;local i = nil<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;-- Lock controls from user to make sure no conflicts happened while palying sequence<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;simon.LockControls()<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;-- Play all sequence<br>
+							    &nbsp;&nbsp;&nbsp;&nbsp;repeat<br>
+							    	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon.SetLight(SIMON_NONE)<br>
+							    	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sleep(300)<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i, v = next(Sequence, i)<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon.SetLight(v)<br><br>
+							
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if i ~= nil then<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sleep(500)<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>
+							    &nbsp;&nbsp;&nbsp;&nbsp;until i == nil<br><br>
+							    
+							    &nbsp;&nbsp;&nbsp;&nbsp;simon.UnlockControls()<br>
+							    &nbsp;&nbsp;&nbsp;&nbsp;simon.SetLight(SIMON_NONE)<br>
+							end<br>
+						</blockquote>
+					</td>						  
+				</tr>  
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	 The two local variables v and i are going to be use to retrieve the result
+							 of our calls to the next() function. The next() function is use to retrieve the
+							 next element in a lua table by specifiying the actual table and the index of
+							 the current element as arguments. The simon.LockControls() and simon.UnlockControls() functions
+							 are exported from the game's engine and their main goal is to lock/unlock the
+							 controls from the player to avoid any conflict in the code. In the previous sample
+							 of code, those calls will be made before and after the loop that is actually
+							 displaying the sequence to the player. Also, in the code sample the repeat...until
+							 statement was used to allow the code to enter in the loop for the first iteration
+							 everytime it has to but any other loop syntax would have been a proper use as well.
+							 The first chunk in the loop is a call to the simon.SetLight() function using
+							 SIMON_NONE as first and only argument. This instruction will turn off all the lights
+							 in the game because we want to make sure that for each item no other light but the one
+							 of the current item will be on. Next, we have a Sleep() call of 300 miliseconds as
+							 the argument. This call, unlike the one in <a href=".\Page2_En.html">step 2</a> of
+							 this tutorial, has the same effect on the computer but is more used as a "pause"
+							 feature than a CPU "slower" kind of feature. With what has been clarify so far,
+							 you should be able to understand the remaining lines that I didn't detailed.
+						  </p> 
+						  <p style="text-align:justify"> 
+						  	 To finalize this step we will add some code to the simon:OnButtonClick(ButtonIndex)
+							 function. This function will be called the the Simon<sup>®</sup> game's engine everytime
+							 the player pushes one of the four buttons in the game. Our main goal in that function
+							 is to validate the pushed button and start managing points for an eventual victory.
+							 To do so, the functions simon.GetScore() and simon.SetScore() will be used. View the
+							 simplicity of this function and the advancement in the tutorial, this function will
+							 not be explained in details. Just remember what we've dicuss so far in the turorial:
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							-- Event handler called by simon.dll when any of the colored buttons are clicked<br>
+							function simon:OnButtonClick(ButtonIndex)<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;local Result = 0<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;UserSequenceCount = UserSequenceCount + 1<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;if MainSequence[UserSequenceCount] == ButtonIndex then<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon.SetScore(simon.GetScore() + 10)<br>
+								    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result = 1<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;end<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;return Result<br>
+							end<br>
+						</blockquote>
+					</td>						  
+				</tr>  
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	 In the next step of this tutorial, we will discuss more about controling the
+							 game in the main loop and linking the functions from the C/C++/Delphi dll file.
+						  </p> 
+						  <br>
+					</td>
+				</tr> 
+				<tr> 
+					<td valign="bottom">													  
+						<font face="Tahoma" size="2">
+						<div align="left" valign="bottom">
+							<a href=".\Page2_En.html">&lt;&lt; Previous</a>
+						</div>	
+					</td> 
+					<td>   
+						<font face="Tahoma" size="2">
+						<div align="right" valign="bottom">
+                             <a href=".\Page4_En.html">Next &gt;&gt;</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Bind a Dll to LuaEdit (Tutorial)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>

+ 305 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/English/Page4_En.html

@@ -0,0 +1,305 @@
+<html>	
+	<head>
+		  <title>
+		  		 Bind a Dll to LuaEdit (Tutorial) - Controling and binding the Game
+		  </title>	
+		  <link rel="stylesheet" href="..\Tutorial.css" type="text/css">
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Controling and binding the Game</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Lua homepage</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2">
+						  <hr size="1" color="#000000">
+						  <br>
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <p style="text-align:justify">
+							 Now that we have quiet something to start with, it's time to actually control
+							 the game through that previously created main loop.
+						  </p>
+						  <br> 
+						  </font>
+					</td>
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <p style="text-align:justify"> 
+						  	 Before the simon.Create() function call previously added, we will add a new call
+							 to the simon.SetMediaPath() function. This will specify the game's engine to look
+							 in the specified directory to find its multimedia files (*.wav). Here is how the whole
+							 chunk should looks like:
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							-- Show Simon game main form<br>
+							simon.SetMediaPath("C:\\Prog\\Delphi\\MNet\\Bin\\Medias")<br>
+							simon.Create()<br><br>
+							
+							-- Main processing loop<br>
+							while simon.GetPowerStatus() == 1 do<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;if simon.GetPlayStatus() == 1 then<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:Initialize()<br><br>
+									
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- Game processing loop<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while GameState do<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserSequenceCount = 0<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:AddSequence()<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:DisplayMessage("Simon's Turn!", "clRed", 750)<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:PlaySequence(MainSequence)<br><br>
+										
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:DisplayMessage("Your Turn!", "clLime", 1000)<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GameState = simon.GetUserSequence(SequenceCount, 2000)<br><br>
+										
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if simon:GetScore() > 1000 then<br>
+											&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:DisplayMessage("You Win!", "clAqua", -1)<br>
+											&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GameState = false<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;end<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;-- Make sure the processor doesn't runs for no reason<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;Sleep(10)<br>
+							end<br><br>
+							
+							simon.Destroy()<br>
+						</blockquote>
+					</td>						  
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	 The function simon.GetPowerStatus() is used to determine if the "power" (in our 
+							 case virtual) is still on. If this function returns 1, this means the "power" is still
+							 on. The simon.GetPlayerStatus() function returns 1 if the user pushed the "play" button.
+							 Calling simon.DisplayMessage() will display the specified string using the specified 
+							 color (for color codes, look at the "Delphi/C++ Builder" column of
+							 <a href="http://www.iocomp.com/support/helpvcl/ioc01592.htm">this website</a>) and
+							 and the specified length in miliseconds. In our case, this will be use to display whose turn it is.
+							 The function simon.GetUserSequence() will prompt the user to enter its sequence. The first
+							 argument specifies the length of the sequence to retrieve and the second one specifies
+							 the timeout value in miliseconds to use before considering the turn as wrong. In terms of
+							 execution in the Lua script, this call should hang the code while waiting for user's response
+							 but will eventually trigger automated calls to the simon:OnButtonClick() function everytime
+							 the user pushes a button from the game. This function also return the state of the game
+							 (false == game over). Now, the following should briefly explain how to configure the dll
+							 in C++/Delphi to actually allow LuaEdit to bind to your code, in this case: simon.dll. (The full
+							 code is available in the tutorial's sources but for a reason of time and complexity, it won't be explained in
+							 details like the simon.lua script. Only the "initializer" part will be.)
+						  </p> 	
+						  <p style="text-align:justify"> 
+						  	 As discussed in the <a href=".\Page1_En.html">part 1</a> of the tutorial, your dll MUST export the
+							 specific function LuaDebug_Initializer(). This function will be called by LuaEdit right before starting
+							 a debugging session. We will then use this "hook"/"callback" to register all of the game's engine
+							 functions previously described. This will map the functions in Lua and prevent LuaEdit from yelding
+							 errors because it can't find any reference to the function from the script. This way, runtime debugging
+							 will be available through LuaEdit.
+						  </p>
+						  <br>
+						  <b>Delphi:</b> (This function must added in the "exports" instruction area of your code just like all the registred functions referenced in it)
+						  <br>
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>						
+								// Register a c function in a specified table<br>
+								procedure LuaRegisterCustom(L: PLua_State; ndx: Integer; funcname: String; func: lua_CFunction);<br>
+								begin<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_pushstring(L, funcname);<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_pushcfunction(L, func);<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_rawset(L, ndx - 2);<br>
+								end;<br><br>
+												
+								// Register a c function using the globalsindex constant<br>
+								procedure LuaRegister(L: PLua_State; funcname: String; func: lua_CFunction);<br>
+								begin<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, LUA_GLOBALSINDEX, funcname, func);<br>
+								end;<br><br>
+														
+								// LuaEdit is calling this function everytime a script with a project<br>
+								// specifying this dll as the initializer when debugging<br>
+								function LuaDebug_Initializer(L: PLua_State): Integer;<br>
+								begin<br>
+								  	 &nbsp;&nbsp;&nbsp;&nbsp;// Create new table on the lua stack<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;lua_newtable(L);<br><br>
+								
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Register delphi functions in that new table<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'SetMediaPath', SetMediaPath);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'SetLight', SetLight);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'Create', Create);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'Destroy', Destroy);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'GetUserSequence', GetUserSequence);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'GetPowerStatus', GetPowerStatus);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'GetPlayStatus', GetPlayStatus);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'SetScore', SetScore);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'GetScore', GetScore);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'LockControls', LockControls);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'UnlockControls', UnlockControls);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'DisplayMessage', DisplayMessage);<br><br>
+									
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Register other miscalleneous functions<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegister(L, 'Sleep', LuaSleep);<br><br>
+									
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Assing "simon" lua global variable to the new table<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;lua_setglobal(L, 'simon');<br>
+								end;<br>
+						</blockquote>
+					</td>						  
+				</tr>
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>
+						  <b>C/C++:</b> (This function must added in the "EXPORTS" instruction area of your *.def file just like all the registred functions referenced in it)
+						  <br>
+						  <br>
+					</td>
+				</tr> 
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>						
+								// Register a c function in a specified table<br>
+								void LuaRegisterCustom(lua_State *L, long ndx, const char* funcname, lua_CFunction func)<br>
+								{<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_pushstring(L, funcname);<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_pushcfunction(L, func);<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_rawset(L, ndx - 2);<br>
+								}<br><br>
+												
+								// Register a c function using the globalsindex constant<br>
+								void LuaRegister(lua_State *L, const char* funcname, lua_CFunction func)<br>
+								{<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, LUA_GLOBALSINDEX, funcname, func);<br>
+								}<br><br>
+														
+								// LuaEdit is calling this function everytime a script with a project<br>
+								// specifying this dll as the initializer when debugging<br>
+								int LuaDebug_Initializer(lua_State *L)<br>
+								{<br>
+								  	 &nbsp;&nbsp;&nbsp;&nbsp;// Create new table on the lua stack<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;lua_newtable(L);<br><br>
+								
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Register delphi functions in that new table<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "SetMediaPath", SetMediaPath);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "SetLight", SetLight);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "Create", Create);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "Destroy", Destroy);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "GetUserSequence", GetUserSequence);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "GetPowerStatus", GetPowerStatus);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "GetPlayStatus", GetPlayStatus);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "SetScore", SetScore);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "GetScore", GetScore);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "LockControls", LockControls);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "UnlockControls", UnlockControls);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "DisplayMessage", DisplayMessage);<br><br>
+									
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Register other miscalleneous functions<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegister(L, "Sleep", LuaSleep);<br><br>
+									
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Assing "simon" lua global variable to the new table<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;lua_setglobal(L, "simon");<br>
+								}<br>
+						</blockquote>
+					</td>						  
+				</tr>
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	 The LuaRegisterCustom() and LuaRegister() functions will simplify the code's complexity
+							 since we would have had to repeat those 3 lines of code for every functions that
+							 we needed to register in the Lua environment. Now, to complete this project/turotial,
+							 all you need to do inspired yourself from the supplied code and finish the dll. As mentioned
+							 higher, this part will not be explained in details.
+						  </p>
+						  <br>
+						  <p style="text-align:justify">
+						  	 Now you've seen enough to know how Lua works in interaction with LuaEdit to eventually
+							 build your own project that way so that Lua code can finally be an easy thing to debug.
+							 I hopped this tutorial helped you in many ways. If you still have questions you can always
+							 post a new thread in the <a href="">"Tutorial" section</a> of our forum or feel free to
+							 contact me at the following address: <a href="mailto:[email protected]?subject=About Bind a Dll to LuaEdit (Tutorial)...">
+							 [email protected]</a>. Thank you very much for using this tutorial and good luck in your future projects!
+						  </p>
+					</td>
+				</tr>
+				<tr>	  
+					<td colspan="2">
+							<font face="Tahoma" size="2">
+					 	  	<br>
+							<br>
+							<b>Hints:</b>
+							<ul type="square">		
+								<li>Try live debugging with the script you just finished using the compiled simon.dll
+									and lua.dll located in the bin folder. Copy/paste the project and Lua script you
+									created in that same folder, launch LuaEdit, set a breakpoint somewhere and press
+									play.</li>				 
+								<li>Try adding some "Level" logic in the Lua code by modifying the game's variants
+								    such as the sequence display speed, the player's timeout, the number of
+									items added to the main sequence per turn, etc...</li>
+								<li>Challenge your firends with some "impossible to win" scripts! :P</li>
+								<li>For more advanced users, try adding a multiplayer engine to play over LAN.</li>
+								<li>Implement an *.exe application that will launch the dll the same way LuaEdit
+									does by calling at first the LuaDebug_Initializer() function and then loading
+									the Lua script using the luaL_loadbuffer() API. See Delphi code of the SimonExec
+									project.</li>
+							</ul>
+						  </p> 
+					</td>
+				</tr> 
+				<tr> 
+					<td valign="bottom">													  
+						<font face="Tahoma" size="2">
+						<div align="left" valign="bottom">
+							<a href=".\Page3_En.html">&lt;&lt; Previous</a>
+						</div>	
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Bind a Dll to LuaEdit (Tutorial)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>
+

+ 78 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/Francais/Intro_Fr.html

@@ -0,0 +1,78 @@
+<html>	
+	<head>
+		  <title>
+		  		 Lier une Dll 'a LuaEdit (Tutoriel) - Introduction
+		  </title>
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Introduction</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Page d'accueuil Lua</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2">
+						  <hr size="1" color="#000000">
+						  <br>
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <p style="text-align:justify">
+						    Bienvenue dans le tutoriel "Lier une Dll à LuaEdit". Ce tutoriel vous apprendra comment
+							lier à LuaEdit un fichier dll qui exporte la fonction "Initializer" (nous verrons
+							ceci en détail plus tard) pour permettre un déboguage en temps réel. Ce tutoriel devrais être
+							d'une durée de 1 à 2 heure pour un débutant ou quelques minutes pour un expert. Aucun matériel n'est requit
+							pour ce tutoriel mis à part un ordinateur (Je pense que ceci ne posera pas de problèmes!), les fichiers
+							distribués avec le tutoriel et LuaEdit version 2.5 (ou mieu). (Une copie gratuite de LuaEdit est disponible <a href="http://luaforge.net/frs/?group_id=84">
+							ici</a>) Tout au long du tutoriel vous devriez être capable de localiser les liens "&lt;&lt; 
+							Précédent" et "Suivant &gt;&gt;" au bas de chaque page.	Aussi, jettez un coup d'oeil aux sections
+							<b>Conseils</b>. Elles pourraient s'avérer utiles si vous n'êtes pas à l'aise avec l'interface de LuaEdit ou
+							si vous avez envie d'approfondir vos connaissances davantage. Bonne chance!
+						  </p>
+						  <br> 
+						  </font>
+					</td>
+				</tr> 
+				<tr> 
+					<td valign="bottom">													  
+						<font face="Tahoma" size="2">
+						<div align="left" valign="bottom">
+							<a href="..\Welcome.html">&lt;&lt; Précédent</a>
+						</div>	
+					</td> 
+					<td>   
+						<font face="Tahoma" size="2">
+						<div align="right" valign="bottom">
+                             <a href=".\Page1_Fr.html">Suivant &gt;&gt;</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Lier une Dll à LuaEdit (Tutoriel)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>
+

+ 104 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/Francais/Page1_Fr.html

@@ -0,0 +1,104 @@
+<html>	
+	<head>
+		  <title>
+		  		 Lier une Dll à LuaEdit (Tutoriel) - Et c'est un Départ!
+		  </title>
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Et c'est un Départ!</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Page d'accueuil Lua</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2">
+						  <hr size="1" color="#000000">
+						  <br>
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <p style="text-align:justify">
+						  	Tout d'abord, téléchargez LuaEdit <a href="http://luaforge.net/frs/?group_id=84&release_id=318">ici</a>,
+							installez-le et démarrez-le. (Si LuaEdit est déjà installé, il est inutile de le retélécharger et réinstaller)
+							Ensuite, on doit créer un nouveau project qui contiendra une script lua.
+							Une fois le project créé, sauvegardez-le sous [Tutoriel]\Bin\Simon.lpr et sauvegardez la script lua
+							sous [Tutoriel]\Bin\Simon.lua où [Tutoriel] représente le chemin où vous avez dézippé le tutoriel.
+							On se doit de le faire ainsi afin d'utiliser la propriété "Initializer". Cette propriété
+							est en fait le chemin complet d'une dll qui DOIT exporter une fonction suivant le prototype suivant:
+							
+							<ul type="square"> 
+							  <li>Delphi: <b style="color: navy">&nbsp;LuaDebug_Initializer(L: PLua_State): Integer; cdecl;&nbsp;</b></li>
+							  <li>C/C++: <b style="color: navy">&nbsp;int LuaDebug_Initializer(lua_State *L);&nbsp;</b></li>
+							</ul>
+										   
+							Cette fonction sera appelée juste avant l'exécution de la script et peut être utilisée
+							pour différente raison d'un projet à l'autre. En d'autre mots, ceci se trouve à être une fonction "call back" dans laquel vous
+							pouvez fair pratiquement quoi que soit d'utile avec/sans l'environnement Lua avant l'exécution d'une script Lua.
+							Seul les scripts lua contenue dans un projet peuvent bénéficier de la propriété "Initializer"
+							étant donné le fait que celle-ci n'est disponible que dans les options d'un projet.	Dans ce tutoriel, nous 
+							assignerons le chemin complet du fichier [Tutorial]\Bin\simon.dll. Cette dll exporte déjà la fonction discuté plus haut
+							pour enregister des fonctions dans l'environnement Lua. Une fois cette propriété ajusté, sauvegardez le projet
+							et commencons à parler de code!
+							<br>
+							<br>
+							<br>
+							<b>Conseils:</b>
+							<ul type="square">						 
+								<li>Pour créer un projet, cliquez sur le menu Files/New/Project</li>
+								<li>Si vous ne trouvez pas la fenêtre "Project Tree", c'est peut-être parce qu'elle.
+									est cachée. Pour l'afficher, cliquez sur le menu View/Project Tree.</li>
+								<li>Pour ajuster la propriété "Initializer" d'un projet, appliquez un cliquer droit sur celui-ci
+									et cliquez sur le menu Project Settings. Dans cette boîte de dialogue
+									selectionnez le tabulateur Debug. Specifiez le chemin complet de la dll en question
+									et appuyez sur Ok lorsque terminé.</li>
+								<li>Vous voulez peut-être changer le nom du projet pour l'apperler "Simon".
+									Changer cette propriété n'a aucun effet sur le comportement du code Lua
+									mais peut être utile pour se retrouver dans l'interface de LuaEdit.</li>
+							</ul>
+						  </p>
+						  <br> 
+						  </font>
+					</td>
+				</tr> 
+				<tr> 
+					<td valign="bottom">													  
+						<font face="Tahoma" size="2">
+						<div align="left" valign="bottom">
+							<a href=".\Intro_Fr.html">&lt;&lt; Précédent</a>
+						</div>	
+					</td> 
+					<td>   
+						<font face="Tahoma" size="2">
+						<div align="right" valign="bottom">
+                             <a href=".\Page2_Fr.html">Suivant &gt;&gt;</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Lier une Dll à LuaEdit (Tutoriel)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>

+ 217 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/Francais/Page2_Fr.html

@@ -0,0 +1,217 @@
+<html>	
+	<head>
+		  <title>
+		  		 Lier une Dll à LuaEdit (Tutoriel) - Créer les Bases du Code
+		  </title>	 
+		  <link rel="stylesheet" href="..\Tutorial.css" type="text/css">
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Créer les Bases du Code</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Page d'accueuil Lua</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2">
+						  <hr size="1" color="#000000">
+						  <br>
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <p style="text-align:justify">
+							Avant de commencer à programmer la logique du jeu Simon<sup>®</sup>, il y a quelques bases que
+							l'ont doit créer, tout comme dans n'importe quel autre projet. Commencons par ajouter les variables
+							suivante au début du script:
+						  </p>
+						  <br> 
+						  </font>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>	  
+							-- Set "constants" for Simon game<br>
+							local SIMON_NONE		= 0<br>
+							local SIMON_RED			= 1<br>
+							local SIMON_BLUE		= 2<br>
+							local SIMON_YELLOW		= 3<br>
+							local SIMON_GREEN		= 4
+						</blockquote>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>
+						  <p style="text-align:justify"> 
+						  	Ces variables seront utilisées "comme si" elle étaient des constantes étant donné le fait que
+							le concepte de constantes n'existe pas vraiment en Lua. Cela signifie que notre code ne modifira
+							pas leurs contenue. Ensuite, allons ajouter de "réel" variables (leurs contenue ne sera pas
+							modifier tout au long de la script) pour controler l'environnment du jeu:
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>	  
+							-- Game handling variables<br>
+							local GameState = true<br>
+							local MainSequence = {}<br>
+							local SequenceCount = 0<br>
+							local UserSequenceCount = 0
+						</blockquote>
+					</td>						  
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>
+						  <p style="text-align:justify"> 
+						  	La variable GameState est un booléen qui contiendra false si le jeu est terminé. MainSequence est
+							une table qui contiendra la séquence complète depuis le début d'une nouvelle partie. la variable SequenceCount is
+							un entier qui contiendra le compte actuel de la longeur totale de la séquence. Finallement, UserSequenceCount est un entier
+							qui contiendra la longeur de la séquence entrée par le joueur jusqu'à maintenant. Maintenant, nous allons ajouter 4 fonctions dans lesquelles
+							nous ajouterons du code plus tard. Ces fonctions seront localisées dans la table simon qui sera créée par le moteur du jeu
+							(simon.dll) quand la script sera intialisée à travers la fonction "Initializer":
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							function simon:OnButtonClick(ButtonIndex)<br>
+							end<br><br>
+							
+							function simon:AddSequence(Sequence)<br>
+							end<br><br>
+							
+							function simon:PlaySequence(Sequence)<br>
+							end<br><br>
+							
+							function simon:Initialize()<br>
+							end<br>
+						</blockquote>
+					</td>						  
+				</tr>
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>
+						  <p style="text-align:justify"> 
+						  	La fonction OnClick(ButtonIndex) sera appelée à chaque fois que le joueur cliquera sur
+							un bouton dans le jeu. Cette fonction servira à valider le
+							bouton dans la séquence courrante. Les fonctions simon:AddSequence(Sequence), 
+							simon:PlaySequence(Sequence) et simon:Initialize() sont des fonctions appelées
+							à travers la script lors de différentes étapes durant le jeu.
+							Une dernière chose est requise avant la fin de cette étape: créer la charpente.
+							Pour se faire, une boucle principale sera ajoutée en fin de fichier comme suit:
+						  </p> 
+						  <br>
+					</td>
+				</tr> 
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							simon.Create()<br><br>
+							
+							-- Main processing loop<br>
+							while simon.GetPowerStatus() == 1 do<br>
+							  &nbsp;&nbsp;&nbsp;&nbsp;-- Make sure the processor doesn't runs for no reason<br>
+							  &nbsp;&nbsp;&nbsp;&nbsp;Sleep(10)<br>
+							end<br><br>
+							
+							simon.Destroy()<br>
+						</blockquote>
+					</td>						  
+				</tr>
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>
+						  <p style="text-align:justify"> 
+						  	Cette boucle manipulera le jeu du début jusqu'à la fin. Un itération dans cette
+							boucle sera exécuté plusieurs fois par seconde tandisqu'un tel travail de la par du processeur n'est
+							aucunement nécessaire au jeu afin de fonctionner. C'est pourquoi le moteur du jeu (simon.dll) exporte une fonction appelée Sleep()
+							qui signale au processeur de "dormir" pendant un certain laps de temps en milisecondes.
+							En d'autre mots, en employant cette fonction nous nous assurerons que le jeu n'utilisera pas 100% des ressources du processeur
+							alors que dans ce cas précis nous n'en avons guerre de besoin.	Aussi, comme vous avez probablement déjà remarqué,
+							cette partie de code inclue deux appels à des fonctions du moteur du jeu: simon.Create() et
+							simon.Destroy(). la fonction simon.Create() crée l'interface du jeu Simon<sup>®</sup> afin d'interagir
+							avec le joueur alors que la fonction simon.Destroy() détruit celle-ci. Dans la prochaine étape,
+							ajouterons du code à l'intérieur des fonctions que nous venons d'instancier.
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>	  
+					<td colspan="2">
+							<font face="Tahoma" size="2">
+							<b>Conseils:</b>
+							<ul type="square">						 
+								<li>L'expression réservé "local" utilisée lors de la déclaration de variables ci-haut
+									n'est pas nécessaire au code afin de fonctionner dans la mesure où la script n'est pas chargé dans d'autre scripts.
+									Cepandant, étant donné que ces variables ne seront utilisées que dans le scope global
+									de ce scripts, il serait recommendé, afin de prévenir tout potentiel problème que ce soit,
+									de garder l'instruction "local" instruction même si elle n'est pas nécessaire dans ce cas précis. Voir
+									section 2.6 de la documentation Lua 5.0 pour plus de détails. (Disponible dans le menu Help de LuaEdit)</li>
+								<li>La fonction Create() accepte un argument optionel. Celui-ci gère le "comment" l'interface sera crée.
+									Quand cet argument vaut 1, l'interface est crée dans une fenêtre ajustable. Lorsque ce même argument
+									vaut 2, l'interface est créé dans une fenêtre d'outils ajustable. Lorsque l'argument vaut ni 1, ni 2, 
+									l'interface est créé dans une fenêtre sans bordure. Dans l'example, l'argument
+									optionel valait nil puisque nous n'avions jamais donné quelque valeur que ce soit lors de l'appel de cette fonction.</li>
+							</ul>
+						  </p> 
+					</td>
+				</tr>
+				<tr> 
+					<td valign="bottom">													  
+						<font face="Tahoma" size="2">
+						<div align="left" valign="bottom">
+							<a href=".\Page1_Fr.html">&lt;&lt; Précédent</a>
+						</div>	
+					</td>
+					<td>   
+						<font face="Tahoma" size="2">
+						<div align="right" valign="bottom">
+                             <a href=".\Page3_Fr.html">Suivant &gt;&gt;</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Lier une Dll à LuaEdit (Tutoriel)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>

+ 258 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/Francais/Page3_Fr.html

@@ -0,0 +1,258 @@
+<html>	
+	<head>
+		  <title>
+		  		 Lier une Dll à LuaEdit (Tutoriel) - Gérer le Jeu
+		  </title>	
+		  <link rel="stylesheet" href="..\Tutorial.css" type="text/css">
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Gérer le Jeu</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Page d'accueuil Lua</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2">
+						  <hr size="1" color="#000000">
+						  <br>
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <p style="text-align:justify">
+							Maintenant, la script contient de solides bases/structures autour desquelles nous allons
+							ajouter du code pour gérer le jeu. Cela signifie algorythmes de génération aléatoire de séquence,
+							validations de touche, système de pointage, etc. Commencons par la routine d'intialisation du jeu.
+						  </p>
+						  <br> 
+						  </font>
+					</td>
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <p style="text-align:justify"> 
+						  	La fonction simon:Initialize() précédemment ajoutée sera appelé juste avant chaque nouvelle partie
+							requise par le joueur. Notre but principal dans cette fonction est de réinitialiser tout les variables de manipulation
+							précédemment créées et initialiser la logique de hasard. Dans le monde des ordinateurs, générer
+							le hasard est loin d'être une mince chose à accomplir. Soyons réalistes, il est impossible de recréer
+							exactement ce que le hasard est par définition. D'un autre côté, nous pouvons générer quelque chose
+							de si grand en termes de quantité de possibilités, que statistiquement et humainement parlant, nous pouvons
+							appeler cela du hasard. Le moteur de pseudo-hasard de Lua fonctionne de la même manière que celui du C/C++.
+							En fait, "derrière la scène", Lua utilise le moteur de pseudo-harsard du C/C++. Ce moteur fonctionne
+							avec des "seeds" (semances) pour générer des séquences de numéros au "hasard". Une "seed" (semance) est un nombre qui sera
+							utilisé pour générer les numéros au "hasard". En d'autre mots, deux séquences utilisant la même "seed" (semance)
+							sera identique. Pour éviter ce problème, plusieurs scripts/programmes utilisent l'heure courrante du système
+							comme "seed" (semance), ce qui rend pratiquement impossible pour l'utilisateur d'obetenir ou même de se rappeler
+							d'avoir obetenue la même séquence. Voici comment la fonction simon:Initialize() devrait ressembler à:
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							-- Initialize the game<br>
+							function simon:Initialize()<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;-- Initalize variables<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;simon:SetScore(0)<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;GameState = true<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;UserSequenceCount = 0<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;SequenceCount = 0<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;MainSequence = {}<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;-- Initialize random engine<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;math.randomseed(os.time())<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;math.random()<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;math.random()<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;math.random()<br>
+							end<br>
+						</blockquote>
+					</td>						  
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	Dans le précédent exemple de code, la fonction math.random() est appelée par trois fois parce que sur certains
+							système d'exploitation (du moins dans Windows 2k<sup>®</sup>) les premiers numéros d'une séquence de hasard que vous obtenez ne sont pas réellement
+							"hasardés". (Source prise du site web <a href="http://lua-users.org/wiki/MathLibraryTutorial">lua-users wiki</a>) Pour obtenir de meilleur pseudo-hasardeux numéros, nous avons juste à générer quelques numéros au hasard
+							avant de réellement les utiliser. Les autre lignes de code dans le précédent exemple initialise les variables précédemment
+							déclarées à <a href=".\Page2_En.html">l'étape 2</a> de ce tutoriel. Maintenant, ajoutons du code à la
+							fonction simon:AddSequence(Sequence). Le but de cette fonction est d'ajouter un nouvel item à séquence
+							principale que le joueur essaira de reproduire plus tard. Pour se faire, nous incrémenterons par 1
+							la variable globale SequenceCount et nous "hasarderons" un numéro de 1 à 4. Le numéro généré
+							représentera une des lumière à allumer dans la séquence. Voici à quoi la fonction devrait ressembler à:
+						  </p> 
+						  <br>
+					</td>
+				</tr>  
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							-- Add one more part to the game's sequence<br>
+							function simon:AddSequence()<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;SequenceCount = SequenceCount + 1<br>
+							    &nbsp;&nbsp;&nbsp;&nbsp;MainSequence[SequenceCount] = math.random(4)<br>
+							end<br>
+						</blockquote>
+					</td>						  
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	 Maintenant, remplissons la fonction simon:PlaySequence(Sequence). Le principal obectif de cette
+							 fonction est de jouer une séquence précédemment bâtit par l'intermédiaire de fonctions exportées du
+							 moteur du jeu Simon<sup>®</sup>. Dans cette fonction, on devrait analyser la table de la séquence principale
+							 item par item et allumet la lumière qui correspond avec la valeur de l'item courrant.
+							 Soyons un peu plus spécifique:
+						  </p> 
+						  <br>
+					</td>
+				</tr> 
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							-- Play the game's sequence<br>
+							function simon:PlaySequence(Sequence)<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;local v = nil<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;local i = nil<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;-- Lock controls from user to make sure no conflicts happened while palying sequence<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;simon.LockControls()<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;-- Play all sequence<br>
+							    &nbsp;&nbsp;&nbsp;&nbsp;repeat<br>
+							    	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon.SetLight(SIMON_NONE)<br>
+							    	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sleep(300)<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i, v = next(Sequence, i)<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon.SetLight(v)<br><br>
+							
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if i ~= nil then<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sleep(500)<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>
+							    &nbsp;&nbsp;&nbsp;&nbsp;until i == nil<br><br>
+							    
+							    &nbsp;&nbsp;&nbsp;&nbsp;simon.UnlockControls()<br>
+							    &nbsp;&nbsp;&nbsp;&nbsp;simon.SetLight(SIMON_NONE)<br>
+							end<br>
+						</blockquote>
+					</td>						  
+				</tr>  
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	 Les deux variables locales v et i serons utilisées pour récupérer le résultat
+							 du retour aux appels à la fonction next(). La fonction next() sert à obtenir l'item
+							 suivant l'élément donné dans une table Lua en passant celle-ci et l'index de
+							 l'élément courrant comme arguments. Les fonctions simon.LockControls() et simon.UnlockControls()
+							 sont exportées du moteur du jeu leur but principal est de verrouiller/déverrouiller
+							 les contrôles au joueur afin d'éviter toute conflit dans le code. Dans le précédent exemple
+							 de code, ces appels effectués avant et après la boucle qui s'occupe d'afficher la séquence
+							 au joueur à l'écran. Aussi, la l'exemple de code, l'instruction repeat...until
+							 a été utilisé afin de permettre au code d'entrer dans la bouvle à la première itération
+							 chaque fois qu'il le doit mais n'importe quel autre syntaxe de boucle aurait très bien pu faire l'affaire.
+							 Le premier morceau de code dans la boucle principale est un appel à la fonction simon.SetLight() utilisant
+							 SIMON_NONE comme premier et seul argument. Cette instruction fermera tout les lumières
+							 dans le jeu parce que nous voulons nous assurer que pour chaque item il n'y aille pas d'autre lumière allumée
+							 que celle représenter par l'item courrant. Ensuite, nous avons un appel à la fonction Sleep() avec 300 miliseconds
+							 comme argument. Cet appel, contrairement à celui à <a href=".\Page2_En.html">l'étape 2</a> du
+							 tutoriel, a le même effet sur le processeur de l'ordinateur mais est davantage utilisé dans ce cas-ci comme un dispositif de "pause"
+							 plutôt qu'un dispositif de "rallentissement". Avec ce qui a été clarifié jusqu'à maintenant,
+							 vous devriez être capable de comprendre les lignes de code qui n'ont toujours pas été expliquées.
+						  </p> 
+						  <p style="text-align:justify"> 
+						  	 Afin de finaliser cette étape, nous allons ajouter un peu de code à la fonction simon:OnButtonClick(ButtonIndex).
+							 Cette fonction sera apellée depuis le moteur du jeu Simon<sup>®</sup> à chaque fois que
+							 le joueur appuira sur un des quatre bouttons du jeu. Notre but principal dans cette fonction
+							 est de valider les boutton que le joueur à appuyé et commencer à gérer le système de pointage pour une éventuelle victoire.
+							 Pour se faire, les fonctions simon.GetScore() et simon.SetScore() seront utilisées. Étant donné la
+							 simplicité de cette fonction et l'avancement du tutoriel, cette fonction ne sera pas
+							 expliqué en détail. Vous avez juste à vous rappeler de ce que nous avons discuté jusqu'à maintenant dans ce turoriel:
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							-- Event handler called by simon.dll when any of the colored buttons are clicked<br>
+							function simon:OnButtonClick(ButtonIndex)<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;local Result = 0<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;UserSequenceCount = UserSequenceCount + 1<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;if MainSequence[UserSequenceCount] == ButtonIndex then<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon.SetScore(simon.GetScore() + 10)<br>
+								    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result = 1<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;end<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;return Result<br>
+							end<br>
+						</blockquote>
+					</td>						  
+				</tr>  
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	 Dans la prochaine étape de ce tutoriel, nous discuterons davantage à propos du "contrôle" du jeu
+							 dans la boucle principale et lier les fonctions de la dll C/C++/Delphi.
+						  </p> 
+						  <br>
+					</td>
+				</tr> 
+				<tr> 
+					<td valign="bottom">													  
+						<font face="Tahoma" size="2">
+						<div align="left" valign="bottom">
+							<a href=".\Page2_Fr.html">&lt;&lt; Précédent</a>
+						</div>	
+					</td> 
+					<td>   
+						<font face="Tahoma" size="2">
+						<div align="right" valign="bottom">
+                             <a href=".\Page4_Fr.html">Suivant &gt;&gt;</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Lier une Dll à LuaEdit (Tutoriel)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>

+ 304 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/Francais/Page4_Fr.html

@@ -0,0 +1,304 @@
+<html>	
+	<head>
+		  <title>
+		  		 Lier une Dll à LuaEdit (Tutoriel) - Contrôler et Lier le Jeu
+		  </title>	
+		  <link rel="stylesheet" href="..\Tutorial.css" type="text/css">
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Contrôler et Lier le Jeu</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Page d'accueuil Lua</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2">
+						  <hr size="1" color="#000000">
+						  <br>
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <p style="text-align:justify">
+							 Maintenant que nous avons un bon "quelque chose" avec quoi démarrer, c'est le temps de vraiment contrôler
+							 le jeu à travers la boucle principale précemment créée.
+						  </p>
+						  <br> 
+						  </font>
+					</td>
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <p style="text-align:justify"> 
+						  	 Avant l'appel à la fonction simon.Create() précédemment ajouté, nous allons ajouter un nouvel appel
+							 à la fonction simon.SetMediaPath(). Ceci spécifiera au moteur du jeu d'analyser le répertoire
+							 spécifié pour trouver ses fichiers multimédia (*.wav). Voici comment à quoi la boucle complète devrait
+							 ressembler à:
+						  </p> 
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>
+							-- Show Simon game main form<br>
+							simon.SetMediaPath("C:\\Prog\\Delphi\\MNet\\Bin\\Medias")<br>
+							simon.Create()<br><br>
+							
+							-- Main processing loop<br>
+							while simon.GetPowerStatus() == 1 do<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;if simon.GetPlayStatus() == 1 then<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:Initialize()<br><br>
+									
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- Game processing loop<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while GameState do<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserSequenceCount = 0<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:AddSequence()<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:DisplayMessage("Simon's Turn!", "clRed", 750)<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:PlaySequence(MainSequence)<br><br>
+										
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:DisplayMessage("Your Turn!", "clLime", 1000)<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GameState = simon.GetUserSequence(SequenceCount, 2000)<br><br>
+										
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if simon:GetScore() > 1000 then<br>
+											&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simon:DisplayMessage("You Win!", "clAqua", -1)<br>
+											&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GameState = false<br>
+										&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;end<br><br>
+								
+								&nbsp;&nbsp;&nbsp;&nbsp;-- Make sure the processor doesn't runs for no reason<br>
+								&nbsp;&nbsp;&nbsp;&nbsp;Sleep(10)<br>
+							end<br><br>
+							
+							simon.Destroy()<br>
+						</blockquote>
+					</td>						  
+				</tr> 
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	 La fonction simon.GetPowerStatus() est utilisé pour déterminer si "l'allimentation" (dans notre 
+							 cas virtuel) est toujours "ouverte". Si cette fonction retourne 1, cela signifie que "l'alimentation"
+							 est toujours "ouverte". La fonction simon.GetPlayerStatus() retourne 1 si le joueur à appuyé sur le boutton "play".
+							 Appeler simon.DisplayMessage() affichera la chaîne de caractères spécifiée en utilisant la couleur spécifiée 
+							 (pour les codes de couleurs, jettez un coup d'oeil à la colonne "Delphi/C++ Builder" de ce
+							 <a href="http://www.iocomp.com/support/helpvcl/ioc01592.htm">site web</a>) et
+							 et la longueur spécifiée en milisecondes. Dans notre cas, ceci sera utilisé afin de faire savoir au joueur à quel tour il s'agit.
+							 La fonction simon.GetUserSequence() demandera au joueur d'entrer sa séquence. Le premier argument
+							 spécifie la durée de la séquence à obtenir et le deuxième spécifie la valeur du "timeout"
+							 en milisecondes à utiliser avant de considérer le tour comme échec. En terme d'exécution,
+							 dans la script Lua, cet appel devrait être suspendre le code en attedant la réponse du joueur.
+							 mais eventuellement déclanchera un appel automatique du moteur du jeu à la fonction simon:OnButtonClick() chaque fois
+							 le joueur appuiera un boutton depuis le jeu. Cette fonction retourne égallement l'état de la partie
+							 (false == "game over"). Maintenant, ce qui suit devrait brièvement expliquer comment configurer la dll
+							 en C++/Delphi pour actuellement permettre à LuaEdit de se lier à votre code, dans ce cas-ci: simon.dll. (La source
+							 complète du code est disponible dans les sources du tutoriel mais pour des raison de temps et de complexité ne sera pas expliqué complètement en détails
+							 comme la script simon.lua. Seul la partie "initializer" le sera.)
+						  </p> 	
+						  <p style="text-align:justify"> 
+						  	 Comme discuté dans <a href=".\Page1_En.html">l'étape 1</a> de ce tutoriel, votre dll DOIT exporter la
+							 fonction spécifique LuaDebug_Initializer(). Cette fonction sera appelée par LuaEdit juste avant de démarrer
+							 une session de débug. Nous allons ensuite utiliser ce "hook"/"callback" afin d'enregister toute les fonctions du
+							 moteur du jeu précédemment décrite. Ceci tracera les fonctions en Lua et préviendra LuaEdit de notifier
+							 des erreurs parce qu'il ne trouve peut trouver une référence à la fonction dans le script. De cette manière, le débuggage en temps réel
+							 sera dispnible à travers LuaEdit.
+						  </p>
+						  <br>
+						  <b>Delphi:</b> (Cette fonction doit être ajouté dans l'instruction "exports" de votre code tout comme chacune des fonctions enregistré à l'environnement Lua qui se trouve à l'intérieur de celle-ci)
+						  <br>
+						  <br>
+					</td>
+				</tr>
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>						
+								// Register a c function in a specified table<br>
+								procedure LuaRegisterCustom(L: PLua_State; ndx: Integer; funcname: String; func: lua_CFunction);<br>
+								begin<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_pushstring(L, funcname);<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_pushcfunction(L, func);<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_rawset(L, ndx - 2);<br>
+								end;<br><br>
+												
+								// Register a c function using the globalsindex constant<br>
+								procedure LuaRegister(L: PLua_State; funcname: String; func: lua_CFunction);<br>
+								begin<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, LUA_GLOBALSINDEX, funcname, func);<br>
+								end;<br><br>
+														
+								// LuaEdit is calling this function everytime a script with a project<br>
+								// specifying this dll as the initializer when debugging<br>
+								function LuaDebug_Initializer(L: PLua_State): Integer;<br>
+								begin<br>
+								  	 &nbsp;&nbsp;&nbsp;&nbsp;// Create new table on the lua stack<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;lua_newtable(L);<br><br>
+								
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Register delphi functions in that new table<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'SetMediaPath', SetMediaPath);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'SetLight', SetLight);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'Create', Create);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'Destroy', Destroy);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'GetUserSequence', GetUserSequence);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'GetPowerStatus', GetPowerStatus);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'GetPlayStatus', GetPlayStatus);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'SetScore', SetScore);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'GetScore', GetScore);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'LockControls', LockControls);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'UnlockControls', UnlockControls);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, 'DisplayMessage', DisplayMessage);<br><br>
+									
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Register other miscalleneous functions<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegister(L, 'Sleep', LuaSleep);<br><br>
+									
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Assing "simon" lua global variable to the new table<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;lua_setglobal(L, 'simon');<br>
+								end;<br>
+						</blockquote>
+					</td>						  
+				</tr>
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>
+						  <b>C/C++:</b> (Cette fonction doit être ajouté dans l'instruction "EXPORTS" de votre fichier *.def tout comme chacune des fonctions enregistré à l'environnement Lua qui se trouve à l'intérieur de celle-ci)
+						  <br>
+						  <br>
+					</td>
+				</tr> 
+				<tr>
+					<td class="code" colspan="2">
+						<br>
+						<blockquote>						
+								// Register a c function in a specified table<br>
+								void LuaRegisterCustom(lua_State *L, long ndx, const char* funcname, lua_CFunction func)<br>
+								{<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_pushstring(L, funcname);<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_pushcfunction(L, func);<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;lua_rawset(L, ndx - 2);<br>
+								}<br><br>
+												
+								// Register a c function using the globalsindex constant<br>
+								void LuaRegister(lua_State *L, const char* funcname, lua_CFunction func)<br>
+								{<br>
+									&nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, LUA_GLOBALSINDEX, funcname, func);<br>
+								}<br><br>
+														
+								// LuaEdit is calling this function everytime a script with a project<br>
+								// specifying this dll as the initializer when debugging<br>
+								int LuaDebug_Initializer(lua_State *L)<br>
+								{<br>
+								  	 &nbsp;&nbsp;&nbsp;&nbsp;// Create new table on the lua stack<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;lua_newtable(L);<br><br>
+								
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Register delphi functions in that new table<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "SetMediaPath", SetMediaPath);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "SetLight", SetLight);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "Create", Create);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "Destroy", Destroy);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "GetUserSequence", GetUserSequence);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "GetPowerStatus", GetPowerStatus);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "GetPlayStatus", GetPlayStatus);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "SetScore", SetScore);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "GetScore", GetScore);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "LockControls", LockControls);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "UnlockControls", UnlockControls);<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegisterCustom(L, -1, "DisplayMessage", DisplayMessage);<br><br>
+									
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Register other miscalleneous functions<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;LuaRegister(L, "Sleep", LuaSleep);<br><br>
+									
+									 &nbsp;&nbsp;&nbsp;&nbsp;// Assing "simon" lua global variable to the new table<br>
+									 &nbsp;&nbsp;&nbsp;&nbsp;lua_setglobal(L, "simon");<br>
+								}<br>
+						</blockquote>
+					</td>						  
+				</tr>
+				<tr>
+					<td colspan="2"> 	
+						  <font face="Tahoma" size="2">	
+						  <br>
+						  <br>	
+						  <p style="text-align:justify"> 
+						  	 Les fonctions LuaRegisterCustom() et LuaRegister() simplifieront la complexité du code
+							 étant donné le fait que nous aurions à répéter ces 3 lignes de code pour chaque fonction qui
+							 a besoins d'être enregistré à l'environnement Lua. Maintenant, pour complété ce projet/turotiel,
+							 tout ce dont vous avez besoins de faire est de vous inspirer du code fournis et de terminer cette dll. Comme mentionné
+							 ci-haut, cette partie ne sera pas expliqué en détails.
+						  </p>
+						  <br>
+						  <p style="text-align:justify">
+						  	 Maintenant, vous devriez en avoir suffisamment vue pour savoir comment Lua interragit avec LuaEdit pour éventuellement
+							 bâtir votre propre projet de cette manière afin que le code Lua soit une chose facile à débogger.
+							 J'espère grandement que ce tutoriel vous a aider de plusieurs manière. Si vous avez toujours des questions, vous pouvez toujours
+							 poster une nouvelle "thread" dans la <a href="">section "Tutorial"</a> de notre forum ou sentez à l'aiser de
+							 me contacter à l'addresse courriel suivante: <a href="mailto:[email protected]?subject=À propos de Lier une Dll à LuaEdit (Tutoriel)...">
+							 [email protected]</a>. Merci d'avoir utilisé ce tutoriel et bonne chance dans vos futur projets!
+						  </p>
+					</td>
+				</tr>
+				<tr>	  
+					<td colspan="2">
+							<font face="Tahoma" size="2">
+					 	  	<br>
+							<br>
+							<b>Hints:</b>
+							<ul type="square">		
+								<li>Essayez le déboggage en temps réel avec la script que vous venez juste d'accomplir en utilisant le fichiers compilé simon.dll
+									et lua.dll situés dans le répertoire bin du tutoriel. Copiez et collez le projet et la script Lua que venez
+									de créer dans ce même répertoire, lancez LuaEdit, ajoutez un "breakpoint" sur n'importe quelle ligne de code (pas de commentaire...)
+									et appuyez sur "play".</li>				 
+								<li>Essayez d'ajouter une logique de "Level" dans le code Lua en modifiant certaines variantes du jeu
+								    comme la vitesse d'affichage de la séquence, le "timeout" du joueur, le nombre d'item ajouté
+									à la séquence par tour, etc...</li>
+								<li>Défiez vos amis/amies avec une script modifié "impossible à gagner"! :P</li>
+								<li>Pour des utilisateurs plus avancé, essayez d'ajouter un moteur multijoueur pour joueur sur un LAN.</li>
+								<li>Implémentez une application *.exe qui lancera la dll de la même manière que LuaEdit
+									en appelant d'abord la fonction LuaDebug_Initializer() et ensuite en chargant
+									la script Lua en utilisant l'API luaL_loadbuffer(). Jettez un coup d'oeil au code Delphi du projet SimonExec.</li>
+							</ul>
+						  </p> 
+					</td>
+				</tr> 
+				<tr> 
+					<td valign="bottom">													  
+						<font face="Tahoma" size="2">
+						<div align="left" valign="bottom">
+							<a href=".\Page3_Fr.html">&lt;&lt; Précédent</a>
+						</div>	
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Lier une Dll à LuaEdit (Tutoriel)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>
+

+ 5 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/Tutorial.css

@@ -0,0 +1,5 @@
+.code {
+	font-family: Courier, 'Courier New', sans-serif; font-size: 11px; color: #006600;
+	background-color: #FAFAFA; border: #D1D7DC; border-style: solid;
+	border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
+}

+ 73 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/Welcome.html

@@ -0,0 +1,73 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>	
+	<head>
+		  <title>
+		  		 Bind a Dll to LuaEdit (Tutorial) - Welcome
+		  </title>
+	</head>
+
+	<body bgcolor="#FFFFFF" vlink="silver" alink="navy" link="navy">
+		 <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
+				<tr> 
+					<td valign="bottom">													  
+						<div align="left">
+							<b><font face="Tahoma" size="3" color="navy">Welcome</font></b>
+						</div>	
+					</td> 
+					<td>
+						<font face="Tahoma" size="1" color="silver">  
+						<div align="right" valign="top">
+							 <a href="http://www.lua.org">Lua homepage</a>
+						</div>	
+						</font>
+					</td>
+				</tr>
+				<tr valign="top">
+					<td colspan="2" align="center">
+						  <hr size="1" color="#000000">
+						  <font face="Tahoma" size="5" color="navy">
+						  <br>
+						  <br>
+						  <u>Bind a Dll to LuaEdit (Tutorial)</u>
+						  <br> 
+						  <font face="Tahoma" size="1" color="navy">
+						  <a href="mailto:[email protected]?subject=About Bind a Dll to LuaEdit (Tutorial)...">Written by Jean-Francois Goulet</a>
+						  <br>
+						  <br>
+						  <br>
+						  <br>	
+						  <br>
+						  <font face="Tahoma" size="2">
+						  <a href=".\English\Intro_En.html">Welcome (english)</a>
+						  <br>
+						  <br>
+						  <a href=".\Francais\Intro_Fr.html">Bienvenue (français)</a>
+						  <br>
+						  <br> 
+						  <br>	   
+						  <br>
+						  <br>
+						  <br>
+						  <br>
+						  <br>
+						  <br>
+						  </font>
+					</td>
+				</tr>
+				<tr>
+					<td colspan="2">
+						<font face="Tahoma" size="1" color="silver">
+						<hr size="1" color="#000000">
+							<div align="right">			  
+								<a href="http://www.luaedit.org">www.luaedit.org</a>
+								<br>
+								© Copyright 2004-2005 LuaEdit
+								<br>
+								Bind a Dll to LuaEdit (Tutorial)
+							</div>
+						</font>
+					</td>
+				</tr>
+		  </table>
+	</body>
+</html>

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/bin/Medias/01.wav


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/bin/Medias/02.wav


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/bin/Medias/03.wav


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/bin/Medias/04.wav


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/bin/Medias/SIMON.ICO


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/bin/Simon.dll


+ 14 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/bin/Simon.lpr

@@ -0,0 +1,14 @@
+[Description]
+Name=Simon
+VersionMajor=1
+VersionMinor=0
+VersionRelease=0
+VersionRevision=0
+AutoIncRevNumber=0
+[Debug]
+Initializer=C:\Prog\Delphi\MNet\Bin\Simon.dll
+RemoteIP=0.0.0.0
+RemoteDirectory=
+RemotePort=1024
+[Files]
+File0=Simon.lua

+ 111 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/bin/Simon.lua

@@ -0,0 +1,111 @@
+--[[
+
+This file manage the Simon game by randomizing sequences and validating
+results. LuaEdit's initializer logic has been implemented in Simon.dll
+to allow debugging.
+
+]]--
+
+-- Set "constant" for Simon game
+local SIMON_NONE		= 0
+local SIMON_RED			= 1
+local SIMON_BLUE		= 2
+local SIMON_YELLOW		= 3
+local SIMON_GREEN		= 4
+
+-- Game handling variables
+local GameState = true
+local MainSequence = {}
+local SequenceCount = 0
+local UserSequenceCount = 0
+
+-- Event handler called by simon.dll when any of the colored buttons are clicked
+function simon:OnButtonClick(ButtonIndex)
+	local Result = 0
+	UserSequenceCount = UserSequenceCount + 1
+	
+	if MainSequence[UserSequenceCount] == ButtonIndex then
+		simon.SetScore(simon.GetScore() + 10)
+	    Result = 1
+	end
+	
+	return Result
+end
+
+-- Add one more part to the game's sequence
+function simon:AddSequence()
+	SequenceCount = SequenceCount + 1
+    MainSequence[SequenceCount] = math.random(4)
+end  
+
+-- Play the game's sequence
+function simon:PlaySequence(Sequence)
+	local v = nil
+	local i = nil
+	
+	-- Lock controls from user to make sure no conflicts happened while palying sequence
+	simon.LockControls()
+	
+	-- Play all sequence
+    repeat
+    	simon.SetLight(SIMON_NONE)
+    	Sleep(300)
+		i, v = next(Sequence, i)
+		simon.SetLight(v)
+
+		if i ~= nil then
+			Sleep(500)
+		end
+    until i == nil
+    
+    simon.UnlockControls()
+    simon.SetLight(SIMON_NONE)
+end
+
+-- Initialize the game
+function simon:Initialize()
+	-- Initalize variables
+	simon:SetScore(0)
+	GameState = true
+	UserSequenceCount = 0
+	SequenceCount = 0
+	MainSequence = {}
+	
+	-- Initialize random engine
+	math.randomseed(os.time())
+	math.random()
+	math.random()
+	math.random()
+end
+				
+-- Show Simon game main form
+simon.SetMediaPath("C:\\Prog\\Delphi\\MNet\\Bin\\Medias")
+simon.Create()
+
+-- Main processing loop
+while simon.GetPowerStatus() == 1 do
+	if simon.GetPlayStatus() == 1 then
+		simon:Initialize()
+		
+		-- Game processing loop
+		while GameState do
+			UserSequenceCount = 0
+			simon:AddSequence()
+			simon:DisplayMessage("Simon's Turn!", "clRed", 750)
+			simon:PlaySequence(MainSequence)
+			
+			simon:DisplayMessage("Your Turn!", "clLime", 1000)
+			GameState = simon.GetUserSequence(SequenceCount, 2000)
+			
+			if simon:GetScore() > 1000 then
+				simon:DisplayMessage("You Win!", "clAqua", -1)
+				GameState = false
+			end
+		end
+	end
+	
+	-- Make sure the processor doesn't runs for no reason
+	Sleep(10)
+end
+
+simon.Destroy()

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/bin/SimonExec.exe


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/bin/lua.dll


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/LuaDelphi007.lzh


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/LuaUtils.dcu


+ 1444 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/LuaUtils.pas

@@ -0,0 +1,1444 @@
+//******************************************************************************
+//***                     LUA SCRIPT DELPHI UTILITIES                        ***
+//***                                                                        ***
+//***        (c) 2005 Jean-Fran輟is Goulet,  Massimo Magnano, Kuma           ***
+//***                                                                        ***
+//***                                                                        ***
+//******************************************************************************
+//  File        : LuaUtils.pas
+//
+//  Description : Useful functions for work with Lua in Delphi. 
+//
+//******************************************************************************
+//** See Copyright Notice in lua.h
+
+//Revision 1.6
+//     JF Adds :
+//             LuaTableToVirtualTreeView
+//
+//Revision 1.1
+//     MaxM Adds :
+//             LuaPCallFunction
+//
+//Revision 1.0
+//     MaxM Adds :
+//             LuaPushVariant
+//             LuaToVariant
+//             LuaGetTableInteger, LuaGet\SetTableTMethod
+//             LuaLoadBufferFromFile
+//     Solved Bugs : Stack problem in LuaProcessTableName
+//                   LuaToInteger why Round?, Trunc is better
+unit LuaUtils;
+
+interface
+
+uses
+  SysUtils, Classes, ComCtrls, lua, lualib, lauxlib, Variants, VirtualTrees;
+
+const
+     ERR_Script ='Script Error : ';  
+
+type
+  TOnLuaStdout = procedure (S: PChar; N: Integer);
+  ELuaException = class(Exception)
+    Title: string;
+    Line: Integer;
+    Msg: string;
+    constructor Create(Title: string; Line: Integer; Msg: string);
+  end;
+
+  PBasicTreeData = ^TBasicTreeData;
+  TBasicTreeData = record
+    sName: String;
+    sValue: String;
+  end;
+
+  TVariantArray =array of Variant;
+  PVariantArray =^TVariantArray;
+
+function Quote(const Str: string): string;
+function Dequote(const QuotedStr: string): string;
+function lua_print(L: Plua_State): Integer; cdecl;
+function lua_io_write(L: Plua_State): Integer; cdecl;
+
+function LuaToBoolean(L: PLua_State; Index: Integer): Boolean;
+procedure LuaPushBoolean(L: PLua_State; B: Boolean);
+function LuaToInteger(L: PLua_State; Index: Integer): Integer;
+procedure LuaPushInteger(L: PLua_State; N: Integer);
+function LuaToVariant(L: Plua_State; Index: Integer): Variant;
+procedure LuaPushVariant(L: Plua_State; N: Variant);
+function LuaToString(L: PLua_State; Index: Integer): string;
+procedure LuaPushString(L: PLua_State; const S: string);
+function LuaIncIndex(L: Plua_State; Index: Integer): Integer;
+function LuaAbsIndex(L: Plua_State; Index: Integer): Integer;
+procedure LuaGetTable(L: Plua_State; TableIndex: Integer; const Key: string);
+function LuaGetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string): Boolean;
+function LuaGetTableNumber(L: Plua_State; TableIndex: Integer; const Key: string): Double;
+function LuaGetTableInteger(L: Plua_State; TableIndex: Integer; const Key: string): Integer;
+function LuaGetTableString(L: Plua_State; TableIndex: Integer; const Key: string): string;
+function LuaGetTableFunction(L: Plua_State; TableIndex: Integer; const Key: string): lua_CFunction;
+function LuaGetTableLightUserData(L: Plua_State; TableIndex: Integer; const Key: string): Pointer;
+function LuaGetTableTMethod(L: Plua_State; TableIndex: Integer; const Key: string): TMethod;
+procedure LuaRawGetTable(L: Plua_State; TableIndex: Integer; const Key: string);
+function LuaRawGetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string): Boolean;
+function LuaRawGetTableNumber(L: Plua_State; TableIndex: Integer; const Key: string): Double;
+function LuaRawGetTableString(L: Plua_State; TableIndex: Integer; const Key: string): string;
+function LuaRawGetTableFunction(L: Plua_State; TableIndex: Integer; const Key: string): lua_CFunction;
+function LuaRawGetTableLightUserData(L: Plua_State; TableIndex: Integer; const Key: string): Pointer;
+procedure LuaSetTableValue(L: PLua_State; TableIndex: Integer; const Key: string; ValueIndex: Integer);
+procedure LuaSetTableNil(L: Plua_State; TableIndex: Integer; const Key: string);
+procedure LuaSetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string; B: Boolean);
+procedure LuaSetTableNumber(L: Plua_State; TableIndex: Integer; const Key: string; N: Double);
+procedure LuaSetTableString(L: Plua_State; TableIndex: Integer; const Key: string; S: string);
+procedure LuaSetTableFunction(L: Plua_State; TableIndex: Integer; const Key: string; F: lua_CFunction);
+procedure LuaSetTableLightUserData(L: Plua_State; TableIndex: Integer; const Key: string; P: Pointer);
+procedure LuaSetTableTMethod(L: Plua_State; TableIndex: Integer; const Key: string; M: TMethod);
+procedure LuaSetTableClear(L: Plua_State; TableIndex: Integer);
+procedure LuaRawSetTableValue(L: PLua_State; TableIndex: Integer; const Key: string; ValueIndex: Integer);
+procedure LuaRawSetTableNil(L: Plua_State; TableIndex: Integer; const Key: string);
+procedure LuaRawSetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string; B: Boolean);
+procedure LuaRawSetTableNumber(L: Plua_State; TableIndex: Integer; const Key: string; N: Double);
+procedure LuaRawSetTableString(L: Plua_State; TableIndex: Integer; const Key: string; S: string);
+procedure LuaRawSetTableFunction(L: Plua_State; TableIndex: Integer; const Key: string; F: lua_CFunction);
+procedure LuaRawSetTableLightUserData(L: Plua_State; TableIndex: Integer; const Key: string; P: Pointer);
+procedure LuaRawSetTableClear(L: Plua_State; TableIndex: Integer);
+function LuaGetMetaFunction(L: Plua_State; Index: Integer; Key: string): lua_CFunction;
+procedure LuaSetMetaFunction(L: Plua_State; Index: Integer; Key: string; F: lua_CFunction);
+
+procedure LuaShowStack(L: Plua_State; Caption: string = '');
+function LuaStackToStr(L: Plua_State; Index: Integer; MaxTable: Integer = -1): string;
+procedure LuaRegisterCustom(L: PLua_State; TableIndex: Integer; const Name: PChar; F: lua_CFunction);
+procedure LuaRegister(L: Plua_State; const Name: PChar; F: lua_CFunction);
+procedure LuaRegisterMetatable(L: Plua_State; const Name: PChar; F: lua_CFunction);
+procedure LuaRegisterProperty(L: PLua_State; const Name: PChar; ReadFunc, WriteFunc: lua_CFunction);
+procedure LuaStackToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer = -1);
+procedure LuaLocalToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer = -1; Level: Integer = 0);
+procedure LuaTableToStrings(L: Plua_State; Index: Integer; Lines: TStrings; MaxTable: Integer = -1);
+procedure LuaTableToVirtualTreeView(L: Plua_State; Index: Integer; VTV: TVirtualStringTree; MaxTable: Integer);
+procedure LuaTableToTreeView(L: Plua_State; Index: Integer; TV: TTreeView; MaxTable: Integer = -1);
+function LuaGetIdentValue(L: Plua_State; Ident: string; MaxTable: Integer = -1): string;
+procedure LuaSetIdentValue(L: Plua_State; Ident, Value: string; MaxTable: Integer = -1);
+procedure LuaLoadBuffer(L: Plua_State; const Code: string; const Name: string);
+procedure LuaLoadBufferFromFile(L: Plua_State; const Filename: string; const Name: string);
+procedure LuaPCall(L: Plua_State; NArgs, NResults, ErrFunc: Integer);
+function LuaPCallFunction(L: Plua_State; FunctionName :String;
+                          const Args: array of Variant;
+                          Results : PVariantArray;
+                          ErrFunc: Integer=0;
+                          NResults :Integer=LUA_MULTRET):Integer;
+procedure LuaError(L: Plua_State; const Msg: string);
+procedure LuaErrorFmt(L: Plua_State; const Fmt: string; const Args: array of Const);
+function LuaDataStrToStrings(const TableStr: string; Strings: TStrings): string;
+function LuaDoFile(L: Plua_State): Integer; cdecl;
+
+const
+  LuaGlobalVariableStr = '[LUA_GLOBALSINDEX]';
+var
+  OnLuaStdout: TOnLuaStdout;
+  DefaultMaxTable: Integer;
+
+implementation
+
+uses
+  Dialogs;
+
+const
+  QuoteStr = '"';
+  CR = #$0D;
+  LF = #$0A;
+  CRLF = CR + LF;
+
+function Quote(const Str: string): string;
+begin
+  Result := AnsiQuotedStr(Str, QuoteStr);
+end;
+
+function Dequote(const QuotedStr: string): string;
+begin
+  Result := AnsiDequotedStr(QuotedStr, QuoteStr);
+end;
+
+function fwrite(S: PChar; Un, Len: Integer; Dummy: Integer): Integer;
+// 標準出力
+var
+  Size: Integer;
+begin
+  Size := Un * Len;
+  if (Assigned(OnLuaStdout)) then
+    OnLuaStdout(S, Size);
+  Result := Size;
+end;
+
+function fputs(const S: string; Dummy: Integer): Integer;
+// 標準出力
+begin
+  Result := fwrite(PChar(S), SizeOf(Char), Length(S), Dummy);
+end;
+
+function lua_print(L: Plua_State): Integer; cdecl;
+// 標準出力関数
+const
+  TAB = #$08;
+  NL = #$0A;
+  stdout = 0;
+var
+  N, I: Integer;
+  S: PChar;
+begin
+  N := lua_gettop(L);  (* number of arguments *)
+  lua_getglobal(L, 'tostring');
+  for I := 1 to N do
+  begin
+    lua_pushvalue(L, -1);  (* function to be called *)
+    lua_pushvalue(L, i);   (* value to print *)
+    lua_call(L, 1, 1);
+    S := lua_tostring(L, -1);  (* get result *)
+    if (S = nil) then
+    begin
+      Result := luaL_error(L, '`tostring'' must return a string to `print''');
+      Exit;
+    end;
+    if (I > 1) then fputs(TAB, stdout);
+    fputs(S, stdout);
+    lua_pop(L, 1);  (* pop result *)
+  end;
+  fputs(NL, stdout);
+  Result := 0;
+end;
+
+function lua_io_write(L: Plua_State): Integer; cdecl;
+// 標準出力関数
+  function pushresult(L: Plua_State; I: Boolean; FileName: PChar): Integer;
+  begin
+    lua_pushboolean(L, 1);
+    Result := 1;
+  end;
+const
+  F = 0;
+var
+  NArgs: Integer;
+  Status: Boolean;
+  Arg: Integer;
+  Len: Integer;
+  S: PChar;
+begin
+  Arg := 1;
+  NArgs := lua_gettop(L);
+  Status := True;
+  while (NArgs > 0) do
+  begin
+    Dec(NArgs);
+    if (lua_type(L, Arg) = LUA_TNUMBER) then
+    begin
+      (* optimization: could be done exactly as for strings *)
+      Status := Status and
+          (fputs(Format(LUA_NUMBER_FMT, [lua_tonumber(L, Arg)]), 0) > 0);
+    end else
+    begin
+      S := luaL_checklstring(L, Arg, @Len);
+      Status := Status and (fwrite(S, SizeOf(Char), Len, F) = Len);
+    end;
+    Inc(Arg);
+  end;
+  Result := pushresult(L, Status, nil);
+end;
+
+function LuaToBoolean(L: PLua_State; Index: Integer): Boolean;
+begin
+  Result := (lua_toboolean(L, Index) <> 0);
+end;
+
+procedure LuaPushBoolean(L: PLua_State; B: Boolean);
+begin
+  lua_pushboolean(L, Integer(B));
+end;
+
+function LuaToInteger(L: PLua_State; Index: Integer): Integer;
+begin
+  Result := Trunc(lua_tonumber(L, Index));  //Round(lua_tonumber(L, Index));
+end;
+
+procedure LuaPushInteger(L: PLua_State; N: Integer);
+begin
+  lua_pushnumber(L, N);
+end;
+
+
+function LuaToVariant(L: Plua_State; Index: Integer): Variant;
+Var
+   dataType :Integer;
+   dataNum  :Double;
+
+begin
+     dataType :=lua_type(L, Index);
+     Case dataType of
+     LUA_TSTRING          : Result := VarAsType(LuaToString(L, Index), varString);
+     LUA_TUSERDATA,
+     LUA_TLIGHTUSERDATA   : Result := VarAsType(Integer(lua_touserdata(L, Index)), varInteger);
+     LUA_TNONE,
+     LUA_TNIL             : Result := varNull;
+     LUA_TBOOLEAN         : Result := VarAsType(LuaToBoolean(L, Index), varBoolean);
+     LUA_TNUMBER          : begin
+                                 dataNum :=lua_tonumber(L, Index);
+                                 if (Abs(dataNum)>MAXINT)
+                                 then Result :=VarAsType(dataNum, varDouble)
+                                 else begin
+                                           if (Frac(dataNum)<>0)
+                                           then Result :=VarAsType(dataNum, varDouble)
+                                           else Result :=VarAsType(dataNum, varInteger)
+                                      end;
+                            end;
+     end;
+end;
+
+procedure LuaPushVariant(L: Plua_State; N: Variant);
+begin
+     case VarType(N) of
+     varEmpty,
+     varNull          :lua_pushnil(L);
+     varBoolean         :LuaPushBoolean(L, N);
+     varStrArg,
+     varOleStr,
+     varString        :LuaPushString(L, N);
+     varDate          :LuaPushString(L, DateTimeToStr(VarToDateTime(N)));
+     else lua_pushnumber(L, N);
+     end;
+end;
+
+function LuaToString(L: PLua_State; Index: Integer): string;
+var
+  Size: Integer;
+begin
+  Size := lua_strlen(L, Index);
+  SetLength(Result, Size);
+  if (Size > 0) then
+    Move(lua_tostring(L, Index)^, Result[1], Size);
+end;
+
+procedure LuaPushString(L: PLua_State; const S: string);
+begin
+  lua_pushstring(L, PChar(S));
+end;
+
+function LuaIncIndex(L: Plua_State; Index: Integer): Integer;
+// 相対インデックス -1 ~ -N へ変換
+begin
+  if ((Index = LUA_GLOBALSINDEX) or (Index = LUA_REGISTRYINDEX)) then
+  begin
+    Result := Index;
+    Exit;
+  end;
+
+  Result := LuaAbsIndex(L, Index) - lua_gettop(L) - 1;
+end;
+
+function LuaAbsIndex(L: Plua_State; Index: Integer): Integer;
+// 絶対インデックス 1 ~ N へ変換
+begin
+  if ((Index = LUA_GLOBALSINDEX) or (Index = LUA_REGISTRYINDEX)) then
+  begin
+    Result := Index;
+    Exit;
+  end;
+
+  if (Index < 0) then
+    Result := Index + lua_gettop(L) + 1
+  else
+    Result := Index;
+end;
+
+procedure LuaPushKeyString(L: PLua_State; var Index: Integer; const Key: string);
+begin
+  Index := LuaAbsIndex(L, Index);
+  lua_pushstring(L, PChar(Key));
+end;
+
+procedure LuaGetTable(L: Plua_State; TableIndex: Integer; const Key: string);
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_gettable(L, TableIndex);
+end;
+
+function LuaGetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string): Boolean;
+begin
+  LuaGetTable(L, TableIndex, Key);
+  Result := (lua_toboolean(L, -1) <> 0);
+  lua_pop(L, 1);
+end;
+
+function LuaGetTableNumber(L: Plua_State; TableIndex: Integer; const Key: string): Double;
+begin
+  LuaGetTable(L, TableIndex, Key);
+  Result := lua_tonumber(L, -1);
+  lua_pop(L, 1);
+end;
+
+function LuaGetTableInteger(L: Plua_State; TableIndex: Integer; const Key: string): Integer;
+begin
+  LuaGetTable(L, TableIndex, Key);
+  Result := LuaToInteger(L, -1);
+  lua_pop(L, 1);
+end;
+
+function LuaGetTableString(L: Plua_State; TableIndex: Integer; const Key: string): string;
+begin
+  LuaGetTable(L, TableIndex, Key);
+  Result := lua_tostring(L, -1);
+  lua_pop(L, 1);
+end;
+
+function LuaGetTableFunction(L: Plua_State; TableIndex: Integer; const Key: string): lua_CFunction;
+begin
+  LuaGetTable(L, TableIndex, Key);
+  Result := lua_tocfunction(L, -1);
+  lua_pop(L, 1);
+end;
+
+function LuaGetTableLightUserData(L: Plua_State; TableIndex: Integer; const Key: string): Pointer;
+begin
+  LuaGetTable(L, TableIndex, Key);
+  Result := lua_touserdata(L, -1);
+  lua_pop(L, 1);
+end;
+
+function LuaGetTableTMethod(L: Plua_State; TableIndex: Integer; const Key: string): TMethod;
+begin
+     Result.Code :=LuaGetTableLightUserData(L, TableIndex, Key+'_Code'); //Code is the Method Pointer
+     Result.Data :=LuaGetTableLightUserData(L, TableIndex, Key+'_Data'); //Data is the object Pointer
+end;
+
+procedure LuaRawGetTable(L: Plua_State; TableIndex: Integer; const Key: string);
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_rawget(L, TableIndex);
+end;
+
+function LuaRawGetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string): Boolean;
+begin
+  LuaRawGetTable(L, TableIndex, Key);
+  Result := (lua_toboolean(L, -1) <> 0);
+  lua_pop(L, 1);
+end;
+
+function LuaRawGetTableNumber(L: Plua_State; TableIndex: Integer; const Key: string): Double;
+begin
+  LuaRawGetTable(L, TableIndex, Key);
+  Result := lua_tonumber(L, -1);
+  lua_pop(L, 1);
+end;
+
+function LuaRawGetTableString(L: Plua_State; TableIndex: Integer; const Key: string): string;
+begin
+  LuaRawGetTable(L, TableIndex, Key);
+  Result := lua_tostring(L, -1);
+  lua_pop(L, 1);
+end;
+
+function LuaRawGetTableFunction(L: Plua_State; TableIndex: Integer; const Key: string): lua_CFunction;
+begin
+  LuaRawGetTable(L, TableIndex, Key);
+  Result := lua_tocfunction(L, -1);
+  lua_pop(L, 1);
+end;
+
+function LuaRawGetTableLightUserData(L: Plua_State; TableIndex: Integer; const Key: string): Pointer;
+begin
+  LuaRawGetTable(L, TableIndex, Key);
+  Result := lua_touserdata(L, -1);
+  lua_pop(L, 1);
+end;
+
+procedure LuaSetTableValue(L: PLua_State; TableIndex: Integer; const Key: string; ValueIndex: Integer);
+begin
+  TableIndex := LuaAbsIndex(L, TableIndex);
+  ValueIndex := LuaAbsIndex(L, ValueIndex);
+  lua_pushstring(L, PChar(Key));
+  lua_pushvalue(L, ValueIndex);
+  lua_settable(L, TableIndex);
+end;
+
+procedure LuaSetTableNil(L: Plua_State; TableIndex: Integer; const Key: string);
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushnil(L);
+  lua_settable(L, TableIndex);
+end;
+
+procedure LuaSetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string; B: Boolean);
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushboolean(L, Integer(B));
+  lua_settable(L, TableIndex);
+end;
+
+procedure LuaSetTableNumber(L: Plua_State; TableIndex: Integer; const Key: string; N: Double); 
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushnumber(L, N);
+  lua_settable(L, TableIndex);
+end;
+
+procedure LuaSetTableString(L: Plua_State; TableIndex: Integer; const Key: string; S: string);
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushstring(L, PChar(S));
+  lua_settable(L, TableIndex);
+end;
+
+procedure LuaSetTableFunction(L: Plua_State; TableIndex: Integer; const Key: string; F: lua_CFunction);
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushcfunction(L, F);
+  lua_settable(L, TableIndex);
+end;
+
+procedure LuaSetTableLightUserData(L: Plua_State; TableIndex: Integer; const Key: string; P: Pointer);
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushlightuserdata(L, P);
+  lua_settable(L, TableIndex);
+end;
+
+procedure LuaSetTableTMethod(L: Plua_State; TableIndex: Integer; const Key: string; M: TMethod);
+begin
+     LuaSetTableLightUserData(L, TableIndex, Key+'_Code', M.Code);
+     LuaSetTableLightUserData(L, TableIndex, Key+'_Data', M.Data);
+end;
+
+procedure LuaSetTableClear(L: Plua_State; TableIndex: Integer);
+begin
+  TableIndex := LuaAbsIndex(L, TableIndex);
+
+  lua_pushnil(L);
+  while (lua_next(L, TableIndex) <> 0) do
+  begin
+    lua_pushnil(L);
+    lua_replace(L, -1 - 1);
+    lua_settable(L, TableIndex);
+    lua_pushnil(L);
+  end;
+end;
+
+procedure LuaRawSetTableValue(L: PLua_State; TableIndex: Integer; const Key: string; ValueIndex: Integer);
+begin
+  TableIndex := LuaAbsIndex(L, TableIndex);
+  ValueIndex := LuaAbsIndex(L, ValueIndex);
+  lua_pushstring(L, PChar(Key));
+  lua_pushvalue(L, ValueIndex);
+  lua_rawset(L, TableIndex);
+end;
+
+procedure LuaRawSetTableNil(L: Plua_State; TableIndex: Integer; const Key: string);
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushnil(L);
+  lua_rawset(L, TableIndex);
+end;
+
+procedure LuaRawSetTableBoolean(L: Plua_State; TableIndex: Integer; const Key: string; B: Boolean); 
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushboolean(L, Integer(B));
+  lua_rawset(L, TableIndex);
+end;
+
+procedure LuaRawSetTableNumber(L: Plua_State; TableIndex: Integer; const Key: string; N: Double); 
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushnumber(L, N);
+  lua_rawset(L, TableIndex);
+end;
+
+procedure LuaRawSetTableString(L: Plua_State; TableIndex: Integer; const Key: string; S: string); 
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushstring(L, PChar(S));
+  lua_rawset(L, TableIndex);
+end;
+
+procedure LuaRawSetTableFunction(L: Plua_State; TableIndex: Integer; const Key: string; F: lua_CFunction);
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushcfunction(L, F);
+  lua_rawset(L, TableIndex);
+end;
+
+procedure LuaRawSetTableLightUserData(L: Plua_State; TableIndex: Integer; const Key: string; P: Pointer);
+begin
+  LuaPushKeyString(L, TableIndex, Key);
+  lua_pushlightuserdata(L, P);
+  lua_rawset(L, TableIndex);
+end;
+
+procedure LuaRawSetTableClear(L: Plua_State; TableIndex: Integer);
+begin
+  TableIndex := LuaAbsIndex(L, TableIndex);
+
+  lua_pushnil(L);
+  while (lua_next(L, TableIndex) <> 0) do
+  begin
+    lua_pushnil(L);
+    lua_replace(L, -1 - 1);
+    lua_rawset(L, TableIndex);
+    lua_pushnil(L);
+  end;
+end;
+
+function LuaGetMetaFunction(L: Plua_State; Index: Integer; Key: string): lua_CFunction;
+// メタ関数の取得
+begin
+  Result := nil;
+  Index := LuaAbsIndex(L, Index);
+  if (lua_getmetatable(L, Index) = 0) then
+    Exit;
+
+  LuaGetTable(L, -1, Key);
+  if (lua_iscfunction(L, -1) <> 0) then
+    Result := lua_tocfunction(L, -1);
+  lua_pop(L, 2);
+end;
+
+procedure LuaSetMetaFunction(L: Plua_State; Index: Integer; Key: string; F: lua_CFunction);
+// メタ関数の設定
+// Key = __add, __sub, __mul, __div, __pow, __unm, __concat,
+//       __eq, __lt, __le, __index, __newindex, __call
+// [メモ]
+// __newindex は 新規代入時しか呼ばれないので注意
+// table をグローバル変数とするとこうなる。
+//
+// a=1  -- (a=nilなので)メタ関数呼び出される
+// a=2  -- メタ関数は呼び出されない
+// a=3  -- メタ関数は呼び出されない
+// a=nil
+// a=4  -- (a=nilなので)メタ関数呼び出される
+//
+// lua 付属の trace-globals では__newindex と __index をセットで上書きして
+// グローバル変数へのアクセスをローカル変数へのアクセスに切り替えてグロー
+// バル変数の実体は常に table[key] = nil を保たせて __newindex イベントを
+// 発生させている。
+begin
+  Index := LuaAbsIndex(L, Index);
+  if (lua_getmetatable(L, Index) = 0) then
+    lua_newtable(L);
+
+  LuaRawSetTableFunction(L, -1, Key, F);
+  lua_setmetatable(L, Index);
+end;
+
+function LuaStackToStr(L: Plua_State; Index: Integer; MaxTable: Integer): string;
+//スタックの内容を文字列に変換
+// nil    : nil
+// Number : FloatToStr
+// Boolean: True/False
+// stirng : "..."
+// Table  : { Key1=Value Key2=Value }
+  function TableToStr(Index: Integer): string;
+  var
+    Key, Value: string;
+    Count: Integer;
+  begin
+    Result := '{ ';
+    Count := 0;
+    lua_pushnil(L);
+    while (lua_next(L, Index) <> 0) do
+    begin
+      Inc(Count);
+      if (Count > MaxTable) then
+      begin
+        Result := Result + '... ';
+        lua_pop(L, 2);
+        Break;
+      end;
+
+      if lua_type(L, -2) = LUA_TNUMBER then
+        Key := '[' + Dequote(LuaStackToStr(L, -2, MaxTable)) + ']'
+      else
+        Key := Dequote(LuaStackToStr(L, -2, MaxTable));
+
+      if (Key = '_G') then
+        Value := LuaGlobalVariableStr
+      else
+        Value := LuaStackToStr(L, -1, MaxTable);
+      if (lua_type(L, -1) = LUA_TFUNCTION) then
+        Result := Result + Format('%s()=%p ', [Key, lua_topointer(L, -1)])
+      else
+        Result := Result + Format('%s=%s ', [Key, Value]);
+      // Key は次のために残す
+      lua_pop(L, 1);
+    end;
+    Result := Result + '}';
+  end;
+var
+  Size: Integer;
+begin
+  if (MaxTable < 0) then
+    MaxTable := DefaultMaxTable;
+
+  Index := LuaAbsIndex(L, Index);
+
+  case (lua_type(L, Index)) of
+  LUA_TNIL:
+    Result := 'nil';
+  LUA_TNUMBER:
+    Result := Format('%g', [lua_tonumber(L, Index)]);
+  LUA_TBOOLEAN:
+    Result := BoolToStr(lua_toboolean(L, Index) <> 0, True);
+  LUA_TSTRING:
+  begin
+    Size := lua_strlen(L, Index);
+    SetLength(Result, Size);
+    if (Size > 0) then
+      Move(lua_tostring(L, Index)^, Result[1], Size);
+    Result := Quote(Result);
+  end;
+  LUA_TTABLE:
+    Result := TableToStr(Index);
+  LUA_TFUNCTION:
+    if (lua_iscfunction(L, Index) <> 0) then
+      Result := Format('CFUNC:%p', [Pointer(lua_tocfunction(L, Index))])
+    else
+      Result := Format('FUNC:%p', [lua_topointer(L, Index)]);
+  LUA_TUSERDATA:
+    Result := Format('USERDATA:%p', [lua_touserdata(L, Index)]);
+  LUA_TTHREAD:
+    Result := Format('THREAD:%p', [lua_tothread(L, Index)]);
+  LUA_TLIGHTUSERDATA:
+    Result := Format('LIGHTUSERDATA:%p', [lua_touserdata(L, Index)]);
+  else
+    Assert(False);
+  end;
+end;
+
+procedure LuaShowStack(L: Plua_State; Caption: string);
+var
+  I, N: Integer;
+  S: string;
+begin
+  N := lua_gettop(L);
+  S := '[' + Caption + ']';
+  for I := N downto 1 do
+  begin
+    S := S + CRLF + Format('%3d,%3d:%s', [LuaAbsIndex(L, I), LuaIncIndex(L, I),
+      LuaStackToStr(L, I, -1)]);
+  end;
+  ShowMessage(S);
+end;
+
+procedure LuaProcessTableName(L: Plua_State; const Name: PChar;
+  var LastName: string; var TableIndex, Count: Integer);
+// Name のテーブル要素をスタックに積んで、
+// スタックに積んだ数と Name の最終要素の名前とその親テーブルのインデックスを返す
+// テーブルが無い場合は作成する
+// LuaProcessTableName(L, 'print', S, TI, Count) → S = print, TI = LUA_GLOBALSINDEX, Count = 0
+// LuaProcessTableName(L, 'io.write', S, TI, Count) → S = write, TI -> io, Count = 1
+// LuaProcessTableName(L, 'a.b.c.func', S, TI, Count) → S = func, TI -> a.b.c, Count = 3
+
+var
+  S: string;
+
+
+  function GetToken: string;
+  var
+    Index: Integer;
+  begin
+    Index := Pos('.', S);
+    if (Index = 0) then
+    begin
+      Result := S;
+      S := '';
+      Exit;
+    end;
+    Result := Copy(S, 1, Index - 1);
+    S := Copy(S, Index + 1, Length(S));
+  end;
+
+
+begin
+  S := Name;
+  Count := 0;
+
+  LastName := GetToken;
+  while (S <> '') do
+  begin
+    Inc(Count);
+    TableIndex := LuaAbsIndex(L, TableIndex);
+    LuaGetTable(L, TableIndex, LastName);
+    if (lua_type(L, -1) <> LUA_TTABLE) then
+    begin
+      lua_pop(L, 1);
+      lua_pushstring(L, PChar(LastName));
+      lua_newtable(L);
+      lua_rawset(L, TableIndex);
+      LuaGetTable(L, TableIndex, LastName);
+    end;
+    TableIndex := -1;
+    LastName := GetToken;
+  end;
+end;
+
+procedure LuaRegisterCustom(L: PLua_State; TableIndex: Integer; const Name: PChar; F: lua_CFunction);
+var
+  Count: Integer;
+  S: string;
+begin
+  LuaProcessTableName(L, Name, S, TableIndex, Count);
+  LuaRawSetTableFunction(L, TableIndex, S, F);
+  lua_pop(L, Count);
+end;
+
+procedure LuaRegister(L: Plua_State; const Name: PChar; F: lua_CFunction);
+// 関数の登録
+// LuaRegister(L, 'print', lua_print);
+// LuaRegister(L, 'io.write', lua_io_write);  // テーブル io が無い場合は作成
+// LuaRegister(L, 'a.b.c.func', a_b_c_func);  // テーブル a.b.c が無い場合は作成
+begin
+  LuaRegisterCustom(L, LUA_GLOBALSINDEX, Name, F);
+end;
+
+procedure LuaRegisterMetatable(L: Plua_State; const Name: PChar; F: lua_CFunction);
+begin
+  LuaRegisterCustom(L, LUA_REGISTRYINDEX, Name, F);
+end;
+
+procedure LuaRegisterProperty(L: PLua_State; const Name: PChar; ReadFunc, WriteFunc: lua_CFunction);
+var
+  Count: Integer;
+  TI: Integer;
+  S: string;
+begin
+  TI := LUA_GLOBALSINDEX;
+  LuaProcessTableName(L, Name, S, TI, Count);
+  TI := LuaAbsIndex(L, TI);
+
+  LuaGetTable(L, TI, S);
+  if (lua_type(L, -1) <> LUA_TTABLE) then
+  begin
+    lua_pop(L, 1);
+    lua_pushstring(L, PChar(S));
+    lua_newtable(L);
+    lua_settable(L, TI);
+    LuaGetTable(L, TI, S);
+  end;
+  if (Assigned(ReadFunc)) then
+    LuaSetMetaFunction(L, -1, '__index', ReadFunc);
+  if (Assigned(WriteFunc)) then
+    LuaSetMetaFunction(L, -1, '__newindex', WriteFunc);
+  lua_pop(L, Count + 1);
+end;
+
+procedure LuaStackToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer);
+var
+  I: Integer;
+begin
+  Lines.Clear;
+  for I := lua_gettop(L) downto 1 do
+    Lines.Add(LuaStackToStr(L, I, MaxTable));
+end;
+
+procedure LuaLocalToStrings(L: Plua_State; Lines: TStrings; MaxTable: Integer; Level: Integer);
+var
+  Name: PChar;
+  Index: Integer;
+  Debug: lua_Debug;
+  AR: Plua_Debug;
+begin
+  AR := @Debug;
+  Lines.Clear;
+  Index := 1;
+  if (lua_getstack(L, Level, AR) = 0) then
+    Exit;
+
+  Name := lua_getlocal(L, AR, Index);
+  while (Name <> nil) do
+  begin
+    Lines.Values[Name] := LuaStackToStr(L, -1, MaxTable);
+    lua_pop(L, 1);
+    Inc(Index);
+    Name := lua_getlocal(L, AR, Index);
+  end;
+end;
+
+procedure LuaTableToStrings(L: Plua_State; Index: Integer; Lines: TStrings; MaxTable: Integer);
+var
+  Key, Value: string;
+begin
+  Index := LuaAbsIndex(L, Index);
+  Lines.Clear;
+
+  lua_pushnil(L);
+  while (lua_next(L, Index) <> 0) do
+  begin
+    Key := Dequote(LuaStackToStr(L, -2, MaxTable));
+    Value := LuaStackToStr(L, -1, MaxTable);
+    Lines.Values[Key] := Value;
+    lua_pop(L, 1);
+  end;
+end;
+
+procedure LuaTableToVirtualTreeView(L: Plua_State; Index: Integer; VTV: TVirtualStringTree; MaxTable: Integer);
+  // Go through all child of current table and create nodes
+  procedure ParseTreeNode(TreeNode: PVirtualNode; Index: Integer);
+  var
+    Key: string;
+    pData: PBasicTreeData;
+    pNode: PVirtualNode;
+  begin
+    // Retreive absolute index 
+    Index := LuaAbsIndex(L, Index);
+    
+    // Get the root node if current node is not assigned
+    //if not Assigned(TreeNode) then
+      //TreeNode := VTV.RootNode;
+
+    lua_pushnil(L);
+    while (lua_next(L, Index) <> 0) do
+    begin
+      Key := Dequote(LuaStackToStr(L, -2, MaxTable));
+      if (lua_type(L, -1) <> LUA_TTABLE) then
+      begin
+        pData := VTV.GetNodeData(VTV.AddChild(TreeNode));
+        pData.sName := Key;
+        pData.sValue := LuaStackToStr(L, -1, MaxTable);
+      end
+      else
+      begin
+        if (Key = '_G') then
+        begin
+          pData := VTV.GetNodeData(VTV.AddChild(TreeNode));
+          pData.sName := Key;
+          pData.sValue := '[LUA_GLOBALSINDEX]';
+        end
+        else
+        begin
+          pNode := VTV.AddChild(TreeNode);
+          pData := VTV.GetNodeData(pNode);
+          pData.sName := Key;
+          pData.sValue := '';
+          ParseTreeNode(pNode, -1);
+        end;
+      end;
+      lua_pop(L, 1);
+    end;
+  end;
+begin
+  Assert(lua_type(L, Index) = LUA_TTABLE);
+  VTV.BeginUpdate;
+  VTV.Clear;
+  try
+    ParseTreeNode(nil, Index);
+  finally
+    VTV.EndUpdate;
+  end;
+end;
+
+procedure LuaTableToTreeView(L: Plua_State; Index: Integer; TV: TTreeView; MaxTable: Integer);
+  // Go through all child of current table and create nodes
+  procedure ParseTreeNode(TreeNode: TTreeNode; Index: Integer);
+  var
+    Key: string;
+  begin
+    Index := LuaAbsIndex(L, Index);
+
+    lua_pushnil(L);
+    while (lua_next(L, Index) <> 0) do
+    begin
+      Key := Dequote(LuaStackToStr(L, -2, MaxTable));
+      if (lua_type(L, -1) <> LUA_TTABLE) then
+        TV.Items.AddChild(TreeNode, Key + '=' + LuaStackToStr(L, -1, MaxTable))
+      else
+      begin
+        if (Key = '_G') then
+          TV.Items.AddChild(TreeNode, Key + '=[LUA_GLOBALSINDEX]')
+        else
+          ParseTreeNode(TV.Items.AddChild(TreeNode, Key), -1);
+      end;
+      lua_pop(L, 1);
+    end;
+  end;
+begin
+  Assert(lua_type(L, Index) = LUA_TTABLE);
+  TV.Items.BeginUpdate;
+  TV.Items.Clear;
+  try
+    ParseTreeNode(nil, Index);
+  finally
+    TV.Items.EndUpdate;
+  end;
+end;
+
+function LuaGetIdentValue(L: Plua_State; Ident: string; MaxTable: Integer): string;
+const
+  DebugValue = '___DEBUG_VALUE___';
+var
+  Local: TStrings;
+  Code: string;
+  Hook: lua_Hook;
+  Mask: Integer;
+  Count: Integer;
+begin
+  if (Ident = '') then
+  begin
+    Result := '';
+    Exit;
+  end;
+
+  Local := TStringList.Create;
+  try
+    LuaLocalToStrings(L, Local, MaxTable);
+    Result := Local.Values[Ident];
+    if (Result <> '') then
+      Exit;
+  finally
+    Local.Free;
+  end;
+
+  Code := DebugValue + '=' + Ident;
+  luaL_loadbuffer(L, PChar(Code), Length(Code), 'debug');
+  Hook := lua_gethook(L);
+  Mask := lua_gethookmask(L);
+  Count := lua_gethookcount(L);
+  lua_sethook(L, Hook, 0, Count);
+  if (lua_pcall(L, 0, 0, 0) = 0) then
+    LuaRawGetTable(L, LUA_GLOBALSINDEX, DebugValue);
+  Result := LuaStackToStr(L, -1, MaxTable);
+  lua_remove(L, -1);
+  lua_dostring(L, DebugValue + '=nil');
+  lua_sethook(L, Hook, Mask, Count);
+end;
+
+procedure LuaSetIdentValue(L: Plua_State; Ident, Value: string; MaxTable: Integer);
+var
+  Local: TStrings;
+  Code: string;
+  Index: Integer;
+  Debug: lua_Debug;
+  AR: Plua_Debug;
+begin
+  Local := TStringList.Create;
+  try
+    AR := @Debug;
+    LuaLocalToStrings(L, Local, MaxTable);
+    Index := Local.IndexOf(Ident);
+    if (Index >= 0) then
+    begin
+      try
+        lua_pushnumber(L, StrToFloat(Value));
+      except
+        lua_pushstring(L, PChar(Dequote(Value)));
+      end;
+      lua_getstack(L, 0, AR);
+      lua_getinfo(L, 'Snlu', AR);
+      lua_setlocal(L, AR, Index + 1);
+    end else
+    begin
+      Code := Ident + '=' + Value;
+      luaL_loadbuffer(L, PChar(Code), Length(Code), 'debug');
+      if (lua_pcall(L, 0, 0, 0) <> 0) then
+        lua_remove(L, -1);
+    end;
+  finally
+    Local.Free;
+  end;
+end;
+
+procedure LuaProcessErrorMessage(const ErrMsg: string; var Title: string; var Line: Integer; var Msg: string);
+const
+  Term = #$00;
+  function S(Index: Integer): Char;
+  begin
+    if (Index <= Length(ErrMsg)) then
+      Result := ErrMsg[Index]
+    else
+      Result := Term;
+  end;
+  function IsDigit(C: Char): Boolean;
+  begin
+    Result := ('0' <= C) and (C <= '9');
+  end;
+  function PP(var Index: Integer): Integer;
+  begin
+    Inc(Index);
+    Result := Index;
+  end;
+var
+  I, Start, Stop: Integer;
+  LS: string;
+  Find: Boolean;
+begin
+  // ErrMsg = Title:Line:Message
+  Title := '';
+  Line := 0;
+  Msg := ErrMsg;
+  Find := False;
+  I := 1 - 1;
+  Stop := 0;
+  // :数値: を探す
+  repeat
+    while (S(PP(I)) <> ':') do
+      if (S(I) = Term) then
+        Exit;
+    Start := I;
+    if (not IsDigit(S(PP(I)))) then
+      Continue;
+    while (IsDigit(S(PP(I)))) do
+      if (S(I - 1) = Term) then
+        Exit;
+    Stop := I;
+    if (S(I) = ':') then
+      Find := True;
+  until (Find);
+  Title := Copy(ErrMsg, 1, Start - 1);
+  LS := Copy(ErrMsg, Start + 1, Stop - Start - 1);
+  Line := StrToIntDef(LS, 0);
+  Msg := Copy(ErrMsg, Stop + 1, Length(ErrMsg));
+end;
+
+procedure LuaLoadBuffer(L: Plua_State; const Code: string; const Name: string);
+var
+  Title, Msg: string;
+  Line: Integer;
+begin
+  if (luaL_loadbuffer(L, PChar(Code), Length(Code), PChar(Name)) = 0) then
+    Exit;
+
+  LuaProcessErrorMessage(Dequote(LuaStackToStr(L, -1, -1)),
+    Title, Line, Msg);
+  raise ELuaException.Create(Title, Line, Msg);
+end;
+
+procedure LuaLoadBufferFromFile(L: Plua_State; const Filename: string; const Name: string);
+Var
+   xCode :String;
+   xFile :TStringList;
+
+begin
+     xFile := TStringList.Create;
+     xFile.LoadFromFile(FileName);
+     xCode := xFile.Text;
+     xFile.Free;
+     LuaLoadBuffer(L, xCode, Name);
+end;
+
+procedure LuaPCall(L: Plua_State; NArgs, NResults, ErrFunc: Integer);
+var
+  Title, Msg: string;
+  Line: Integer;
+begin
+  if (lua_pcall(L, NArgs, NResults, ErrFunc) = 0) then
+    Exit;
+
+  LuaProcessErrorMessage(Dequote(LuaStackToStr(L, -1, -1)),
+    Title, Line, Msg);
+  raise ELuaException.Create(Title, Line, Msg);
+end;
+
+function LuaPCallFunction(L: Plua_State; FunctionName :String;
+                          const Args: array of Variant;
+                          Results : PVariantArray;
+                          ErrFunc: Integer=0;
+                          NResults :Integer=LUA_MULTRET):Integer;
+var
+   NArgs,
+   i        :Integer;
+
+begin
+     //Put Function To Call on the Stack
+     luaPushString(L, FunctionName);
+     lua_gettable(L, LUA_GLOBALSINDEX);
+
+     //Put Parameters on the Stack
+     NArgs := High(Args)+1;
+     for i:=0 to (NArgs-1) do
+       LuaPushVariant(L, Args[i]);
+
+     //Call the Function
+     LuaPcall(L, NArgs, NResults, ErrFunc);
+     Result :=lua_gettop(L);   //Get Number of Results
+
+     if (Results<>Nil)
+     then begin 
+               //Get Results in the right order
+               SetLength(Results^, Result);
+               for i:=0 to Result-1 do
+               begin
+                    Results^[Result-(i+1)] :=LuaToVariant(L, -(i+1));
+               end;
+          end;
+end;
+
+procedure LuaError(L: Plua_State; const Msg: string);
+begin
+  luaL_error(L, PChar(Msg));
+end;
+
+procedure LuaErrorFmt(L: Plua_State; const Fmt: string; const Args: array of Const);
+begin
+  LuaError(L, Format(Fmt, Args));
+end;
+
+{ ELuaException }
+
+constructor ELuaException.Create(Title: string; Line: Integer;
+  Msg: string);
+var
+  LS: string;
+begin
+  if (Line > 0) then
+    LS := Format('(%d)', [Line])
+  else
+    LS := '';
+  inherited Create(Title + LS + Msg);
+  Self.Title := Title;
+  Self.Line := Line;
+  Self.Msg := Msg;
+end;
+
+function LuaDataStrToStrings(const TableStr: string; Strings: TStrings): string;
+(*
+  LuaStackToStr 形式から Strings.Values[Name] 構造へ変換
+  TableStr
+  { Name = "Lua" Version = 5.0 }
+  ↓
+  Strings
+  Name="Lua"
+  Version=5.0
+
+  DataList  : Data DataList
+            |
+
+  Data      : Table
+            | {グローバル変数}
+            | Ident ( )
+            | Ident = Value
+            | Ident
+            |
+
+  Table     : { DataList }
+            |
+
+  Value     : "..."
+            | Data
+
+*)
+const
+  EOF = #$00;
+var
+  Index: Integer;
+  Text: string;
+  Token: Char;
+  function S(Index: Integer): Char;
+  begin
+    if (Index <= Length(TableStr)) then
+      Result := TableStr[Index]
+    else
+      Result := EOF;
+  end;
+  function GetString: string;
+  var
+    SI: Integer;
+  begin
+    Dec(Index);
+    Result := '';
+    repeat
+      Assert(S(Index) = '"');
+      SI := Index;
+      Inc(Index);
+      while (S(Index) <> '"') do
+        Inc(Index);
+      Result := Result + Copy(TableStr, SI, Index - SI + 1);
+      Inc(Index);
+    until (S(Index) <> '"');
+  end;
+  function GetValue: string;
+    function IsIdent(C: Char): Boolean;
+    const
+      S = ' =(){}' + CR + LF;
+    begin
+      Result := (Pos(C, S) = 0);
+    end;
+  var
+    SI: Integer;
+  begin
+    Dec(Index);
+    SI := Index;
+    while (IsIdent(S(Index))) do
+      Inc(Index);
+    Result := Copy(TableStr, SI, Index - SI);
+  end;
+  function GetToken: Char;
+    function SkipSpace(var Index: Integer): Integer;
+    const
+      TAB = #$09;
+      CR = #$0D;
+      LF = #$0A;
+    begin
+      while (S(Index) in [' ', TAB, CR, LF]) do
+        Inc(Index);
+      Result := Index;
+    end;
+  begin
+    SkipSpace(Index);
+    Token := S(Index);
+    Inc(Index);
+    Text := Token;
+    case (Token) of
+    EOF: ;
+    '"': Text := GetString;
+    '{':
+      if (Copy(TableStr, Index - 1, Length(LuaGlobalVariableStr)) = LuaGlobalVariableStr) then
+      begin
+        Token := 'G';
+        Text := LuaGlobalVariableStr;
+        Inc(Index, Length(LuaGlobalVariableStr) - 1);
+      end;
+    '}': ;
+    '(': ;
+    ')': ;
+    '=': ;
+    else Text := GetValue
+    end;
+    Result := Token;
+  end;
+  procedure Check(S: string);
+  begin
+    if (Pos(Token, S) = -1) then
+      raise Exception.CreateFmt('Error %s is required :%s', [Copy(TableStr, Index - 1, Length(TableStr))]);
+  end;
+  function CheckGetToken(S: string): Char;
+  begin
+    Result := GetToken;
+    Check(S);
+  end;
+  function ParseData: string; forward;
+  function ParseTable: string; forward;
+  function ParseValue: string; forward;
+  function ParseDataList: string;
+  begin
+    with (TStringList.Create) do
+    try
+      while not (Token in [EOF, '}']) do
+        Add(ParseData);
+      Result := Text;
+    finally
+      Free;
+    end;
+  end;
+  function ParseData: string;
+  begin
+    if (Token = EOF) then
+    begin
+      Result := '';
+      Exit;
+    end;
+
+    case (Token) of
+    '{': Result := ParseTable;
+    'G':
+      begin
+        Result := Text;
+        GetToken;
+      end;
+    else
+      begin
+        Result := Text;
+        case (GetToken) of
+        '(':
+          begin
+            CheckGetToken(')');
+            Result := Format('%s=()', [Result]);
+            GetToken;
+          end;
+        '=':
+          begin
+            GetToken;
+            Result := Format('%s=%s', [Result, ParseValue]);
+          end;
+        end;
+      end;
+    end;
+  end;
+  function ParseTable: string;
+  begin
+    if (Token in [EOF]) then
+    begin
+      Result := '';
+      Exit;
+    end;
+    Check('{');
+    GetToken;
+    with (TStringList.Create) do
+    try
+      Text := ParseDataList;
+      Result := CommaText;
+    finally
+      Free;
+    end;
+    Check('}');
+    GetToken;
+  end;
+  function ParseValue: string;
+  begin
+    if (Token = EOF) then
+    begin
+      Result := '';
+      Exit;
+    end;
+
+    case (Token) of
+    '"':
+      begin
+        Result := Text;
+        GetToken;
+      end;
+    else
+      Result := ParseData;
+    end;
+  end;
+begin
+  Index := 1;
+  GetToken;
+  Strings.Text := ParseDataList;
+end;           
+
+function LuaDoFile(L: Plua_State): Integer; cdecl;
+// dofile 引数(arg)戻り値付き
+// Lua: DoFile(FileName, Args...)
+const
+  ArgIdent = 'arg';
+var
+  FileName: PChar;
+  I, N, R: Integer;
+  ArgTable, ArgBackup: Integer;
+begin
+  N := lua_gettop(L);
+
+  // arg, result の保存
+  lua_getglobal(L, ArgIdent);
+  ArgBackup := lua_gettop(L);
+
+  FileName := luaL_checkstring(L, 1);
+  lua_newtable(L);
+  ArgTable := lua_gettop(L);
+  for I := 2 to N do
+  begin
+    lua_pushvalue(L, I);
+    lua_rawseti(L, ArgTable, I - 1);
+  end;
+  lua_setglobal(L, ArgIdent);
+
+  Result := lua_gettop(L);
+  luaL_loadfile(L, PChar(FileName));
+  R := lua_pcall(L, 0, LUA_MULTRET, 0);
+  Result := lua_gettop(L) - Result;
+
+  LuaRawSetTableValue(L, LUA_GLOBALSINDEX, ArgIdent, ArgBackup);
+  lua_remove(L, ArgBackup);
+
+  if (R <> 0) then
+    lua_error(L);
+end;
+
+initialization
+  DefaultMaxTable := 256;
+
+end.

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lauxlib.dcu


+ 284 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lauxlib.pas

@@ -0,0 +1,284 @@
+(*
+** $Id: lauxlib.pas,v 1.1 2005-11-26 15:19:46 jfgoulet Exp $
+** Auxiliary functions for building Lua libraries
+** See Copyright Notice in lua.h
+*)
+unit lauxlib;
+
+{$IFNDEF lauxlib_h}
+{$DEFINE lauxlib_h}
+{$ENDIF}
+
+interface
+
+uses
+  lua;
+
+
+type
+  luaL_reg = record
+    name: PChar;
+    func: lua_CFunction;
+  end;
+  PluaL_reg = ^luaL_reg;
+
+procedure luaL_openlib(L: Plua_State; libname: PChar;
+                               R: PluaL_reg; Nup: Integer);
+  cdecl external 'lua.dll';
+function luaL_getmetafield(L: Plua_State; Obj: Integer; const E: PChar): Integer;
+  cdecl external 'lua.dll';
+function luaL_callmeta(L: Plua_State; Obj: Integer; const E: PChar): Integer;
+  cdecl external 'lua.dll';
+function luaL_typerror(L: Plua_State; NArg: Integer; const TName: PChar): Integer;
+  cdecl external 'lua.dll';
+function luaL_argerror(L: Plua_State; NumArg: Integer; const ExtraMsg: PChar): Integer;
+  cdecl external 'lua.dll';
+function luaL_checklstring(L: Plua_State; NumArg: Integer; S: Psize_t): PChar;
+  cdecl external 'lua.dll';
+function luaL_optlstring(L: Plua_State; NumArg: Integer;
+                                           const Def: PChar; S: Psize_t): PChar;
+  cdecl external 'lua.dll';
+function luaL_checknumber(L: Plua_State; NumArg: Integer): lua_Number;
+  cdecl external 'lua.dll';
+function luaL_optnumber(L: Plua_State; NArg: Integer; Def: Lua_Number): lua_Number;
+  cdecl external 'lua.dll';
+
+procedure luaL_checkstack(L: Plua_State; SZ: Integer; const Msg: PChar);
+  cdecl external 'lua.dll';
+procedure luaL_checktype(L: Plua_State; NArg: Integer; T: Integer);
+  cdecl external 'lua.dll';
+procedure luaL_checkany(L: Plua_State; NArg: Integer);
+  cdecl external 'lua.dll';
+
+function   luaL_newmetatable(L: Plua_State; const TName: PChar): Integer;
+  cdecl external 'lua.dll';
+procedure  luaL_getmetatable(L: Plua_State; const TName: PChar);
+  cdecl external 'lua.dll';
+function luaL_checkudata(L: Plua_State; UD: Integer; const TName: PChar): Pointer;
+  cdecl external 'lua.dll';
+
+procedure luaL_where(L: Plua_State; LVL: Integer);
+  cdecl external 'lua.dll';
+function luaL_error(L: Plua_State; const Fmt: PChar): Integer; varargs;
+  cdecl external 'lua.dll';
+
+function luaL_findstring(const ST: PChar; lst: array of PChar): Integer;
+  cdecl external 'lua.dll';
+
+function luaL_ref(L: Plua_State; T: Integer): Integer;
+  cdecl external 'lua.dll';
+procedure luaL_unref(L: Plua_State; T: Integer; Ref: Integer);
+  cdecl external 'lua.dll';
+
+function luaL_getn(L: Plua_State; T: Integer): Integer;
+  cdecl external 'lua.dll';
+procedure luaL_setn(L: Plua_State; T: Integer; N: Integer);
+  cdecl external 'lua.dll';
+
+function luaL_loadfile(L: Plua_State; const FileName: PChar): Integer;
+  cdecl external 'lua.dll';
+function luaL_loadbuffer(L: Plua_State; const Buff: PChar; SZ: size_t;
+                                const Name: PChar): Integer;
+  cdecl external 'lua.dll';
+
+
+
+(*
+** ===============================================================
+** some useful macros
+** ===============================================================
+*)
+
+function luaL_argcheck(L: Plua_State; Cond: Boolean; NumArg: Integer; const ExtraMsg: PChar): Integer;
+function luaL_checkstring(L: Plua_State; N: Integer): PChar;
+function luaL_optstring(L: Plua_State; N: Integer; const D: PChar): PChar;
+function luaL_checkint(L: Plua_State; N: Integer): Integer;
+function luaL_checklong(L: Plua_State; N: Integer): Integer;
+function luaL_optint(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+function luaL_optlong(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+
+(*
+** {======================================================
+** Generic Buffer manipulation
+** =======================================================
+*)
+
+
+{$IFNDEF BUFSIZ}
+const
+  BUFSIZ = 1024;
+{$ENDIF}
+
+{$IFNDEF LUAL_BUFFERSIZE}
+const
+  LUAL_BUFFERSIZE = BUFSIZ;
+{$ENDIF}
+
+type
+  luaL_Buffer = record
+    P: PChar;    (* current position in buffer *)
+    lvl: Integer; (* number of strings in the stack(level) *)
+    L: Plua_State;
+    buffer: array [0..LUAL_BUFFERSIZE - 1] of Char;
+  end;
+  PluaL_Buffer = ^luaL_Buffer;
+
+procedure luaL_putchar(B: PluaL_Buffer; C: Char);
+
+function luaL_addsize(B: PLuaL_Buffer; N: Integer): PChar;
+
+procedure luaL_buffinit(L: Plua_State; B: PluaL_Buffer);
+  cdecl external 'lua.dll';
+function luaL_prepbuffer(B: PluaL_Buffer): PChar;
+  cdecl external 'lua.dll';
+procedure luaL_addlstring(B: PluaL_Buffer; const S: PChar; L: size_t);
+  cdecl external 'lua.dll';
+procedure luaL_addstring(B: PluaL_Buffer; const S: PChar);
+  cdecl external 'lua.dll';
+procedure luaL_addvalue(B: PluaL_Buffer);
+  cdecl external 'lua.dll';
+procedure luaL_pushresult(B: PluaL_Buffer);
+  cdecl external 'lua.dll';
+
+
+(* }====================================================== *)
+
+
+
+(*
+** Compatibility macros and functions
+*)
+
+function lua_dofile(L: Plua_State; const FileName: PChar): Integer;
+  cdecl external 'lua.dll';
+function lua_dostring(L: Plua_State; const Str: PChar): Integer;
+  cdecl external 'lua.dll';
+function lua_dobuffer(L: Plua_State; const Buff: PChar; SZ: size_t;
+                               const N: PChar): Integer;
+  cdecl external 'lua.dll';
+
+function luaL_check_lstr(L: Plua_State; NumArg: Integer; S: Psize_t): PChar;
+function luaL_opt_lstr(L: Plua_State; NumArg: Integer;
+                                           const Def: PChar; S: Psize_t): PChar;
+function luaL_check_number(L: Plua_State; NumArg: Integer): lua_Number;
+function luaL_opt_number(L: Plua_State; NArg: Integer; Def: Lua_Number): lua_Number;
+procedure luaL_arg_check(L: Plua_State; Cond: Boolean; NumArg: Integer; const ExtraMsg: PChar);
+function luaL_check_string(L: Plua_State; N: Integer): PChar;
+function luaL_opt_string(L: Plua_State; N: Integer; const D: PChar): PChar;
+function luaL_check_int(L: Plua_State; N: Integer): Integer;
+function luaL_check_long(L: Plua_State; N: Integer): Integer;
+function luaL_opt_int(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+function luaL_opt_long(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+
+implementation
+
+function luaL_argcheck(L: Plua_State; Cond: Boolean; NumArg: Integer; const ExtraMsg: PChar): Integer;
+begin
+ Result := 0;
+ if(not Cond) then
+   Result := luaL_argerror(L, NumArg, ExtraMsg)
+end;
+
+function luaL_checkstring(L: Plua_State; N: Integer): PChar;
+begin
+  Result := luaL_checklstring(L, N, nil);
+end;
+
+function luaL_optstring(L: Plua_State; N: Integer; const D: PChar): PChar;
+begin
+  Result := luaL_optlstring(L, N, D, nil);
+end;
+
+function luaL_checkint(L: Plua_State; N: Integer): Integer;
+begin
+  Result := Trunc(luaL_checknumber(L, N));
+end;
+
+function luaL_checklong(L: Plua_State; N: Integer): Integer;
+begin
+  Result := Trunc(luaL_checknumber(L, N));
+end;
+
+function luaL_optint(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+begin
+  Result := Trunc(luaL_optnumber(L, N, D));
+end;
+
+function luaL_optlong(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+begin
+  Result := Trunc(luaL_optnumber(L, N, D));
+end;
+
+procedure luaL_putchar(B: PluaL_Buffer; C: Char);
+begin
+  if ((B.P <= @B.Buffer[High(B.Buffer)]) or (luaL_prepbuffer(B) <> #0)) then
+  begin
+    B.P^ := C;
+    Inc(B.P);
+  end;
+end;
+
+function luaL_addsize(B: PLuaL_Buffer; N: Integer): PChar;
+begin
+  Inc(B.P, N);
+  Result := B.P;
+end;
+
+
+function luaL_check_lstr(L: Plua_State; NumArg: Integer; S: Psize_t): PChar;
+begin
+  Result := luaL_checklstring(L, NumArg, S);
+end;
+
+function luaL_opt_lstr(L: Plua_State; NumArg: Integer;
+                                           const Def: PChar; S: Psize_t): PChar;
+begin
+  Result := luaL_optlstring(L, NumArg, Def, S);
+end;
+
+function luaL_check_number(L: Plua_State; NumArg: Integer): lua_Number;
+begin
+  Result := luaL_checknumber(L, NumArg);
+end;
+
+function luaL_opt_number(L: Plua_State; NArg: Integer; Def: Lua_Number): lua_Number;
+begin
+  Result := luaL_optnumber(L, NArg, Def);
+end;
+
+procedure luaL_arg_check(L: Plua_State; Cond: Boolean; NumArg: Integer; const ExtraMsg: PChar);
+begin
+  luaL_argcheck(L, Cond, NumArg, ExtraMsg);
+end;
+
+function luaL_check_string(L: Plua_State; N: Integer): PChar;
+begin
+  Result := luaL_checkstring(L, N);
+end;
+
+function luaL_opt_string(L: Plua_State; N: Integer; const D: PChar): PChar;
+begin
+  Result := luaL_optstring(L, N, D);
+end;
+
+function luaL_check_int(L: Plua_State; N: Integer): Integer;
+begin
+  Result := luaL_checkint(L, N);
+end;
+
+function luaL_check_long(L: Plua_State; N: Integer): Integer;
+begin
+  Result := luaL_checklong(L, N);
+end;
+
+function luaL_opt_int(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+begin
+  Result := luaL_optint(L, N, D);
+end;
+
+function luaL_opt_long(L: Plua_State; N: Integer; D: Lua_Number): Integer;
+begin
+  Result := luaL_optlong(L, N, D);
+end;
+
+end.

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lua.dcu


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lua.dll


+ 571 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lua.pas

@@ -0,0 +1,571 @@
+(*
+** $Id: lua.pas,v 1.1 2005-11-26 15:19:46 jfgoulet Exp $
+** Lua - An Extensible Extension Language
+** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
+** http://www.lua.org	mailto:[email protected]
+** See Copyright Notice at the end of this file
+*)
+unit lua;
+
+{$IFNDEF lua_h}
+{$DEFINE lua_h}
+{$ENDIF}
+
+interface
+
+const
+ CONST_LUA_VERSION = 'Lua 5.0';
+ CONST_LUA_COPYRIGHT = 'Copyright (C) 1994-2003 Tecgraf, PUC-Rio';
+ CONST_LUA_AUTHORS = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';
+
+(* option for multiple returns in `lua_pcall' and `lua_call' *)
+ LUA_MULTRET = (-1);
+
+
+(*
+** pseudo-indices
+*)
+  LUA_REGISTRYINDEX = (-10000);
+  LUA_GLOBALSINDEX = (-10001);
+
+  function lua_upvalueindex(I: Integer): Integer;
+
+const
+
+(* error codes for `lua_load' and `lua_pcall' *)
+  LUA_ERRRUN = 1;
+  LUA_ERRFILE = 2;
+  LUA_ERRSYNTAX = 3;
+  LUA_ERRMEM = 4;
+  LUA_ERRERR = 5;
+
+
+type
+  lua_State = record
+  end;
+  Plua_State = ^lua_State;
+
+  lua_CFunction = function (L: Plua_State): Integer; cdecl;
+  size_t = Integer;
+  Psize_t = ^size_t;
+
+(*
+** functions that read/write blocks when loading/dumping Lua chunks
+*)
+  lua_Chunkreader = function (L: Plua_State; UD: Pointer; var SZ: size_t): PChar;
+  lua_Chunkwriter = function (L: Plua_State; const P: Pointer; SZ: size_t; UD: Pointer): Integer;
+
+const
+(*
+** basic types
+*)
+  LUA_TNONE = (-1);
+
+  LUA_TNIL = 0;
+  LUA_TBOOLEAN = 1;
+  LUA_TLIGHTUSERDATA = 2;
+  LUA_TNUMBER = 3;
+  LUA_TSTRING = 4;
+  LUA_TTABLE = 5;
+  LUA_TFUNCTION = 6;
+  LUA_TUSERDATA = 7;
+  LUA_TTHREAD = 8;
+
+
+(* minimum Lua stack available to a C function *)
+  LUA_MINSTACK = 20;
+
+
+(*
+** generic extra include file
+*)
+{$IFDEF LUA_USER_H}
+{$INCLUDE} LUA_USER_H
+{$ENDIF}
+
+
+(* type of numbers in Lua *)
+type
+{$IFNDEF LUA_NUMBER}
+  lua_Number = Double;
+{$ELSE}
+  lua_Number = LUA_NUMBER;
+{$ENDIF}
+
+
+(* mark for all API functions *)
+
+
+(*
+** state manipulation
+*)
+function lua_open: Plua_State;
+  cdecl external 'lua.dll';
+procedure lua_close(L: Plua_State);
+  cdecl external 'lua.dll';
+function lua_newthread(L: Plua_State): Plua_State;
+  cdecl external 'lua.dll';
+
+function lua_atpanic(L: Plua_State; Panicf: lua_CFunction): lua_CFunction;
+  cdecl external 'lua.dll';
+
+
+(*
+** basic stack manipulation
+*)
+function lua_gettop(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+procedure lua_settop(L: Plua_State; Idx: Integer);
+  cdecl external 'lua.dll';
+procedure lua_pushvalue(L: Plua_State; Idx: Integer);
+  cdecl external 'lua.dll';
+procedure lua_remove(L: Plua_State; Idx: Integer);
+  cdecl external 'lua.dll';
+procedure lua_insert(L: Plua_State; Idx: Integer);
+  cdecl external 'lua.dll';
+procedure lua_replace(L: Plua_State; Idx: Integer);
+  cdecl external 'lua.dll';
+function lua_checkstack(L: Plua_State; SZ: Integer): Integer;
+  cdecl external 'lua.dll';
+
+procedure lua_xmove (Src, Dst: Plua_State; N: Integer);
+  cdecl external 'lua.dll';
+
+
+(*
+** access functions (stack -> C)
+*)
+
+function lua_isnumber(L: Plua_State; Idx: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_isstring(L: Plua_State; Idx: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_iscfunction(L: Plua_State; Idx: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_isuserdata(L: Plua_State; Idx: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_type(L: Plua_State; Idx: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_typename(L: Plua_State; TP: Integer): PChar;
+  cdecl external 'lua.dll';
+
+function lua_equal(L: Plua_State; Idx1: Integer; Idx2: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_rawequal(L: Plua_State; Idx1: Integer; Idx2: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_lessthan(L: Plua_State; Idx1: Integer; Idx2: Integer): Integer;
+  cdecl external 'lua.dll';
+
+function lua_tonumber(L: Plua_State; Idx: Integer): lua_Number;
+  cdecl external 'lua.dll';
+function lua_toboolean(L: Plua_State; Idx: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_tostring(L: Plua_State; Idx: Integer): PChar;
+  cdecl external 'lua.dll';
+function lua_strlen(L: Plua_State; Idx: Integer): size_t;
+  cdecl external 'lua.dll';
+function lua_tocfunction(L: Plua_State; Idx: Integer): lua_CFunction;
+  cdecl external 'lua.dll';
+function lua_touserdata(L: Plua_State; Idx: Integer): Pointer;
+  cdecl external 'lua.dll';
+function lua_tothread(L: Plua_State; Idx: Integer): Plua_State;
+  cdecl external 'lua.dll';
+function lua_topointer(L: Plua_State; Idx: Integer): Pointer;
+  cdecl external 'lua.dll';
+
+
+(*
+** push functions (C -> stack)
+*)
+procedure lua_pushnil(L: Plua_State);
+  cdecl external 'lua.dll';
+procedure lua_pushnumber(L: Plua_State; N: lua_Number);
+  cdecl external 'lua.dll';
+procedure lua_pushlstring(L: Plua_State; const S: PChar; N: size_t);
+  cdecl external 'lua.dll';
+procedure lua_pushstring(L: Plua_State; const S: PChar);
+  cdecl external 'lua.dll';
+function lua_pushvfstring(L: Plua_State; const Fmt: PChar; Argp: Pointer): PChar;
+  cdecl external 'lua.dll';
+function lua_pushfstring(L: Plua_State; const Fmt: PChar): PChar; varargs;
+  cdecl external 'lua.dll';
+procedure lua_pushcclosure(L: Plua_State; Fn: lua_CFunction; N: Integer);
+  cdecl external 'lua.dll';
+procedure lua_pushboolean(L: Plua_State; B: Integer);
+  cdecl external 'lua.dll';
+procedure lua_pushlightuserdata(L: Plua_State; P: Pointer);
+  cdecl external 'lua.dll';
+
+
+(*
+** get functions (Lua -> stack)
+*)
+procedure lua_gettable(L: Plua_State; Idx: Integer);
+  cdecl external 'lua.dll';
+procedure lua_rawget(L: Plua_State; Idx: Integer);
+  cdecl external 'lua.dll';
+procedure lua_rawgeti(L: Plua_State; Idx: Integer; N: Integer);
+  cdecl external 'lua.dll';
+procedure lua_newtable(L: Plua_State);
+  cdecl external 'lua.dll';
+function lua_newuserdata(L: Plua_State; SZ: size_t): Pointer;
+  cdecl external 'lua.dll';
+function lua_getmetatable(L: Plua_State; ObjIndex: Integer): Integer;
+  cdecl external 'lua.dll';
+procedure lua_getfenv(L: Plua_State; Idx: Integer);
+  cdecl external 'lua.dll';
+
+
+(*
+** set functions (stack -> Lua)
+*)
+procedure lua_settable(L: Plua_State; Idx: Integer);
+  cdecl external 'lua.dll';
+procedure lua_rawset(L: Plua_State; Idx: Integer);
+  cdecl external 'lua.dll';
+procedure lua_rawseti(L: Plua_State; Idx: Integer; N: Integer);
+  cdecl external 'lua.dll';
+function lua_setmetatable(L: Plua_State; ObjIndex: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_setfenv(L: Plua_State; Idx: Integer): Integer;
+  cdecl external 'lua.dll';
+
+
+(*
+** `load' and `call' functions (load and run Lua code)
+*)
+procedure lua_call(L: Plua_State; NArgs: Integer; NResults: Integer);
+  cdecl external 'lua.dll';
+function lua_pcall(L: Plua_State; NArgs: Integer; NResults: Integer; ErrFunc: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_cpcall(L: Plua_State; Func: lua_CFunction; UD: Pointer): Integer;
+  cdecl external 'lua.dll';
+function lua_load(L: Plua_State; Reader: lua_Chunkreader; DT: Pointer;
+                        const ChunkName: PChar): Integer;
+  cdecl external 'lua.dll';
+
+function lua_dump(L: Plua_State; Writer: lua_Chunkwriter; Data: Pointer): Integer;
+  cdecl external 'lua.dll';
+
+
+(*
+** coroutine functions
+*)
+function lua_yield(L: Plua_State; NResults: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_resume(L: Plua_State; NArg: Integer): Integer;
+  cdecl external 'lua.dll';
+
+(*
+** garbage-collection functions
+*)
+function lua_getgcthreshold(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+function lua_getgccount(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+procedure lua_setgcthreshold(L: Plua_State; NewThreshold: Integer);
+  cdecl external 'lua.dll';
+
+(*
+** miscellaneous functions
+*)
+
+function lua_version: PChar;
+  cdecl external 'lua.dll';
+
+function lua_error(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+
+function lua_next(L: Plua_State; Idx: Integer): Integer;
+  cdecl external 'lua.dll';
+
+procedure lua_concat(L: Plua_State; N: Integer);
+  cdecl external 'lua.dll';
+
+
+
+(*
+** ===============================================================
+** some useful macros
+** ===============================================================
+*)
+
+function lua_boxpointer(L: Plua_State; U: Pointer): Pointer;
+function lua_unboxpointer(L: Plua_State; I: Integer): Pointer;
+procedure lua_pop(L: Plua_State; N: Integer);
+procedure lua_register(L: Plua_State; const N: PChar; F: lua_CFunction);
+procedure lua_pushcfunction(L: Plua_State; F: lua_CFunction);
+function lua_isfunction(L: Plua_State; N: Integer): Boolean;
+function lua_istable(L: Plua_State; N: Integer): Boolean;
+function lua_islightuserdata(L: Plua_State; N: Integer): Boolean;
+function lua_isnil(L: Plua_State; N: Integer): Boolean;
+function lua_isboolean(L: Plua_State; N: Integer): Boolean;
+function lua_isnone(L: Plua_State; N: Integer): Boolean;
+function lua_isnoneornil(L: Plua_State; N: Integer): Boolean;
+procedure lua_pushliteral(L: Plua_State; const S: PChar);
+
+(*
+** compatibility macros and functions
+*)
+
+function lua_pushupvalues(L: Plua_State): Integer;
+  cdecl; external 'lua.dll';
+
+procedure lua_getregistry(L: Plua_State);
+procedure lua_setglobal(L: Plua_State; const S: PChar);
+procedure lua_getglobal(L: Plua_State; const S: PChar);
+
+(* compatibility with ref system *)
+
+(* pre-defined references *)
+const
+  LUA_NOREF = (-2);
+  LUA_REFNIL = (-1);
+
+procedure lua_ref(L: Plua_State; Lock: Integer);
+procedure lua_unref(L: Plua_State; Ref: Integer);
+procedure lua_getref(L: Plua_State; Ref: Integer);
+
+(*
+** {======================================================================
+** useful definitions for Lua kernel and libraries
+** =======================================================================
+*)
+
+(* formats for Lua numbers *)
+{$IFNDEF LUA_NUMBER_SCAN}
+const
+  LUA_NUMBER_SCAN = '%lf';
+{$ENDIF}
+
+{$IFNDEF LUA_NUMBER_FMT}
+const
+  LUA_NUMBER_FMT = '%.14g';
+{$ENDIF}
+
+(* }====================================================================== *)
+
+
+(*
+** {======================================================================
+** Debug API
+** =======================================================================
+*)
+
+const
+(*
+** Event codes
+*)
+  LUA_HOOKCALL = 0;
+  LUA_HOOKRET = 1;
+  LUA_HOOKLINE = 2;
+  LUA_HOOKCOUNT = 3;
+  LUA_HOOKTAILRET = 4;
+
+
+(*
+** Event masks
+*)
+  LUA_MASKCALL = (1 shl LUA_HOOKCALL);
+  LUA_MASKRET = (1 shl LUA_HOOKRET);
+  LUA_MASKLINE = (1 shl LUA_HOOKLINE);
+  LUA_MASKCOUNT = (1 shl LUA_HOOKCOUNT);
+
+const
+  LUA_IDSIZE = 60;
+
+type
+  lua_Debug = record
+    event: Integer;
+    name: PChar; (* (n) *)
+    namewhat: PChar; (* (n) `global', `local', `field', `method' *)
+    what: PChar; (* (S) `Lua', `C', `main', `tail' *)
+    source: PChar; (* (S) *)
+    currentline: Integer;  (* (l) *)
+    nups: Integer;   (* (u) number of upvalues *)
+    linedefined: Integer;  (* (S) *)
+    short_src: array [0..LUA_IDSIZE - 1] of Char; (* (S) *)
+    (* private part *)
+    i_ci: Integer;  (* active function *)
+  end;
+  Plua_Debug = ^lua_Debug;
+
+  lua_Hook = procedure (L: Plua_State; AR: Plua_Debug); cdecl;
+
+
+function lua_getstack(L: Plua_State; Level: Integer; AR: Plua_Debug): Integer;
+  cdecl external 'lua.dll';
+function lua_getinfo(L: Plua_State; const What: PChar; AR: Plua_Debug): Integer;
+  cdecl external 'lua.dll';
+function lua_getlocal(L: Plua_State; const AR: Plua_Debug; N: Integer): PChar;
+  cdecl external 'lua.dll';
+function lua_setlocal(L: Plua_State; const AR: Plua_Debug; N: Integer): PChar;
+  cdecl external 'lua.dll';
+function lua_getupvalue(L: Plua_State; FuncIndex: Integer; N: Integer): PChar;
+  cdecl external 'lua.dll';
+function lua_setupvalue(L: Plua_State; FuncIndex: Integer; N: Integer): PChar;
+  cdecl external 'lua.dll';
+
+function lua_sethook(L: Plua_State; Func: lua_Hook; Mask: Integer; Count: Integer): Integer;
+  cdecl external 'lua.dll';
+function lua_gethook(L: Plua_State): lua_Hook;
+  cdecl external 'lua.dll';
+function lua_gethookmask(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+function lua_gethookcount(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+
+(* }====================================================================== *)
+
+
+(******************************************************************************
+* Copyright (C) 1994-2003 Tecgraf, PUC-Rio.  All rights reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining
+* a copy of this software and associated documentation files (the
+* "Software"), to deal in the Software without restriction, including
+* without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to
+* permit persons to whom the Software is furnished to do so, subject to
+* the following conditions:
+*
+* The above copyright notice and this permission notice shall be
+* included in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+******************************************************************************)
+
+
+implementation
+
+uses
+  SysUtils, lauxlib;
+
+const
+  MAX_SIZE = High(Integer);
+  MAX_POINTER_ARRAY = MAX_SIZE div SizeOf(Pointer);
+
+type
+  TPointerArray = array [0..MAX_POINTER_ARRAY - 1] of Pointer;
+  PPointerArray = ^TPointerArray;
+
+function lua_upvalueindex(I: Integer): Integer;
+begin
+  Result := LUA_GLOBALSINDEX - I;
+end;
+
+function lua_boxpointer(L: Plua_State; U: Pointer): Pointer;
+begin
+  PPointerArray(lua_newuserdata(L, sizeof(U)))^[0] := U;
+  Result := U;
+end;
+
+function lua_unboxpointer(L: Plua_State; I: Integer): Pointer;
+begin
+  Result := PPointerArray(lua_touserdata(L, I))^[0];
+end;
+
+procedure lua_pop(L: Plua_State; N: Integer);
+begin
+  lua_settop(L, -(N)-1);
+end;
+
+procedure lua_register(L: Plua_State; const N: PChar; F: lua_CFunction);
+begin
+  lua_pushstring(L, N);
+  lua_pushcfunction(L, F);
+  lua_settable(L, LUA_GLOBALSINDEX);
+end;
+
+procedure lua_pushcfunction(L: Plua_State; F: lua_CFunction);
+begin
+  lua_pushcclosure(L, F, 0);
+end;
+
+function lua_isfunction(L: Plua_State; N: Integer): Boolean;
+begin
+  Result := lua_type(L, n) = LUA_TFUNCTION;
+end;
+
+function lua_istable(L: Plua_State; N: Integer): Boolean;
+begin
+  Result := lua_type(L, n) = LUA_TTABLE;
+end;
+
+function lua_islightuserdata(L: Plua_State; N: Integer): Boolean;
+begin
+  Result := lua_type(L, n) = LUA_TLIGHTUSERDATA;
+end;
+
+function lua_isnil(L: Plua_State; N: Integer): Boolean;
+begin
+  Result := lua_type(L, n) = LUA_TNIL;
+end;
+
+function lua_isboolean(L: Plua_State; N: Integer): Boolean;
+begin
+  Result := lua_type(L, n) = LUA_TBOOLEAN;
+end;
+
+function lua_isnone(L: Plua_State; N: Integer): Boolean;
+begin
+  Result := lua_type(L, n) = LUA_TNONE;
+end;
+
+function lua_isnoneornil(L: Plua_State; N: Integer): Boolean;
+begin
+  Result := lua_type(L, n) <= 0;
+end;
+
+procedure lua_pushliteral(L: Plua_State; const S: PChar);
+begin
+  lua_pushlstring(L, S, StrLen(S));
+end;
+
+procedure lua_getregistry(L: Plua_State);
+begin
+  lua_pushvalue(L, LUA_REGISTRYINDEX);
+end;
+
+procedure lua_setglobal(L: Plua_State; const S: PChar);
+begin
+  lua_pushstring(L, S);
+  lua_insert(L, -2);
+  lua_settable(L, LUA_GLOBALSINDEX);
+end;
+
+procedure lua_getglobal(L: Plua_State; const S: PChar);
+begin
+  lua_pushstring(L, S);
+  lua_gettable(L, LUA_GLOBALSINDEX);
+end;
+
+procedure lua_ref(L: Plua_State; Lock: Integer);
+begin
+  if (Lock <> 0) then
+  begin
+    luaL_ref(L, LUA_REGISTRYINDEX);
+  end else
+  begin
+    lua_pushstring(L, 'unlocked references are obsolete');
+    lua_error(L);
+  end;
+end;
+
+procedure lua_unref(L: Plua_State; Ref: Integer);
+begin
+  luaL_unref(L, LUA_REGISTRYINDEX, Ref);
+end;
+
+procedure lua_getref(L: Plua_State; Ref: Integer);
+begin
+  lua_rawgeti(L, LUA_REGISTRYINDEX, Ref);
+end;
+
+end.

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lualib.dcu


+ 95 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/LuaCore/lualib.pas

@@ -0,0 +1,95 @@
+(*
+** $Id: lualib.pas,v 1.1 2005-11-26 15:19:46 jfgoulet Exp $
+** Lua standard libraries
+** See Copyright Notice in lua.h
+*)
+unit lualib;
+
+{$IFNDEF lualib_h}
+{$DEFINE lualib_h}
+{$ENDIF}
+
+interface
+
+uses
+  lua;
+
+const
+  LUA_COLIBNAME = 'coroutine';
+  LUA_TABLIBNAME = 'table';
+  LUA_IOLIBNAME = 'io';
+  LUA_OSLIBNAME = 'os';
+  LUA_STRLIBNAME = 'string';
+  LUA_MATHLIBNAME = 'math';
+  LUA_DBLIBNAME = 'debug';
+
+function luaopen_base(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+
+function luaopen_table(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+
+function luaopen_io(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+
+function luaopen_string(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+
+function luaopen_math(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+
+function luaopen_debug(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+
+
+function luaopen_loadlib(L: Plua_State): Integer;
+  cdecl external 'lua.dll';
+
+
+(* to help testing the libraries *)
+{$IFNDEF lua_assert}
+//#define lua_assert(c)   (* empty *)
+{$ENDIF}
+
+
+(* compatibility code *)
+function lua_baselibopen(L: Plua_State): Integer;
+function lua_tablibopen(L: Plua_State): Integer;
+function lua_iolibopen(L: Plua_State): Integer;
+function lua_strlibopen(L: Plua_State): Integer;
+function lua_mathlibopen(L: Plua_State): Integer;
+function lua_dblibopen(L: Plua_State): Integer;
+
+implementation
+
+function lua_baselibopen(L: Plua_State): Integer;
+begin
+  Result := luaopen_base(L);
+end;
+
+function lua_tablibopen(L: Plua_State): Integer;
+begin
+  Result := luaopen_table(L);
+end;
+
+function lua_iolibopen(L: Plua_State): Integer;
+begin
+  Result := luaopen_io(L);
+end;
+
+function lua_strlibopen(L: Plua_State): Integer;
+begin
+  Result := luaopen_string(L);
+end;
+
+function lua_mathlibopen(L: Plua_State): Integer;
+begin
+  Result := luaopen_math(L);
+end;
+
+function lua_dblibopen(L: Plua_State): Integer;
+begin
+  Result := luaopen_debug(L);
+end;
+
+end.

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.dcu


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.ddp


+ 232 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.dfm

@@ -0,0 +1,232 @@
+object frmMainSimon: TfrmMainSimon
+  Left = 447
+  Top = 136
+  BorderIcons = []
+  BorderStyle = bsNone
+  Caption = 'Simon'
+  ClientHeight = 473
+  ClientWidth = 402
+  Color = clBlack
+  TransparentColorValue = clNone
+  Constraints.MinHeight = 389
+  Constraints.MinWidth = 389
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'MS Sans Serif'
+  Font.Style = []
+  OldCreateOrder = False
+  Position = poScreenCenter
+  PixelsPerInch = 96
+  TextHeight = 13
+  object lblGreen: TLabel
+    Left = 16
+    Top = 16
+    Width = 185
+    Height = 185
+    Cursor = crHandPoint
+    AutoSize = False
+    Color = clGreen
+    ParentColor = False
+    Transparent = False
+    OnMouseDown = lblGreenMouseDown
+    OnMouseUp = lblGreenMouseUp
+  end
+  object lblRed: TLabel
+    Left = 200
+    Top = 16
+    Width = 185
+    Height = 185
+    Cursor = crHandPoint
+    AutoSize = False
+    Color = clMaroon
+    ParentColor = False
+    Transparent = False
+    OnMouseDown = lblRedMouseDown
+    OnMouseUp = lblRedMouseUp
+  end
+  object lblBlue: TLabel
+    Left = 200
+    Top = 200
+    Width = 185
+    Height = 185
+    Cursor = crHandPoint
+    AutoSize = False
+    Color = clNavy
+    ParentColor = False
+    Transparent = False
+    OnMouseDown = lblBlueMouseDown
+    OnMouseUp = lblBlueMouseUp
+  end
+  object lblYellow: TLabel
+    Left = 16
+    Top = 200
+    Width = 185
+    Height = 185
+    Cursor = crHandPoint
+    AutoSize = False
+    Color = clOlive
+    ParentColor = False
+    Transparent = False
+    OnMouseDown = lblYellowMouseDown
+    OnMouseUp = lblYellowMouseUp
+  end
+  object Shape1: TShape
+    Left = 16
+    Top = 393
+    Width = 169
+    Height = 65
+    Brush.Color = clBlack
+    Pen.Color = clWhite
+    Pen.Width = 5
+    Shape = stRoundRect
+  end
+  object Label1: TLabel
+    Left = 43
+    Top = 406
+    Width = 114
+    Height = 38
+    Caption = 'SIMON'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clWhite
+    Font.Height = -32
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object shpPlay: TShape
+    Left = 353
+    Top = 432
+    Width = 25
+    Height = 25
+    Cursor = crHandPoint
+    Pen.Color = clWhite
+    Shape = stCircle
+    OnMouseDown = shpPlayMouseDown
+  end
+  object Label2: TLabel
+    Left = 349
+    Top = 407
+    Width = 36
+    Height = 19
+    Caption = 'Play'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clWhite
+    Font.Height = -16
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object shpGameOver: TShape
+    Left = 8
+    Top = 161
+    Width = 385
+    Height = 88
+    Brush.Color = clBlack
+    Pen.Color = clWhite
+    Pen.Width = 5
+    Shape = stRoundRect
+  end
+  object lblGameOver: TLabel
+    Left = 18
+    Top = 168
+    Width = 365
+    Height = 75
+    Caption = 'Game Over'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clRed
+    Font.Height = -64
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object shpPower: TShape
+    Left = 272
+    Top = 432
+    Width = 69
+    Height = 25
+    Cursor = crHandPoint
+    Brush.Color = clLime
+    Pen.Color = clLime
+    Shape = stRoundRect
+    OnMouseDown = shpPowerMouseDown
+  end
+  object Label3: TLabel
+    Left = 280
+    Top = 407
+    Width = 52
+    Height = 19
+    Caption = 'Power'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clWhite
+    Font.Height = -16
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object Label4: TLabel
+    Left = 200
+    Top = 407
+    Width = 46
+    Height = 19
+    Caption = 'Score'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clWhite
+    Font.Height = -16
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object Shape2: TShape
+    Left = 192
+    Top = 432
+    Width = 65
+    Height = 25
+    Brush.Color = clBlack
+    Pen.Color = clWhite
+    Pen.Width = 5
+    Shape = stRoundRect
+  end
+  object lblScore: TLabel
+    Left = 206
+    Top = 438
+    Width = 39
+    Height = 14
+    Alignment = taCenter
+    AutoSize = False
+    Caption = '0'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clWhite
+    Font.Height = -11
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object shpMessage: TShape
+    Left = 8
+    Top = 161
+    Width = 385
+    Height = 88
+    Brush.Color = clBlack
+    Pen.Color = clWhite
+    Pen.Width = 5
+    Shape = stRoundRect
+    Visible = False
+  end
+  object lblMessage: TLabel
+    Left = 16
+    Top = 176
+    Width = 369
+    Height = 57
+    Alignment = taCenter
+    AutoSize = False
+    Caption = 'A Message!'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clLime
+    Font.Height = -48
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+    Visible = False
+  end
+end

+ 691 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.pas

@@ -0,0 +1,691 @@
+unit MainSimon;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, ExtCtrls, Lua, LuaUtils, LAuxLib, LuaLib, Themes, UxTheme,
+  StdCtrls, MMSystem;
+
+const
+  // Light colors constants
+  LIGHT_NONE    = 0;
+  LIGHT_RED     = 1;
+  LIGHT_BLUE    = 2;
+  LIGHT_YELLOW  = 3;
+  LIGHT_GREEN   = 4;
+
+  // Turns constants
+  TURN_SIMON  = 1;
+  TURN_USER   = 2;
+
+type
+  TfrmMainSimon = class(TForm)
+    lblGreen: TLabel;
+    lblRed: TLabel;
+    lblBlue: TLabel;
+    lblYellow: TLabel;
+    Shape1: TShape;
+    Label1: TLabel;
+    shpPlay: TShape;
+    Label2: TLabel;
+    lblGameOver: TLabel;
+    shpGameOver: TShape;
+    shpPower: TShape;
+    Label3: TLabel;
+    Label4: TLabel;
+    Shape2: TShape;
+    lblScore: TLabel;
+    shpMessage: TShape;
+    lblMessage: TLabel;
+    procedure shpPowerMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure shpPlayMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblGreenMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblGreenMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblRedMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblRedMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblBlueMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblBlueMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblYellowMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblYellowMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+  private
+    { Private declarations }
+  public
+    { Public declarations }
+    function SetNoLight: Integer;
+    function SetRedLight: Integer;
+    function SetBlueLight: Integer;
+    function SetGreenLight: Integer;
+    function SetYellowLight: Integer;
+  end;
+
+var
+  frmMainSimon: TfrmMainSimon;
+  GameOver: Boolean;
+  Power: Boolean;
+  PlayHit: Boolean;
+  ControlsLock: Boolean;
+  MediaPath: String;
+  AppHandle: HWND;
+  SequenceCount: Integer;
+  MaxInterval: Integer;
+  LastClickInterval: Cardinal;
+  Score: Cardinal;
+  LuaState: Plua_State;
+
+// Other misc functions
+procedure SetAppHandle(Handle: HWND); cdecl;
+
+// LuaEdit debug hook function
+function LuaDebug_Initializer(L: PLua_State): Integer; cdecl;
+
+// Lua registred functions
+function DisplayMessage(L: Plua_State): Integer; cdecl;
+function LockControls(L: Plua_State): Integer; cdecl;
+function UnlockControls(L: Plua_State): Integer; cdecl;
+function SetScore(L: Plua_State): Integer; cdecl;
+function GetScore(L: Plua_State): Integer; cdecl;
+function GetPlayStatus(L: Plua_State): Integer; cdecl;
+function GetPowerStatus(L: Plua_State): Integer; cdecl;
+function GetUserSequence(L: Plua_State): Integer; cdecl;
+function SetMediaPath(L: Plua_State): Integer; cdecl;
+function SetLight(L: Plua_State): Integer; cdecl;
+function Create(L: Plua_State): Integer; cdecl;
+function Destroy(L: Plua_State): Integer; cdecl;
+function LuaSleep(L: Plua_State): Integer; cdecl;
+
+implementation
+
+{$R *.dfm}
+
+//////////////////////////////////////////////////////////////
+//  Miscellaneous exported functions
+//////////////////////////////////////////////////////////////
+
+procedure SetAppHandle(Handle: HWND);
+begin
+  AppHandle := Handle;
+end;
+
+//////////////////////////////////////////////////////////////
+//  LuaEdit debug hook function (simon.dll main entry function)
+//////////////////////////////////////////////////////////////
+
+// LuaEdit is calling this function everytime a script with a project
+// specifying this dll as the initializer when debugging
+function LuaDebug_Initializer(L: PLua_State): Integer;
+begin
+  // Create new table on the lua stack
+  lua_newtable(L);
+
+  // Register delphi functions in that new table
+  LuaRegisterCustom(L, -1, 'SetMediaPath', SetMediaPath);
+  LuaRegisterCustom(L, -1, 'SetLight', SetLight);
+  LuaRegisterCustom(L, -1, 'Create', Create);
+  LuaRegisterCustom(L, -1, 'Destroy', Destroy);
+  LuaRegisterCustom(L, -1, 'GetUserSequence', GetUserSequence);
+  LuaRegisterCustom(L, -1, 'GetPowerStatus', GetPowerStatus);
+  LuaRegisterCustom(L, -1, 'GetPlayStatus', GetPlayStatus);
+  LuaRegisterCustom(L, -1, 'SetScore', SetScore);
+  LuaRegisterCustom(L, -1, 'GetScore', GetScore);
+  LuaRegisterCustom(L, -1, 'LockControls', LockControls);
+  LuaRegisterCustom(L, -1, 'UnlockControls', UnlockControls);
+  LuaRegisterCustom(L, -1, 'DisplayMessage', DisplayMessage);
+
+  // Register other miscalleneous functions
+  LuaRegister(L, 'Sleep', LuaSleep);
+
+  // Assing "Simon" lua global variable to the new table
+  lua_setglobal(L, 'simon');
+  AppHandle := 0;
+  Result := 1;
+end;
+
+//////////////////////////////////////////////////////////////
+//  Lua registred functions
+//////////////////////////////////////////////////////////////
+
+function DisplayMessage(L: Plua_State): Integer;
+var
+  Msg, Color: String;
+  ShowTime: Integer;
+begin
+  Result := 1;
+  ShowTime := -1;
+  Msg := '';
+  Color := 'clWhite';
+
+  if lua_type(L, -3) = LUA_TSTRING then
+    Msg := lua_tostring(L, -3)
+  else
+    Result := 0;
+
+  if lua_type(L, -2) = LUA_TSTRING then
+    Color := lua_tostring(L, -2)
+  else
+    Result := 0;
+
+  if lua_type(L, -1) = LUA_TNUMBER then
+    ShowTime := Trunc(lua_tonumber(L, -1))
+  else
+    Result := 0;
+
+  if Result <> 0 then
+  begin
+    frmMainSimon.lblMessage.Caption := Msg;
+    frmMainSimon.lblMessage.Font.Color := StringToColor(Color);
+    frmMainSimon.lblMessage.Visible := True;
+    frmMainSimon.shpMessage.Visible := True;
+    Application.ProcessMessages;
+
+    if ShowTime > 0 then
+    begin
+      Sleep(ShowTime);
+      frmMainSimon.lblMessage.Visible := False;
+      frmMainSimon.shpMessage.Visible := False;
+    end;
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+function LockControls(L: Plua_State): Integer;
+begin
+  frmMainSimon.lblGreen.Cursor := crDefault;
+  frmMainSimon.lblRed.Cursor := crDefault;
+  frmMainSimon.lblBlue.Cursor := crDefault;
+  frmMainSimon.lblYellow.Cursor := crDefault;
+  frmMainSimon.shpPlay.Cursor := crDefault;
+  frmMainSimon.shpPower.Cursor := crDefault;
+  ControlsLock := True;
+  Application.ProcessMessages;
+  Result := 1;
+  lua_pushnumber(L, Result);
+end;
+
+function UnlockControls(L: Plua_State): Integer;
+begin
+  frmMainSimon.lblGreen.Cursor := crHandPoint;
+  frmMainSimon.lblRed.Cursor := crHandPoint;
+  frmMainSimon.lblBlue.Cursor := crHandPoint;
+  frmMainSimon.lblYellow.Cursor := crHandPoint;
+  frmMainSimon.shpPlay.Cursor := crHandPoint;
+  frmMainSimon.shpPower.Cursor := crHandPoint;
+  ControlsLock := False;
+  Application.ProcessMessages;
+  Result := 1;
+  lua_pushnumber(L, Result);
+end;
+
+function SetScore(L: Plua_State): Integer;
+var
+  NewScore: Cardinal;
+begin
+  Result := 1;
+  if lua_type(L, -1) = LUA_TNUMBER then
+    NewScore := Trunc(lua_tonumber(L, -1))
+  else
+    Result := 0;
+
+  if Result <> 0 then
+  begin
+    Score := NewScore;
+    frmMainSimon.lblScore.Caption := IntToStr(Score);
+    Application.ProcessMessages;
+  end;
+
+  lua_pushnumber(L, Score);
+end;
+
+function GetScore(L: Plua_State): Integer;
+begin
+  Result := 1;
+  lua_pushnumber(L, Score);
+end;
+
+function GetPlayStatus(L: Plua_State): Integer;
+begin
+  Result := Integer(PlayHit);
+  PlayHit := False;
+  lua_pushnumber(L, Result);
+end;
+
+function GetPowerStatus(L: Plua_State): Integer;
+begin
+  Result := Integer(Power);
+  lua_pushnumber(L, Result);
+end;
+
+function GetUserSequence(L: Plua_State): Integer;
+var
+  SequenceLength: Integer;
+begin
+  Result := 1;
+  SequenceCount := 0;
+  LastClickInterval := GetTickCount();
+  GameOver := False;
+
+  if lua_type(L, -2) = LUA_TNUMBER then
+    SequenceLength := Trunc(lua_tonumber(L, -2))
+  else
+    Result := 0;
+
+  if lua_type(L, -1) = LUA_TNUMBER then
+    MaxInterval := Trunc(lua_tonumber(L, -1))
+  else
+    Result := 0;
+
+  if Result <> 0 then
+  begin
+    while (Power and (not GameOver) and (SequenceCount < SequenceLength)) do
+    begin
+      if ((GetTickCount() - LastClickInterval) >= MaxInterval) then
+        GameOver := True;
+
+      Application.ProcessMessages;
+      Sleep(10);
+    end;
+  end;
+
+  if GameOver then
+  begin
+    frmMainSimon.lblGameOver.Visible := True;
+    frmMainSimon.shpGameOver.Visible := True;
+    Application.ProcessMessages;
+    Result := 0;
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+function SetMediaPath(L: Plua_State): Integer;
+var
+  sMediaPath: String;
+begin
+  Result := 0;
+  sMediaPath := '';
+
+  // Retreive last and only one lua argument from lua stack (string)
+  if lua_type(L, -1) = LUA_TSTRING then
+    sMediaPath := lua_tostring(L, -1);
+
+  // Set media path if any
+  if DirectoryExists(sMediaPath) then
+  begin
+    MediaPath := sMediaPath;
+    Result := 1;
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+function SetLight(L: Plua_State): Integer;
+var
+  Color: Integer;
+begin
+  Result := 0;
+  Color := -1;
+
+  // Retreive last and only one lua argument from lua stack (Integer or nil)
+  if lua_type(L, -1) = LUA_TNUMBER then
+    Color := Trunc(lua_tonumber(L, -1))
+  else if lua_type(L, -1) = LUA_TNIL then
+    Color := 0;
+  
+  case Color of
+    LIGHT_NONE:   Result := frmMainSimon.SetNoLight();
+    LIGHT_RED:    Result := frmMainSimon.SetRedLight();
+    LIGHT_BLUE:   Result := frmMainSimon.SetBlueLight();
+    LIGHT_YELLOW: Result := frmMainSimon.SetYellowLight();
+    LIGHT_GREEN:  Result := frmMainSimon.SetGreenLight();
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+function Create(L: Plua_State): Integer;
+var
+  Style: Integer;
+begin
+  // leave those important lines here...
+  // There is a bug with the themes and forms placed in dll
+  // The dll don't have the time to free the theme handle and the when it does it,
+  // the hoset application (LuaEdit) already did it so... Runtime Error 216
+  ThemeServices.ApplyThemeChange;
+  InitThemeLibrary;
+  Result := -1;
+  Style := -1;
+  GameOver := False;
+  Power := True;
+  Score := 0;
+
+  // Retreive optional parameter (create style)
+  if lua_type(L, -1) = LUA_TNUMBER then
+    Style := Trunc(lua_tonumber(L, -1));
+
+  if not Assigned(frmMainSimon) then
+  begin
+    if AppHandle = 0 then
+      AppHandle := GetActiveWindow();
+
+    LuaState := L;
+    Application.Handle := AppHandle;
+    //frmMainSimon := TfrmMainSimon.Create(Application);
+    frmMainSimon := TfrmMainSimon.CreateParented(0);
+
+    case Style of
+      1: frmMainSimon.BorderStyle := bsSizeable;
+      2: frmMainSimon.BorderStyle := bsSizeToolWin;
+    else
+      frmMainSimon.BorderStyle := bsNone;
+    end;
+
+    frmMainSimon.lblGameOver.Visible := False;
+    frmMainSimon.shpGameOver.Visible := False;
+    Application.ProcessMessages;
+    Result := 1;
+  end;
+
+  if Result = 1 then
+  begin
+    frmMainSimon.Show;
+    frmMainSimon.BringToFront;
+    Application.ProcessMessages;
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+function Destroy(L: Plua_State): Integer;
+begin
+  Result := -1;
+
+  if Assigned(frmMainSimon) then
+  begin
+    LuaState := nil;
+    frmMainSimon.Close;
+    SetParent(frmMainSimon.Handle, 0);
+    FreeAndNil(frmMainSimon);
+    Application.ProcessMessages;
+    Result := 1;
+  end;
+
+  // leave those important lines here...
+  // There is a bug with the themes and forms placed in dll
+  // The dll don't have the time to free the theme handle and the when it does it,
+  // the hoset application (LuaEdit) already did it so... Runtime Error 216
+  ThemeServices.ApplyThemeChange;
+  FreeThemeLibrary;
+  lua_pushnumber(L, Result);
+end;
+
+function LuaSleep(L: Plua_State): Integer; cdecl;
+var
+  Length: Integer;
+begin
+  Result := 0;
+  Length := -1;
+
+  // Retreive last and only one lua argument from lua stack (Integer or nil)
+  if lua_type(L, -1) = LUA_TNUMBER then
+    Length := Trunc(lua_tonumber(L, -1));
+
+  if Length > 0 then
+  begin
+    Result := 1;
+    Sleep(Length);
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+//////////////////////////////////////////////////////////////
+//  TfrmMainSimon implementation
+//////////////////////////////////////////////////////////////
+
+function TfrmMainSimon.SetNoLight: Integer;
+begin
+  lblBlue.Color := clNavy;
+  lblRed.Color := clMaroon;
+  lblYellow.Color := clOlive;
+  lblGreen.Color := clGreen;
+  Result := 1;
+end;
+
+function TfrmMainSimon.SetRedLight: Integer;
+begin
+  PlaySound(PChar(MediaPath + '\01.wav'), 0, SND_FILENAME or SND_NODEFAULT or SND_ASYNC);
+  lblBlue.Color := clNavy;
+  lblRed.Color := clRed;
+  lblYellow.Color := clOlive;
+  lblGreen.Color := clGreen;
+  Result := 1;
+end;
+
+function TfrmMainSimon.SetBlueLight: Integer;
+begin
+  PlaySound(PChar(MediaPath + '\02.wav'), 0, SND_FILENAME or SND_NODEFAULT or SND_ASYNC);
+  lblBlue.Color := clBlue;
+  lblRed.Color := clMaroon;
+  lblYellow.Color := clOlive;
+  lblGreen.Color := clGreen;
+  Result := 1;
+end;
+
+function TfrmMainSimon.SetGreenLight: Integer;
+begin
+  PlaySound(PChar(MediaPath + '\03.wav'), 0, SND_FILENAME or SND_NODEFAULT or SND_ASYNC);
+  lblBlue.Color := clNavy;
+  lblRed.Color := clMaroon;
+  lblYellow.Color := clOlive;
+  lblGreen.Color := clLime;
+  Result := 1;
+end;
+
+function TfrmMainSimon.SetYellowLight: Integer;
+begin
+  PlaySound(PChar(MediaPath + '\04.wav'), 0, SND_FILENAME or SND_NODEFAULT or SND_ASYNC);
+  lblBlue.Color := clNavy;
+  lblRed.Color := clMaroon;
+  lblYellow.Color := clYellow;
+  lblGreen.Color := clGreen;
+  Result := 1;
+end;
+
+procedure TfrmMainSimon.shpPowerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  if not ControlsLock then
+  begin
+    ShpPower.Brush.Color := clSilver;
+    ShpPower.Pen.Color := clSilver;
+    Application.ProcessMessages;
+    Power := False;
+    GameOver := True;
+    Sleep(500);
+  end;
+end;
+
+procedure TfrmMainSimon.shpPlayMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  if not ControlsLock then
+  begin
+    PlayHit := True;
+    shpGameOver.Visible := False;
+    lblGameOver.Visible := False;
+    Application.ProcessMessages;
+  end;
+end;
+
+procedure TfrmMainSimon.lblGreenMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  if not ControlsLock then
+  begin
+    SetGreenLight;
+    Application.ProcessMessages;    
+  end;
+end;
+
+procedure TfrmMainSimon.lblGreenMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var
+  TimeDiff: Cardinal;
+begin
+  if not ControlsLock then
+  begin
+    Inc(SequenceCount);
+    TimeDiff := GetTickCount() - LastClickInterval;
+
+    if TimeDiff <= MaxInterval then
+    begin
+      // Calling OnButtonClick lua event handler
+      lua_pushstring(LuaState, 'simon');
+      lua_gettable(LuaState, LUA_GLOBALSINDEX);
+      lua_pushstring(LuaState, 'OnButtonClick');
+      lua_gettable(LuaState, -2);
+      lua_pushnumber(LuaState, LIGHT_GREEN);
+      lua_pushnumber(LuaState, LIGHT_GREEN);
+      lua_pushnumber(LuaState, TimeDiff);
+      lua_call(LuaState, 3, 1);
+      GameOver := (Trunc(lua_tonumber(LuaState, -1)) = 0);
+
+      LastClickInterval := GetTickCount();
+    end
+    else
+      GameOver := True;
+
+    SetNoLight;
+  end;
+end;
+
+procedure TfrmMainSimon.lblRedMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  if not ControlsLock then
+  begin
+    SetRedLight;
+    Application.ProcessMessages;
+  end;
+end;
+
+procedure TfrmMainSimon.lblRedMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var
+  TimeDiff: Cardinal;
+begin
+  if not ControlsLock then
+  begin
+    Inc(SequenceCount);
+    TimeDiff := GetTickCount() - LastClickInterval;
+
+    if TimeDiff <= MaxInterval then
+    begin
+      // Calling OnButtonClick lua event handler
+      lua_pushstring(LuaState, 'simon');
+      lua_gettable(LuaState, LUA_GLOBALSINDEX);
+      lua_pushstring(LuaState, 'OnButtonClick');
+      lua_gettable(LuaState, -2);
+      lua_pushnumber(LuaState, LIGHT_RED);
+      lua_pushnumber(LuaState, LIGHT_RED);
+      lua_pushnumber(LuaState, TimeDiff);
+      lua_call(LuaState, 3, 1);
+      GameOver := (Trunc(lua_tonumber(LuaState, -1)) = 0);
+
+      LastClickInterval := GetTickCount();
+    end
+    else
+      GameOver := True;
+
+    SetNoLight;
+  end;
+end;
+
+procedure TfrmMainSimon.lblBlueMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  if not ControlsLock then
+  begin
+    SetBlueLight;
+    Application.ProcessMessages;
+  end;
+end;
+
+procedure TfrmMainSimon.lblBlueMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var
+  TimeDiff: Cardinal;
+begin
+  if not ControlsLock then
+  begin
+    Inc(SequenceCount);
+    TimeDiff := GetTickCount() - LastClickInterval;
+
+    if TimeDiff <= MaxInterval then
+    begin
+      // Calling OnButtonClick lua event handler
+      lua_pushstring(LuaState, 'simon');
+      lua_gettable(LuaState, LUA_GLOBALSINDEX);
+      lua_pushstring(LuaState, 'OnButtonClick');
+      lua_gettable(LuaState, -2);
+      lua_pushnumber(LuaState, LIGHT_BLUE);
+      lua_pushnumber(LuaState, LIGHT_BLUE);
+      lua_pushnumber(LuaState, TimeDiff);
+      lua_call(LuaState, 3, 1);
+      GameOver := (Trunc(lua_tonumber(LuaState, -1)) = 0);
+
+      LastClickInterval := GetTickCount();
+    end
+    else
+      GameOver := True;
+
+    SetNoLight;
+  end;
+end;
+
+procedure TfrmMainSimon.lblYellowMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var
+  TimeDiff: Cardinal;
+begin
+  if not ControlsLock then
+  begin
+    SetYellowLight;
+    Application.ProcessMessages;
+  end;
+end;
+
+procedure TfrmMainSimon.lblYellowMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var
+  TimeDiff: Cardinal;
+begin
+  if not ControlsLock then
+  begin
+    Inc(SequenceCount);
+    TimeDiff := GetTickCount() - LastClickInterval;
+
+    if TimeDiff <= MaxInterval then
+    begin
+      // Calling OnButtonClick lua event handler
+      lua_pushstring(LuaState, 'simon');
+      lua_gettable(LuaState, LUA_GLOBALSINDEX);
+      lua_pushstring(LuaState, 'OnButtonClick');
+      lua_gettable(LuaState, -2);
+      lua_pushnumber(LuaState, LIGHT_YELLOW);
+      lua_pushnumber(LuaState, LIGHT_YELLOW);
+      lua_pushnumber(LuaState, TimeDiff);
+      lua_call(LuaState, 3, 1);
+      GameOver := (Trunc(lua_tonumber(LuaState, -1)) = 0);
+
+      LastClickInterval := GetTickCount();
+    end
+    else
+      GameOver := True;
+
+    SetNoLight;
+  end;
+end;
+
+end.

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.~ddp


+ 231 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.~dfm

@@ -0,0 +1,231 @@
+object frmMainSimon: TfrmMainSimon
+  Left = 447
+  Top = 136
+  BorderIcons = []
+  BorderStyle = bsNone
+  Caption = 'Simon'
+  ClientHeight = 473
+  ClientWidth = 402
+  Color = clBlack
+  TransparentColorValue = clNone
+  Constraints.MinHeight = 389
+  Constraints.MinWidth = 389
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'MS Sans Serif'
+  Font.Style = []
+  OldCreateOrder = False
+  Position = poScreenCenter
+  PixelsPerInch = 96
+  TextHeight = 13
+  object lblGreen: TLabel
+    Left = 16
+    Top = 16
+    Width = 185
+    Height = 185
+    Cursor = crHandPoint
+    AutoSize = False
+    Color = clGreen
+    ParentColor = False
+    Transparent = False
+    OnMouseDown = lblGreenMouseDown
+    OnMouseUp = lblGreenMouseUp
+  end
+  object lblRed: TLabel
+    Left = 200
+    Top = 16
+    Width = 185
+    Height = 185
+    Cursor = crHandPoint
+    AutoSize = False
+    Color = clMaroon
+    ParentColor = False
+    Transparent = False
+    OnMouseDown = lblRedMouseDown
+    OnMouseUp = lblRedMouseUp
+  end
+  object lblBlue: TLabel
+    Left = 200
+    Top = 200
+    Width = 185
+    Height = 185
+    Cursor = crHandPoint
+    AutoSize = False
+    Color = clNavy
+    ParentColor = False
+    Transparent = False
+    OnMouseDown = lblBlueMouseDown
+    OnMouseUp = lblBlueMouseUp
+  end
+  object lblYellow: TLabel
+    Left = 16
+    Top = 200
+    Width = 185
+    Height = 185
+    Cursor = crHandPoint
+    AutoSize = False
+    Color = clOlive
+    ParentColor = False
+    Transparent = False
+    OnMouseDown = lblYellowMouseDown
+  end
+  object Shape1: TShape
+    Left = 16
+    Top = 393
+    Width = 169
+    Height = 65
+    Brush.Color = clBlack
+    Pen.Color = clWhite
+    Pen.Width = 5
+    Shape = stRoundRect
+  end
+  object Label1: TLabel
+    Left = 43
+    Top = 406
+    Width = 114
+    Height = 38
+    Caption = 'SIMON'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clWhite
+    Font.Height = -32
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object shpPlay: TShape
+    Left = 353
+    Top = 432
+    Width = 25
+    Height = 25
+    Cursor = crHandPoint
+    Pen.Color = clWhite
+    Shape = stCircle
+    OnMouseDown = shpPlayMouseDown
+  end
+  object Label2: TLabel
+    Left = 349
+    Top = 407
+    Width = 36
+    Height = 19
+    Caption = 'Play'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clWhite
+    Font.Height = -16
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object shpGameOver: TShape
+    Left = 8
+    Top = 161
+    Width = 385
+    Height = 88
+    Brush.Color = clBlack
+    Pen.Color = clWhite
+    Pen.Width = 5
+    Shape = stRoundRect
+  end
+  object lblGameOver: TLabel
+    Left = 18
+    Top = 168
+    Width = 365
+    Height = 75
+    Caption = 'Game Over'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clRed
+    Font.Height = -64
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object shpPower: TShape
+    Left = 272
+    Top = 432
+    Width = 69
+    Height = 25
+    Cursor = crHandPoint
+    Brush.Color = clLime
+    Pen.Color = clLime
+    Shape = stRoundRect
+    OnMouseDown = shpPowerMouseDown
+  end
+  object Label3: TLabel
+    Left = 280
+    Top = 407
+    Width = 52
+    Height = 19
+    Caption = 'Power'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clWhite
+    Font.Height = -16
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object Label4: TLabel
+    Left = 200
+    Top = 407
+    Width = 46
+    Height = 19
+    Caption = 'Score'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clWhite
+    Font.Height = -16
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object Shape2: TShape
+    Left = 192
+    Top = 432
+    Width = 65
+    Height = 25
+    Brush.Color = clBlack
+    Pen.Color = clWhite
+    Pen.Width = 5
+    Shape = stRoundRect
+  end
+  object lblScore: TLabel
+    Left = 206
+    Top = 438
+    Width = 39
+    Height = 14
+    Alignment = taCenter
+    AutoSize = False
+    Caption = '0'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clWhite
+    Font.Height = -11
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+  end
+  object shpMessage: TShape
+    Left = 8
+    Top = 161
+    Width = 385
+    Height = 88
+    Brush.Color = clBlack
+    Pen.Color = clWhite
+    Pen.Width = 5
+    Shape = stRoundRect
+    Visible = False
+  end
+  object lblMessage: TLabel
+    Left = 16
+    Top = 176
+    Width = 369
+    Height = 57
+    Alignment = taCenter
+    AutoSize = False
+    Caption = 'A Message!'
+    Font.Charset = ANSI_CHARSET
+    Font.Color = clLime
+    Font.Height = -48
+    Font.Name = 'Bookman Old Style'
+    Font.Style = [fsBold]
+    ParentFont = False
+    Visible = False
+  end
+end

+ 658 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/MainSimon.~pas

@@ -0,0 +1,658 @@
+unit MainSimon;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, ExtCtrls, Lua, LuaUtils, LAuxLib, LuaLib, Themes, UxTheme,
+  StdCtrls, MMSystem;
+
+const
+  // Light colors constants
+  LIGHT_NONE    = 0;
+  LIGHT_RED     = 1;
+  LIGHT_BLUE    = 2;
+  LIGHT_YELLOW  = 3;
+  LIGHT_GREEN   = 4;
+
+  // Turns constants
+  TURN_SIMON  = 1;
+  TURN_USER   = 2;
+
+type
+  TfrmMainSimon = class(TForm)
+    lblGreen: TLabel;
+    lblRed: TLabel;
+    lblBlue: TLabel;
+    lblYellow: TLabel;
+    Shape1: TShape;
+    Label1: TLabel;
+    shpPlay: TShape;
+    Label2: TLabel;
+    lblGameOver: TLabel;
+    shpGameOver: TShape;
+    shpPower: TShape;
+    Label3: TLabel;
+    Label4: TLabel;
+    Shape2: TShape;
+    lblScore: TLabel;
+    shpMessage: TShape;
+    lblMessage: TLabel;
+    procedure shpPowerMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure shpPlayMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblGreenMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblGreenMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblRedMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblRedMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblBlueMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblBlueMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure lblYellowMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+  private
+    { Private declarations }
+  public
+    { Public declarations }
+    function SetNoLight: Integer;
+    function SetRedLight: Integer;
+    function SetBlueLight: Integer;
+    function SetGreenLight: Integer;
+    function SetYellowLight: Integer;
+  end;
+
+var
+  frmMainSimon: TfrmMainSimon;
+  GameOver: Boolean;
+  Power: Boolean;
+  PlayHit: Boolean;
+  ControlsLock: Boolean;
+  MediaPath: String;
+  AppHandle: HWND;
+  SequenceCount: Integer;
+  MaxInterval: Integer;
+  LastClickInterval: Cardinal;
+  Score: Cardinal;
+  LuaState: Plua_State;
+
+// Other misc functions
+procedure SetAppHandle(Handle: HWND); cdecl;
+
+// LuaEdit debug hook function
+function LuaDebug_Initializer(L: PLua_State): Integer; cdecl;
+
+// Lua registred functions
+function DisplayMessage(L: Plua_State): Integer; cdecl;
+function LockControls(L: Plua_State): Integer; cdecl;
+function UnlockControls(L: Plua_State): Integer; cdecl;
+function SetScore(L: Plua_State): Integer; cdecl;
+function GetScore(L: Plua_State): Integer; cdecl;
+function GetPlayStatus(L: Plua_State): Integer; cdecl;
+function GetPowerStatus(L: Plua_State): Integer; cdecl;
+function GetUserSequence(L: Plua_State): Integer; cdecl;
+function SetMediaPath(L: Plua_State): Integer; cdecl;
+function SetLight(L: Plua_State): Integer; cdecl;
+function Create(L: Plua_State): Integer; cdecl;
+function Destroy(L: Plua_State): Integer; cdecl;
+function LuaSleep(L: Plua_State): Integer; cdecl;
+
+implementation
+
+{$R *.dfm}
+
+//////////////////////////////////////////////////////////////
+//  Miscellaneous exported functions
+//////////////////////////////////////////////////////////////
+
+procedure SetAppHandle(Handle: HWND);
+begin
+  AppHandle := Handle;
+end;
+
+//////////////////////////////////////////////////////////////
+//  LuaEdit debug hook function (simon.dll main entry function)
+//////////////////////////////////////////////////////////////
+
+// LuaEdit is calling this function everytime a script with a project
+// specifying this dll as the initializer when debugging
+function LuaDebug_Initializer(L: PLua_State): Integer;
+begin
+  // Create new table on the lua stack
+  lua_newtable(L);
+
+  // Register delphi functions in that new table
+  LuaRegisterCustom(L, -1, 'SetMediaPath', SetMediaPath);
+  LuaRegisterCustom(L, -1, 'SetLight', SetLight);
+  LuaRegisterCustom(L, -1, 'Create', Create);
+  LuaRegisterCustom(L, -1, 'Destroy', Destroy);
+  LuaRegisterCustom(L, -1, 'GetUserSequence', GetUserSequence);
+  LuaRegisterCustom(L, -1, 'GetPowerStatus', GetPowerStatus);
+  LuaRegisterCustom(L, -1, 'GetPlayStatus', GetPlayStatus);
+  LuaRegisterCustom(L, -1, 'SetScore', SetScore);
+  LuaRegisterCustom(L, -1, 'GetScore', GetScore);
+  LuaRegisterCustom(L, -1, 'LockControls', LockControls);
+  LuaRegisterCustom(L, -1, 'UnlockControls', UnlockControls);
+  LuaRegisterCustom(L, -1, 'DisplayMessage', DisplayMessage);
+
+  // Register other miscalleneous functions
+  LuaRegister(L, 'Sleep', LuaSleep);
+
+  // Assing "Simon" lua global variable to the new table
+  lua_setglobal(L, 'simon');
+  AppHandle := 0;
+  Result := 1;
+end;
+
+//////////////////////////////////////////////////////////////
+//  Lua registred functions
+//////////////////////////////////////////////////////////////
+
+function DisplayMessage(L: Plua_State): Integer;
+var
+  Msg, Color: String;
+  ShowTime: Integer;
+begin
+  Result := 1;
+  ShowTime := -1;
+  Msg := '';
+  Color := 'clWhite';
+
+  if lua_type(L, -3) = LUA_TSTRING then
+    Msg := lua_tostring(L, -3)
+  else
+    Result := 0;
+
+  if lua_type(L, -2) = LUA_TSTRING then
+    Color := lua_tostring(L, -2)
+  else
+    Result := 0;
+
+  if lua_type(L, -1) = LUA_TNUMBER then
+    ShowTime := Trunc(lua_tonumber(L, -1))
+  else
+    Result := 0;
+
+  if Result <> 0 then
+  begin
+    frmMainSimon.lblMessage.Caption := Msg;
+    frmMainSimon.lblMessage.Font.Color := StringToColor(Color);
+    frmMainSimon.lblMessage.Visible := True;
+    frmMainSimon.shpMessage.Visible := True;
+    Application.ProcessMessages;
+
+    if ShowTime > 0 then
+    begin
+      Sleep(ShowTime);
+      frmMainSimon.lblMessage.Visible := False;
+      frmMainSimon.shpMessage.Visible := False;
+    end;
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+function LockControls(L: Plua_State): Integer;
+begin
+  frmMainSimon.lblGreen.Cursor := crDefault;
+  frmMainSimon.lblRed.Cursor := crDefault;
+  frmMainSimon.lblBlue.Cursor := crDefault;
+  frmMainSimon.lblYellow.Cursor := crDefault;
+  frmMainSimon.shpPlay.Cursor := crDefault;
+  frmMainSimon.shpPower.Cursor := crDefault;
+  ControlsLock := True;
+  Application.ProcessMessages;
+  Result := 1;
+  lua_pushnumber(L, Result);
+end;
+
+function UnlockControls(L: Plua_State): Integer;
+begin
+  frmMainSimon.lblGreen.Cursor := crHandPoint;
+  frmMainSimon.lblRed.Cursor := crHandPoint;
+  frmMainSimon.lblBlue.Cursor := crHandPoint;
+  frmMainSimon.lblYellow.Cursor := crHandPoint;
+  frmMainSimon.shpPlay.Cursor := crHandPoint;
+  frmMainSimon.shpPower.Cursor := crHandPoint;
+  ControlsLock := False;
+  Application.ProcessMessages;
+  Result := 1;
+  lua_pushnumber(L, Result);
+end;
+
+function SetScore(L: Plua_State): Integer;
+var
+  NewScore: Cardinal;
+begin
+  Result := 1;
+  if lua_type(L, -1) = LUA_TNUMBER then
+    NewScore := Trunc(lua_tonumber(L, -1))
+  else
+    Result := 0;
+
+  if Result <> 0 then
+  begin
+    Score := NewScore;
+    frmMainSimon.lblScore.Caption := IntToStr(Score);
+    Application.ProcessMessages;
+  end;
+
+  lua_pushnumber(L, Score);
+end;
+
+function GetScore(L: Plua_State): Integer;
+begin
+  Result := 1;
+  lua_pushnumber(L, Score);
+end;
+
+function GetPlayStatus(L: Plua_State): Integer;
+begin
+  Result := Integer(PlayHit);
+  PlayHit := False;
+  lua_pushnumber(L, Result);
+end;
+
+function GetPowerStatus(L: Plua_State): Integer;
+begin
+  Result := Integer(Power);
+  lua_pushnumber(L, Result);
+end;
+
+function GetUserSequence(L: Plua_State): Integer;
+var
+  SequenceLength: Integer;
+begin
+  Result := 1;
+  SequenceCount := 0;
+  LastClickInterval := GetTickCount();
+  GameOver := False;
+
+  if lua_type(L, -2) = LUA_TNUMBER then
+    SequenceLength := Trunc(lua_tonumber(L, -2))
+  else
+    Result := 0;
+
+  if lua_type(L, -1) = LUA_TNUMBER then
+    MaxInterval := Trunc(lua_tonumber(L, -1))
+  else
+    Result := 0;
+
+  if Result <> 0 then
+  begin
+    while (Power and (not GameOver) and (SequenceCount < SequenceLength)) do
+    begin
+      if ((GetTickCount() - LastClickInterval) >= MaxInterval) then
+        GameOver := True;
+
+      Application.ProcessMessages;
+      Sleep(10);
+    end;
+  end;
+
+  if GameOver then
+  begin
+    frmMainSimon.lblGameOver.Visible := True;
+    frmMainSimon.shpGameOver.Visible := True;
+    Application.ProcessMessages;
+    Result := 0;
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+function SetMediaPath(L: Plua_State): Integer;
+var
+  sMediaPath: String;
+begin
+  Result := 0;
+  sMediaPath := '';
+
+  // Retreive last and only one lua argument from lua stack (string)
+  if lua_type(L, -1) = LUA_TSTRING then
+    sMediaPath := lua_tostring(L, -1);
+
+  // Set media path if any
+  if DirectoryExists(sMediaPath) then
+  begin
+    MediaPath := sMediaPath;
+    Result := 1;
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+function SetLight(L: Plua_State): Integer;
+var
+  Color: Integer;
+begin
+  Result := 0;
+  Color := -1;
+
+  // Retreive last and only one lua argument from lua stack (Integer or nil)
+  if lua_type(L, -1) = LUA_TNUMBER then
+    Color := Trunc(lua_tonumber(L, -1))
+  else if lua_type(L, -1) = LUA_TNIL then
+    Color := 0;
+  
+  case Color of
+    LIGHT_NONE:   Result := frmMainSimon.SetNoLight();
+    LIGHT_RED:    Result := frmMainSimon.SetRedLight();
+    LIGHT_BLUE:   Result := frmMainSimon.SetBlueLight();
+    LIGHT_YELLOW: Result := frmMainSimon.SetYellowLight();
+    LIGHT_GREEN:  Result := frmMainSimon.SetGreenLight();
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+function Create(L: Plua_State): Integer;
+var
+  Style: Integer;
+begin
+  // leave those important lines here...
+  // There is a bug with the themes and forms placed in dll
+  // The dll don't have the time to free the theme handle and the when it does it,
+  // the hoset application (LuaEdit) already did it so... Runtime Error 216
+  ThemeServices.ApplyThemeChange;
+  InitThemeLibrary;
+  Result := -1;
+  Style := -1;
+  GameOver := False;
+  Power := True;
+  Score := 0;
+
+  // Retreive optional parameter (create style)
+  if lua_type(L, -1) = LUA_TNUMBER then
+    Style := Trunc(lua_tonumber(L, -1));
+
+  if not Assigned(frmMainSimon) then
+  begin
+    if AppHandle = 0 then
+      AppHandle := GetActiveWindow();
+
+    LuaState := L;
+    Application.Handle := AppHandle;
+    //frmMainSimon := TfrmMainSimon.Create(Application);
+    frmMainSimon := TfrmMainSimon.CreateParented(0);
+
+    case Style of
+      1: frmMainSimon.BorderStyle := bsSizeable;
+      2: frmMainSimon.BorderStyle := bsSizeToolWin;
+    else
+      frmMainSimon.BorderStyle := bsNone;
+    end;
+
+    frmMainSimon.lblGameOver.Visible := False;
+    frmMainSimon.shpGameOver.Visible := False;
+    Application.ProcessMessages;
+    Result := 1;
+  end;
+
+  if Result = 1 then
+  begin
+    frmMainSimon.Show;
+    frmMainSimon.BringToFront;
+    Application.ProcessMessages;
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+function Destroy(L: Plua_State): Integer;
+begin
+  Result := -1;
+
+  if Assigned(frmMainSimon) then
+  begin
+    LuaState := nil;
+    frmMainSimon.Close;
+    SetParent(frmMainSimon.Handle, 0);
+    FreeAndNil(frmMainSimon);
+    Application.ProcessMessages;
+    Result := 1;
+  end;
+
+  // leave those important lines here...
+  // There is a bug with the themes and forms placed in dll
+  // The dll don't have the time to free the theme handle and the when it does it,
+  // the hoset application (LuaEdit) already did it so... Runtime Error 216
+  ThemeServices.ApplyThemeChange;
+  FreeThemeLibrary;
+  lua_pushnumber(L, Result);
+end;
+
+function LuaSleep(L: Plua_State): Integer; cdecl;
+var
+  Length: Integer;
+begin
+  Result := 0;
+  Length := -1;
+
+  // Retreive last and only one lua argument from lua stack (Integer or nil)
+  if lua_type(L, -1) = LUA_TNUMBER then
+    Length := Trunc(lua_tonumber(L, -1));
+
+  if Length > 0 then
+  begin
+    Result := 1;
+    Sleep(Length);
+  end;
+
+  lua_pushnumber(L, Result);
+end;
+
+//////////////////////////////////////////////////////////////
+//  TfrmMainSimon implementation
+//////////////////////////////////////////////////////////////
+
+function TfrmMainSimon.SetNoLight: Integer;
+begin
+  lblBlue.Color := clNavy;
+  lblRed.Color := clMaroon;
+  lblYellow.Color := clOlive;
+  lblGreen.Color := clGreen;
+  Result := 1;
+end;
+
+function TfrmMainSimon.SetRedLight: Integer;
+begin
+  PlaySound(PChar(MediaPath + '\01.wav'), 0, SND_FILENAME or SND_NODEFAULT or SND_ASYNC);
+  lblBlue.Color := clNavy;
+  lblRed.Color := clRed;
+  lblYellow.Color := clOlive;
+  lblGreen.Color := clGreen;
+  Result := 1;
+end;
+
+function TfrmMainSimon.SetBlueLight: Integer;
+begin
+  PlaySound(PChar(MediaPath + '\02.wav'), 0, SND_FILENAME or SND_NODEFAULT or SND_ASYNC);
+  lblBlue.Color := clBlue;
+  lblRed.Color := clMaroon;
+  lblYellow.Color := clOlive;
+  lblGreen.Color := clGreen;
+  Result := 1;
+end;
+
+function TfrmMainSimon.SetGreenLight: Integer;
+begin
+  PlaySound(PChar(MediaPath + '\03.wav'), 0, SND_FILENAME or SND_NODEFAULT or SND_ASYNC);
+  lblBlue.Color := clNavy;
+  lblRed.Color := clMaroon;
+  lblYellow.Color := clOlive;
+  lblGreen.Color := clLime;
+  Result := 1;
+end;
+
+function TfrmMainSimon.SetYellowLight: Integer;
+begin
+  PlaySound(PChar(MediaPath + '\04.wav'), 0, SND_FILENAME or SND_NODEFAULT or SND_ASYNC);
+  lblBlue.Color := clNavy;
+  lblRed.Color := clMaroon;
+  lblYellow.Color := clYellow;
+  lblGreen.Color := clGreen;
+  Result := 1;
+end;
+
+procedure TfrmMainSimon.shpPowerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  if not ControlsLock then
+  begin
+    ShpPower.Brush.Color := clSilver;
+    ShpPower.Pen.Color := clSilver;
+    Application.ProcessMessages;
+    Power := False;
+    GameOver := True;
+    Sleep(500);
+  end;
+end;
+
+procedure TfrmMainSimon.shpPlayMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  if not ControlsLock then
+  begin
+    PlayHit := True;
+    shpGameOver.Visible := False;
+    lblGameOver.Visible := False;
+    Application.ProcessMessages;
+  end;
+end;
+
+procedure TfrmMainSimon.lblGreenMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  if not ControlsLock then
+  begin
+    SetGreenLight;
+    Application.ProcessMessages;    
+  end;
+end;
+
+procedure TfrmMainSimon.lblGreenMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var
+  TimeDiff: Cardinal;
+begin
+  if not ControlsLock then
+  begin
+    Inc(SequenceCount);
+    TimeDiff := GetTickCount() - LastClickInterval;
+
+    if TimeDiff <= MaxInterval then
+    begin
+      // Calling OnButtonClick lua event handler
+      lua_pushstring(LuaState, 'simon');
+      lua_gettable(LuaState, LUA_GLOBALSINDEX);
+      lua_pushstring(LuaState, 'OnButtonClick');
+      lua_gettable(LuaState, -2);
+      lua_pushnumber(LuaState, LIGHT_GREEN);
+      lua_pushnumber(LuaState, LIGHT_GREEN);
+      lua_pushnumber(LuaState, TimeDiff);
+      lua_call(LuaState, 3, 1);
+      GameOver := (Trunc(lua_tonumber(LuaState, -1)) = 0);
+
+      LastClickInterval := GetTickCount();
+    end
+    else
+      GameOver := True;
+
+    SetNoLight;
+  end;
+end;
+
+procedure TfrmMainSimon.lblRedMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  if not ControlsLock then
+  begin
+    SetRedLight;
+    Application.ProcessMessages;
+  end;
+end;
+
+procedure TfrmMainSimon.lblRedMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var
+  TimeDiff: Cardinal;
+begin
+  if not ControlsLock then
+  begin
+    Inc(SequenceCount);
+    TimeDiff := GetTickCount() - LastClickInterval;
+
+    if TimeDiff <= MaxInterval then
+    begin
+      // Calling OnButtonClick lua event handler
+      lua_pushstring(LuaState, 'simon');
+      lua_gettable(LuaState, LUA_GLOBALSINDEX);
+      lua_pushstring(LuaState, 'OnButtonClick');
+      lua_gettable(LuaState, -2);
+      lua_pushnumber(LuaState, LIGHT_RED);
+      lua_pushnumber(LuaState, LIGHT_RED);
+      lua_pushnumber(LuaState, TimeDiff);
+      lua_call(LuaState, 3, 1);
+      GameOver := (Trunc(lua_tonumber(LuaState, -1)) = 0);
+
+      LastClickInterval := GetTickCount();
+    end
+    else
+      GameOver := True;
+
+    SetNoLight;
+  end;
+end;
+
+procedure TfrmMainSimon.lblBlueMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  if not ControlsLock then
+  begin
+    SetBlueLight;
+    Application.ProcessMessages;
+  end;
+end;
+
+procedure TfrmMainSimon.lblBlueMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var
+  TimeDiff: Cardinal;
+begin
+  if not ControlsLock then
+  begin
+    Inc(SequenceCount);
+    TimeDiff := GetTickCount() - LastClickInterval;
+
+    if TimeDiff <= MaxInterval then
+    begin
+      // Calling OnButtonClick lua event handler
+      lua_pushstring(LuaState, 'simon');
+      lua_gettable(LuaState, LUA_GLOBALSINDEX);
+      lua_pushstring(LuaState, 'OnButtonClick');
+      lua_gettable(LuaState, -2);
+      lua_pushnumber(LuaState, LIGHT_BLUE);
+      lua_pushnumber(LuaState, LIGHT_BLUE);
+      lua_pushnumber(LuaState, TimeDiff);
+      lua_call(LuaState, 3, 1);
+      GameOver := (Trunc(lua_tonumber(LuaState, -1)) = 0);
+
+      LastClickInterval := GetTickCount();
+    end
+    else
+      GameOver := True;
+
+    SetNoLight;
+  end;
+end;
+
+procedure TfrmMainSimon.lblYellowMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var
+  TimeDiff: Cardinal;
+begin
+  if not ControlsLock then
+  begin
+    SetYellowLight;
+    Application.ProcessMessages;
+  end;
+end;
+
+end.

+ 44 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.cfg

@@ -0,0 +1,44 @@
+-$A8
+-$B-
+-$C-
+-$D-
+-$E-
+-$F-
+-$G+
+-$H+
+-$I-
+-$J-
+-$K-
+-$L+
+-$M-
+-$N+
+-$O-
+-$P+
+-$Q-
+-$R-
+-$S-
+-$T-
+-$U-
+-$V+
+-$W-
+-$X+
+-$Y-
+-$Z1
+-GD
+-cg
+-AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
+-H+
+-W+
+-M
+-$M16384,1048576
+-K$00400000
+-E"..\bin"
+-LE"c:\program files\borland\delphi7\Projects\Bpl"
+-LN"c:\program files\borland\delphi7\Projects\Bpl"
+-U".\LuaCore"
+-O".\LuaCore"
+-I".\LuaCore"
+-R".\LuaCore"
+-w-UNSAFE_TYPE
+-w-UNSAFE_CODE
+-w-UNSAFE_CAST

+ 152 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.dof

@@ -0,0 +1,152 @@
+[FileVersion]
+Version=7.0
+[Compiler]
+A=8
+B=0
+C=0
+D=0
+E=0
+F=0
+G=1
+H=1
+I=0
+J=0
+K=0
+L=1
+M=0
+N=1
+O=0
+P=1
+Q=0
+R=0
+S=0
+T=0
+U=0
+V=1
+W=0
+X=1
+Y=0
+Z=1
+ShowHints=1
+ShowWarnings=1
+UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
+NamespacePrefix=
+SymbolDeprecated=1
+SymbolLibrary=1
+SymbolPlatform=1
+UnitLibrary=1
+UnitPlatform=1
+UnitDeprecated=1
+HResultCompat=1
+HidingMember=1
+HiddenVirtual=1
+Garbage=1
+BoundsError=1
+ZeroNilCompat=1
+StringConstTruncated=1
+ForLoopVarVarPar=1
+TypedConstVarPar=1
+AsgToTypedConst=1
+CaseLabelRange=1
+ForVariable=1
+ConstructingAbstract=1
+ComparisonFalse=1
+ComparisonTrue=1
+ComparingSignedUnsigned=1
+CombiningSignedUnsigned=1
+UnsupportedConstruct=1
+FileOpen=1
+FileOpenUnitSrc=1
+BadGlobalSymbol=1
+DuplicateConstructorDestructor=1
+InvalidDirective=1
+PackageNoLink=1
+PackageThreadVar=1
+ImplicitImport=1
+HPPEMITIgnored=1
+NoRetVal=1
+UseBeforeDef=1
+ForLoopVarUndef=1
+UnitNameMismatch=1
+NoCFGFileFound=1
+MessageDirective=1
+ImplicitVariants=1
+UnicodeToLocale=1
+LocaleToUnicode=1
+ImagebaseMultiple=1
+SuspiciousTypecast=1
+PrivatePropAccessor=1
+UnsafeType=0
+UnsafeCode=0
+UnsafeCast=0
+[Linker]
+MapFile=3
+OutputObjs=0
+ConsoleApp=1
+DebugInfo=0
+RemoteSymbols=0
+MinStackSize=16384
+MaxStackSize=1048576
+ImageBase=4194304
+ExeDescription=
+[Directories]
+OutputDir=..\bin
+UnitOutputDir=
+PackageDLLOutputDir=
+PackageDCPOutputDir=
+SearchPath=.\LuaCore
+Packages=vcl;rtl;vclx;indy;inet;xmlrtl;vclie;inetdbbde;inetdbxpress;dbrtl;dsnap;dsnapcon;vcldb;soaprtl;VclSmp;dbexpress;dbxcds;inetdb;bdertl;vcldbx;webdsnap;websnap;adortl;ibxpress;teeui;teedb;tee;dss;visualclx;visualdbclx;vclactnband;vclshlctrls;IntrawebDB_50_70;Intraweb_50_70;Rave50CLX;Rave50VCL;dclOfficeXP;SynEdit_R7;VirtualTreesD7;DJcl;JvStdCtrlsD7R;JvAppFrmD7R;JvCoreD7R;JvBandsD7R;JvBDED7R;JvDBD7R;JvDlgsD7R;JvCmpD7R;JvCryptD7R;JvCtrlsD7R;JvCustomD7R;JvDockingD7R;JvDotNetCtrlsD7R;JvEDID7R;qrpt;JvGlobusD7R;JvHMID7R;JvInterpreterD7R;JvJansD7R;JvManagedThreadsD7R;JvMMD7R;JvNetD7R;JvPageCompsD7R;JvPluginD7R;JvPrintPreviewD7R;JvRuntimeDesignD7R;JvSystemD7R;JvTimeFrameworkD7R;JvUIBD7R;JvValidatorsD7R;JvWizardD7R;JvXPCtrlsD7R;ExtLib_D6
+Conditionals=
+DebugSourceDirs=
+UsePackages=0
+[Parameters]
+RunParams="C:\Prog\Delphi\MNet\Bin\Simon.lpr"
+HostApplication=C:\Program Files\LuaEdit\LuaEdit.exe
+Launcher=
+UseLauncher=0
+DebugCWD=
+[Language]
+ActiveLang=
+ProjectLang=
+RootDir=
+[Version Info]
+IncludeVerInfo=1
+AutoIncBuild=1
+MajorVer=1
+MinorVer=0
+Release=1
+Build=60
+Debug=0
+PreRelease=0
+Special=0
+Private=0
+DLL=0
+Locale=4105
+CodePage=1252
+[Version Info Keys]
+CompanyName=Open Source Intuitive
+FileDescription=The classic Simon game engine
+FileVersion=1.0.1.60
+InternalName=Simon Game
+LegalCopyright=Jean-Francois Goulet (C) 2005
+LegalTrademarks=
+OriginalFilename=
+ProductName=Simon Game
+ProductVersion=1.0.0.0
+Comments=
+[HistoryLists\hlUnitAliases]
+Count=1
+Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
+[HistoryLists\hlSearchPath]
+Count=6
+Item0=..\LuaCore
+Item1=C:\Prog\Delphi\MNet\LuaCore
+Item2=$(DELPHI)\Lib\Debug;C:\Prog\Delphi\COMPON~1\JEDI\jcl\lib\D7\debug;C:\Prog\Delphi\MNet\LuaCore
+Item3=$(DELPHI)\Lib\Debug;C:\Prog\Delphi\COMPON~1\JEDI\jcl\lib\D7\debug
+Item4=$(DELPHI)\Lib\Debug;C:\Prog\Delphi\Component\JEDI\jcl\lib\D7\debug;C:\Prog\Delphi\COMPON~1\JEDI\jcl\lib\D7\debug;C:\Prog\Delphi\MNet\LuaCore
+Item5=$(DELPHI)\Lib\Debug;C:\Prog\Delphi\Component\JEDI\jcl\lib\D7\debug;C:\Prog\Delphi\COMPON~1\JEDI\jcl\lib\D7\debug
+[HistoryLists\hlOutputDirectorry]
+Count=3
+Item0=..\..\bin
+Item1=..\Bin
+Item2=.\bin

+ 26 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.dpr

@@ -0,0 +1,26 @@
+library Simon;
+
+{ Important note about DLL memory management: ShareMem must be the
+  first unit in your library's USES clause AND your project's (select
+  Project-View Source) USES clause if your DLL exports any procedures or
+  functions that pass strings as parameters or function results. This
+  applies to all strings passed to and from your DLL--even those that
+  are nested in records and classes. ShareMem is the interface unit to
+  the BORLNDMM.DLL shared memory manager, which must be deployed along
+  with your DLL. To avoid using BORLNDMM.DLL, pass string information
+  using PChar or ShortString parameters. }
+
+uses
+  SysUtils,
+  Classes,
+  MainSimon in 'MainSimon.pas' {frmMainSimon};
+
+{$R *.res}
+
+exports
+  LuaDebug_Initializer, SetLight, Create, Destroy, SetMediaPath,
+  GetUserSequence, GetPowerStatus, GetPlayStatus, SetScore, GetScore,
+  LockControls, UnlockControls, DisplayMessage, SetAppHandle, LuaSleep;
+
+begin
+end.

+ 528 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.drc

@@ -0,0 +1,528 @@
+/* VER150
+  Generated by the Borland Delphi Pascal Compiler
+  because -GD or --drc was supplied to the compiler.
+
+  This file contains compiler-generated resources that
+  were bound to the executable.
+  If this file is empty, then no compiler-generated
+  resources were bound to the produced executable.
+*/
+
+#define ComConst_STooManyParams 65264
+#define ExtCtrls_clNameInactiveCaptionText 65280
+#define ExtCtrls_clNameInfoBk 65281
+#define ExtCtrls_clNameInfoText 65282
+#define ExtCtrls_clNameMenu 65283
+#define ExtCtrls_clNameMenuText 65284
+#define ExtCtrls_clNameNone 65285
+#define ExtCtrls_clNameScrollBar 65286
+#define ExtCtrls_clName3DDkShadow 65287
+#define ExtCtrls_clName3DLight 65288
+#define ExtCtrls_clNameWindow 65289
+#define ExtCtrls_clNameWindowFrame 65290
+#define ExtCtrls_clNameWindowText 65291
+#define WinHelpViewer_hNoKeyword 65292
+#define ComConst_SOleError 65293
+#define ComConst_SNoMethod 65294
+#define ComConst_SVarNotObject 65295
+#define ExtCtrls_clNameMedGray 65296
+#define ExtCtrls_clNameActiveBorder 65297
+#define ExtCtrls_clNameActiveCaption 65298
+#define ExtCtrls_clNameAppWorkSpace 65299
+#define ExtCtrls_clNameBackground 65300
+#define ExtCtrls_clNameBtnFace 65301
+#define ExtCtrls_clNameBtnHighlight 65302
+#define ExtCtrls_clNameBtnShadow 65303
+#define ExtCtrls_clNameBtnText 65304
+#define ExtCtrls_clNameCaptionText 65305
+#define ExtCtrls_clNameDefault 65306
+#define ExtCtrls_clNameGrayText 65307
+#define ExtCtrls_clNameHighlight 65308
+#define ExtCtrls_clNameHighlightText 65309
+#define ExtCtrls_clNameInactiveBorder 65310
+#define ExtCtrls_clNameInactiveCaption 65311
+#define ExtCtrls_clNameOlive 65312
+#define ExtCtrls_clNameNavy 65313
+#define ExtCtrls_clNamePurple 65314
+#define ExtCtrls_clNameTeal 65315
+#define ExtCtrls_clNameGray 65316
+#define ExtCtrls_clNameSilver 65317
+#define ExtCtrls_clNameRed 65318
+#define ExtCtrls_clNameLime 65319
+#define ExtCtrls_clNameYellow 65320
+#define ExtCtrls_clNameBlue 65321
+#define ExtCtrls_clNameFuchsia 65322
+#define ExtCtrls_clNameAqua 65323
+#define ExtCtrls_clNameWhite 65324
+#define ExtCtrls_clNameMoneyGreen 65325
+#define ExtCtrls_clNameSkyBlue 65326
+#define ExtCtrls_clNameCream 65327
+#define Consts_SmkcShift 65328
+#define Consts_SmkcCtrl 65329
+#define Consts_SmkcAlt 65330
+#define Consts_SIconToClipboard 65331
+#define Consts_SDuplicateMenus 65332
+#define Consts_SDockedCtlNeedsName 65333
+#define Consts_SDockTreeRemoveError 65334
+#define Consts_SDockZoneNotFound 65335
+#define Consts_SDockZoneHasNoCtl 65336
+#define HelpIntfs_hNoTableOfContents 65337
+#define HelpIntfs_hNothingFound 65338
+#define HelpIntfs_hNoContext 65339
+#define HelpIntfs_hNoTopics 65340
+#define ExtCtrls_clNameBlack 65341
+#define ExtCtrls_clNameMaroon 65342
+#define ExtCtrls_clNameGreen 65343
+#define Consts_SMsgDlgYesToAll 65344
+#define Consts_SmkcBkSp 65345
+#define Consts_SmkcTab 65346
+#define Consts_SmkcEsc 65347
+#define Consts_SmkcEnter 65348
+#define Consts_SmkcSpace 65349
+#define Consts_SmkcPgUp 65350
+#define Consts_SmkcPgDn 65351
+#define Consts_SmkcEnd 65352
+#define Consts_SmkcHome 65353
+#define Consts_SmkcLeft 65354
+#define Consts_SmkcUp 65355
+#define Consts_SmkcRight 65356
+#define Consts_SmkcDown 65357
+#define Consts_SmkcIns 65358
+#define Consts_SmkcDel 65359
+#define Consts_SVIcons 65360
+#define Consts_SVBitmaps 65361
+#define Consts_SMsgDlgWarning 65362
+#define Consts_SMsgDlgError 65363
+#define Consts_SMsgDlgInformation 65364
+#define Consts_SMsgDlgConfirm 65365
+#define Consts_SMsgDlgYes 65366
+#define Consts_SMsgDlgNo 65367
+#define Consts_SMsgDlgOK 65368
+#define Consts_SMsgDlgCancel 65369
+#define Consts_SMsgDlgHelp 65370
+#define Consts_SMsgDlgAbort 65371
+#define Consts_SMsgDlgRetry 65372
+#define Consts_SMsgDlgIgnore 65373
+#define Consts_SMsgDlgAll 65374
+#define Consts_SMsgDlgNoToAll 65375
+#define Consts_SGroupIndexTooLow 65376
+#define Consts_SNoMDIForm 65377
+#define Consts_SControlParentSetToSelf 65378
+#define Consts_SOKButton 65379
+#define Consts_SCancelButton 65380
+#define Consts_SYesButton 65381
+#define Consts_SNoButton 65382
+#define Consts_SHelpButton 65383
+#define Consts_SCloseButton 65384
+#define Consts_SIgnoreButton 65385
+#define Consts_SRetryButton 65386
+#define Consts_SAbortButton 65387
+#define Consts_SAllButton 65388
+#define Consts_SCannotDragForm 65389
+#define Consts_SVMetafiles 65390
+#define Consts_SVEnhMetafiles 65391
+#define Consts_SInvalidImageSize 65392
+#define Consts_SInvalidImageList 65393
+#define Consts_SImageIndexError 65394
+#define Consts_SImageReadFail 65395
+#define Consts_SImageWriteFail 65396
+#define Consts_SWindowDCError 65397
+#define Consts_SWindowClass 65398
+#define Consts_SCannotFocus 65399
+#define Consts_SParentRequired 65400
+#define Consts_SMDIChildNotVisible 65401
+#define Consts_SVisibleChanged 65402
+#define Consts_SCannotShowModal 65403
+#define Consts_SMenuIndexError 65404
+#define Consts_SMenuReinserted 65405
+#define Consts_SMenuNotFound 65406
+#define Consts_SNoTimers 65407
+#define RTLConsts_SReadError 65408
+#define RTLConsts_SReadOnlyProperty 65409
+#define RTLConsts_SResNotFound 65410
+#define RTLConsts_SSeekNotImplemented 65411
+#define RTLConsts_SSortedListError 65412
+#define RTLConsts_SUnknownGroup 65413
+#define RTLConsts_SUnknownProperty 65414
+#define RTLConsts_SWriteError 65415
+#define Consts_SInvalidBitmap 65416
+#define Consts_SInvalidIcon 65417
+#define Consts_SInvalidMetafile 65418
+#define Consts_SChangeIconSize 65419
+#define Consts_SOleGraphic 65420
+#define Consts_SUnknownClipboardFormat 65421
+#define Consts_SOutOfResources 65422
+#define Consts_SNoCanvasHandle 65423
+#define RTLConsts_SClassNotFound 65424
+#define RTLConsts_SDuplicateClass 65425
+#define RTLConsts_SDuplicateItem 65426
+#define RTLConsts_SDuplicateName 65427
+#define RTLConsts_SDuplicateString 65428
+#define RTLConsts_SFCreateErrorEx 65429
+#define RTLConsts_SFOpenErrorEx 65430
+#define RTLConsts_SInvalidImage 65431
+#define RTLConsts_SInvalidName 65432
+#define RTLConsts_SInvalidPropertyPath 65433
+#define RTLConsts_SInvalidPropertyValue 65434
+#define RTLConsts_SListCapacityError 65435
+#define RTLConsts_SListCountError 65436
+#define RTLConsts_SListIndexError 65437
+#define RTLConsts_SMemoryStreamError 65438
+#define RTLConsts_SPropertyException 65439
+#define SysConst_SShortDayNameWed 65440
+#define SysConst_SShortDayNameThu 65441
+#define SysConst_SShortDayNameFri 65442
+#define SysConst_SShortDayNameSat 65443
+#define SysConst_SLongDayNameSun 65444
+#define SysConst_SLongDayNameMon 65445
+#define SysConst_SLongDayNameTue 65446
+#define SysConst_SLongDayNameWed 65447
+#define SysConst_SLongDayNameThu 65448
+#define SysConst_SLongDayNameFri 65449
+#define SysConst_SLongDayNameSat 65450
+#define RTLConsts_SAncestorNotFound 65451
+#define RTLConsts_SAssignError 65452
+#define RTLConsts_SBitsIndexError 65453
+#define RTLConsts_SCantWriteResourceStreamError 65454
+#define RTLConsts_SCheckSynchronizeError 65455
+#define SysConst_SShortMonthNameDec 65456
+#define SysConst_SLongMonthNameJan 65457
+#define SysConst_SLongMonthNameFeb 65458
+#define SysConst_SLongMonthNameMar 65459
+#define SysConst_SLongMonthNameApr 65460
+#define SysConst_SLongMonthNameMay 65461
+#define SysConst_SLongMonthNameJun 65462
+#define SysConst_SLongMonthNameJul 65463
+#define SysConst_SLongMonthNameAug 65464
+#define SysConst_SLongMonthNameSep 65465
+#define SysConst_SLongMonthNameOct 65466
+#define SysConst_SLongMonthNameNov 65467
+#define SysConst_SLongMonthNameDec 65468
+#define SysConst_SShortDayNameSun 65469
+#define SysConst_SShortDayNameMon 65470
+#define SysConst_SShortDayNameTue 65471
+#define SysConst_SAssertError 65472
+#define SysConst_SAbstractError 65473
+#define SysConst_SModuleAccessViolation 65474
+#define SysConst_SOSError 65475
+#define SysConst_SUnkOSError 65476
+#define SysConst_SShortMonthNameJan 65477
+#define SysConst_SShortMonthNameFeb 65478
+#define SysConst_SShortMonthNameMar 65479
+#define SysConst_SShortMonthNameApr 65480
+#define SysConst_SShortMonthNameMay 65481
+#define SysConst_SShortMonthNameJun 65482
+#define SysConst_SShortMonthNameJul 65483
+#define SysConst_SShortMonthNameAug 65484
+#define SysConst_SShortMonthNameSep 65485
+#define SysConst_SShortMonthNameOct 65486
+#define SysConst_SShortMonthNameNov 65487
+#define SysConst_SVarArrayBounds 65488
+#define SysConst_SVarArrayLocked 65489
+#define SysConst_SInvalidVarCast 65490
+#define SysConst_SInvalidVarOp 65491
+#define SysConst_SInvalidVarOpWithHResultWithPrefix 65492
+#define SysConst_SVarTypeCouldNotConvert 65493
+#define SysConst_SVarTypeConvertOverflow 65494
+#define SysConst_SVarOverflow 65495
+#define SysConst_SVarInvalid 65496
+#define SysConst_SVarBadType 65497
+#define SysConst_SVarNotImplemented 65498
+#define SysConst_SVarUnexpected 65499
+#define SysConst_SExternalException 65500
+#define SysConst_SAssertionFailed 65501
+#define SysConst_SIntfCastError 65502
+#define SysConst_SSafecallException 65503
+#define SysConst_SUnderflow 65504
+#define SysConst_SInvalidPointer 65505
+#define SysConst_SInvalidCast 65506
+#define SysConst_SAccessViolationArg3 65507
+#define SysConst_SAccessViolationNoArg 65508
+#define SysConst_SStackOverflow 65509
+#define SysConst_SControlC 65510
+#define SysConst_SPrivilege 65511
+#define SysConst_SException 65512
+#define SysConst_SExceptTitle 65513
+#define SysConst_SInvalidFormat 65514
+#define SysConst_SArgumentMissing 65515
+#define SysConst_SDispatchError 65516
+#define SysConst_SReadAccess 65517
+#define SysConst_SWriteAccess 65518
+#define SysConst_SVarArrayCreate 65519
+#define SysConst_SInvalidInteger 65520
+#define SysConst_SOutOfMemory 65521
+#define SysConst_SInOutError 65522
+#define SysConst_SFileNotFound 65523
+#define SysConst_SInvalidFilename 65524
+#define SysConst_STooManyOpenFiles 65525
+#define SysConst_SAccessDenied 65526
+#define SysConst_SEndOfFile 65527
+#define SysConst_SDiskFull 65528
+#define SysConst_SInvalidInput 65529
+#define SysConst_SDivByZero 65530
+#define SysConst_SRangeError 65531
+#define SysConst_SIntOverflow 65532
+#define SysConst_SInvalidOp 65533
+#define SysConst_SZeroDivide 65534
+#define SysConst_SOverflow 65535
+STRINGTABLE
+BEGIN
+	ComConst_STooManyParams,	"Dispatch methods do not support more than 64 parameters"
+	ExtCtrls_clNameInactiveCaptionText,	"Inactive Caption Text"
+	ExtCtrls_clNameInfoBk,	"Info Background"
+	ExtCtrls_clNameInfoText,	"Info Text"
+	ExtCtrls_clNameMenu,	"Menu Background"
+	ExtCtrls_clNameMenuText,	"Menu Text"
+	ExtCtrls_clNameNone,	"None"
+	ExtCtrls_clNameScrollBar,	"Scroll Bar"
+	ExtCtrls_clName3DDkShadow,	"3D Dark Shadow"
+	ExtCtrls_clName3DLight,	"3D Light"
+	ExtCtrls_clNameWindow,	"Window Background"
+	ExtCtrls_clNameWindowFrame,	"Window Frame"
+	ExtCtrls_clNameWindowText,	"Window Text"
+	WinHelpViewer_hNoKeyword,	"No help keyword specified."
+	ComConst_SOleError,	"OLE error %.8x"
+	ComConst_SNoMethod,	"Method '%s' not supported by automation object"
+	ComConst_SVarNotObject,	"Variant does not reference an automation object"
+	ExtCtrls_clNameMedGray,	"Medium Gray"
+	ExtCtrls_clNameActiveBorder,	"Active Border"
+	ExtCtrls_clNameActiveCaption,	"Active Caption"
+	ExtCtrls_clNameAppWorkSpace,	"Application Workspace"
+	ExtCtrls_clNameBackground,	"Background"
+	ExtCtrls_clNameBtnFace,	"Button Face"
+	ExtCtrls_clNameBtnHighlight,	"Button Highlight"
+	ExtCtrls_clNameBtnShadow,	"Button Shadow"
+	ExtCtrls_clNameBtnText,	"Button Text"
+	ExtCtrls_clNameCaptionText,	"Caption Text"
+	ExtCtrls_clNameDefault,	"Default"
+	ExtCtrls_clNameGrayText,	"Gray Text"
+	ExtCtrls_clNameHighlight,	"Highlight Background"
+	ExtCtrls_clNameHighlightText,	"Highlight Text"
+	ExtCtrls_clNameInactiveBorder,	"Inactive Border"
+	ExtCtrls_clNameInactiveCaption,	"Inactive Caption"
+	ExtCtrls_clNameOlive,	"Olive"
+	ExtCtrls_clNameNavy,	"Navy"
+	ExtCtrls_clNamePurple,	"Purple"
+	ExtCtrls_clNameTeal,	"Teal"
+	ExtCtrls_clNameGray,	"Gray"
+	ExtCtrls_clNameSilver,	"Silver"
+	ExtCtrls_clNameRed,	"Red"
+	ExtCtrls_clNameLime,	"Lime"
+	ExtCtrls_clNameYellow,	"Yellow"
+	ExtCtrls_clNameBlue,	"Blue"
+	ExtCtrls_clNameFuchsia,	"Fuchsia"
+	ExtCtrls_clNameAqua,	"Aqua"
+	ExtCtrls_clNameWhite,	"White"
+	ExtCtrls_clNameMoneyGreen,	"Money Green"
+	ExtCtrls_clNameSkyBlue,	"Sky Blue"
+	ExtCtrls_clNameCream,	"Cream"
+	Consts_SmkcShift,	"Shift+"
+	Consts_SmkcCtrl,	"Ctrl+"
+	Consts_SmkcAlt,	"Alt+"
+	Consts_SIconToClipboard,	"Clipboard does not support Icons"
+	Consts_SDuplicateMenus,	"Menu '%s' is already being used by another form"
+	Consts_SDockedCtlNeedsName,	"Docked control must have a name"
+	Consts_SDockTreeRemoveError,	"Error removing control from dock tree"
+	Consts_SDockZoneNotFound,	" - Dock zone not found"
+	Consts_SDockZoneHasNoCtl,	" - Dock zone has no control"
+	HelpIntfs_hNoTableOfContents,	"Unable to find a Table of Contents"
+	HelpIntfs_hNothingFound,	"No help found for %s"
+	HelpIntfs_hNoContext,	"No context-sensitive help installed"
+	HelpIntfs_hNoTopics,	"No topic-based help system installed"
+	ExtCtrls_clNameBlack,	"Black"
+	ExtCtrls_clNameMaroon,	"Maroon"
+	ExtCtrls_clNameGreen,	"Green"
+	Consts_SMsgDlgYesToAll,	"Yes to &All"
+	Consts_SmkcBkSp,	"BkSp"
+	Consts_SmkcTab,	"Tab"
+	Consts_SmkcEsc,	"Esc"
+	Consts_SmkcEnter,	"Enter"
+	Consts_SmkcSpace,	"Space"
+	Consts_SmkcPgUp,	"PgUp"
+	Consts_SmkcPgDn,	"PgDn"
+	Consts_SmkcEnd,	"End"
+	Consts_SmkcHome,	"Home"
+	Consts_SmkcLeft,	"Left"
+	Consts_SmkcUp,	"Up"
+	Consts_SmkcRight,	"Right"
+	Consts_SmkcDown,	"Down"
+	Consts_SmkcIns,	"Ins"
+	Consts_SmkcDel,	"Del"
+	Consts_SVIcons,	"Icons"
+	Consts_SVBitmaps,	"Bitmaps"
+	Consts_SMsgDlgWarning,	"Warning"
+	Consts_SMsgDlgError,	"Error"
+	Consts_SMsgDlgInformation,	"Information"
+	Consts_SMsgDlgConfirm,	"Confirm"
+	Consts_SMsgDlgYes,	"&Yes"
+	Consts_SMsgDlgNo,	"&No"
+	Consts_SMsgDlgOK,	"OK"
+	Consts_SMsgDlgCancel,	"Cancel"
+	Consts_SMsgDlgHelp,	"&Help"
+	Consts_SMsgDlgAbort,	"&Abort"
+	Consts_SMsgDlgRetry,	"&Retry"
+	Consts_SMsgDlgIgnore,	"&Ignore"
+	Consts_SMsgDlgAll,	"&All"
+	Consts_SMsgDlgNoToAll,	"N&o to All"
+	Consts_SGroupIndexTooLow,	"GroupIndex cannot be less than a previous menu item's GroupIndex"
+	Consts_SNoMDIForm,	"Cannot create form. No MDI forms are currently active"
+	Consts_SControlParentSetToSelf,	"A control cannot have itself as its parent"
+	Consts_SOKButton,	"OK"
+	Consts_SCancelButton,	"Cancel"
+	Consts_SYesButton,	"&Yes"
+	Consts_SNoButton,	"&No"
+	Consts_SHelpButton,	"&Help"
+	Consts_SCloseButton,	"&Close"
+	Consts_SIgnoreButton,	"&Ignore"
+	Consts_SRetryButton,	"&Retry"
+	Consts_SAbortButton,	"Abort"
+	Consts_SAllButton,	"&All"
+	Consts_SCannotDragForm,	"Cannot drag a form"
+	Consts_SVMetafiles,	"Metafiles"
+	Consts_SVEnhMetafiles,	"Enhanced Metafiles"
+	Consts_SInvalidImageSize,	"Invalid image size"
+	Consts_SInvalidImageList,	"Invalid ImageList"
+	Consts_SImageIndexError,	"Invalid ImageList Index"
+	Consts_SImageReadFail,	"Failed to read ImageList data from stream"
+	Consts_SImageWriteFail,	"Failed to write ImageList data to stream"
+	Consts_SWindowDCError,	"Error creating window device context"
+	Consts_SWindowClass,	"Error creating window class"
+	Consts_SCannotFocus,	"Cannot focus a disabled or invisible window"
+	Consts_SParentRequired,	"Control '%s' has no parent window"
+	Consts_SMDIChildNotVisible,	"Cannot hide an MDI Child Form"
+	Consts_SVisibleChanged,	"Cannot change Visible in OnShow or OnHide"
+	Consts_SCannotShowModal,	"Cannot make a visible window modal"
+	Consts_SMenuIndexError,	"Menu index out of range"
+	Consts_SMenuReinserted,	"Menu inserted twice"
+	Consts_SMenuNotFound,	"Sub-menu is not in menu"
+	Consts_SNoTimers,	"Not enough timers available"
+	RTLConsts_SReadError,	"Stream read error"
+	RTLConsts_SReadOnlyProperty,	"Property is read-only"
+	RTLConsts_SResNotFound,	"Resource %s not found"
+	RTLConsts_SSeekNotImplemented,	"%s.Seek not implemented"
+	RTLConsts_SSortedListError,	"Operation not allowed on sorted list"
+	RTLConsts_SUnknownGroup,	"%s not in a class registration group"
+	RTLConsts_SUnknownProperty,	"Property %s does not exist"
+	RTLConsts_SWriteError,	"Stream write error"
+	Consts_SInvalidBitmap,	"Bitmap image is not valid"
+	Consts_SInvalidIcon,	"Icon image is not valid"
+	Consts_SInvalidMetafile,	"Metafile is not valid"
+	Consts_SChangeIconSize,	"Cannot change the size of an icon"
+	Consts_SOleGraphic,	"Invalid operation on TOleGraphic"
+	Consts_SUnknownClipboardFormat,	"Unsupported clipboard format"
+	Consts_SOutOfResources,	"Out of system resources"
+	Consts_SNoCanvasHandle,	"Canvas does not allow drawing"
+	RTLConsts_SClassNotFound,	"Class %s not found"
+	RTLConsts_SDuplicateClass,	"A class named %s already exists"
+	RTLConsts_SDuplicateItem,	"List does not allow duplicates ($0%x)"
+	RTLConsts_SDuplicateName,	"A component named %s already exists"
+	RTLConsts_SDuplicateString,	"String list does not allow duplicates"
+	RTLConsts_SFCreateErrorEx,	"Cannot create file \"%s\". %s"
+	RTLConsts_SFOpenErrorEx,	"Cannot open file \"%s\". %s"
+	RTLConsts_SInvalidImage,	"Invalid stream format"
+	RTLConsts_SInvalidName,	"''%s'' is not a valid component name"
+	RTLConsts_SInvalidPropertyPath,	"Invalid property path"
+	RTLConsts_SInvalidPropertyValue,	"Invalid property value"
+	RTLConsts_SListCapacityError,	"List capacity out of bounds (%d)"
+	RTLConsts_SListCountError,	"List count out of bounds (%d)"
+	RTLConsts_SListIndexError,	"List index out of bounds (%d)"
+	RTLConsts_SMemoryStreamError,	"Out of memory while expanding memory stream"
+	RTLConsts_SPropertyException,	"Error reading %s%s%s: %s"
+	SysConst_SShortDayNameWed,	"Wed"
+	SysConst_SShortDayNameThu,	"Thu"
+	SysConst_SShortDayNameFri,	"Fri"
+	SysConst_SShortDayNameSat,	"Sat"
+	SysConst_SLongDayNameSun,	"Sunday"
+	SysConst_SLongDayNameMon,	"Monday"
+	SysConst_SLongDayNameTue,	"Tuesday"
+	SysConst_SLongDayNameWed,	"Wednesday"
+	SysConst_SLongDayNameThu,	"Thursday"
+	SysConst_SLongDayNameFri,	"Friday"
+	SysConst_SLongDayNameSat,	"Saturday"
+	RTLConsts_SAncestorNotFound,	"Ancestor for '%s' not found"
+	RTLConsts_SAssignError,	"Cannot assign a %s to a %s"
+	RTLConsts_SBitsIndexError,	"Bits index out of range"
+	RTLConsts_SCantWriteResourceStreamError,	"Can't write to a read-only resource stream"
+	RTLConsts_SCheckSynchronizeError,	"CheckSynchronize called from thread $%x, which is NOT the main thread"
+	SysConst_SShortMonthNameDec,	"Dec"
+	SysConst_SLongMonthNameJan,	"January"
+	SysConst_SLongMonthNameFeb,	"February"
+	SysConst_SLongMonthNameMar,	"March"
+	SysConst_SLongMonthNameApr,	"April"
+	SysConst_SLongMonthNameMay,	"May"
+	SysConst_SLongMonthNameJun,	"June"
+	SysConst_SLongMonthNameJul,	"July"
+	SysConst_SLongMonthNameAug,	"August"
+	SysConst_SLongMonthNameSep,	"September"
+	SysConst_SLongMonthNameOct,	"October"
+	SysConst_SLongMonthNameNov,	"November"
+	SysConst_SLongMonthNameDec,	"December"
+	SysConst_SShortDayNameSun,	"Sun"
+	SysConst_SShortDayNameMon,	"Mon"
+	SysConst_SShortDayNameTue,	"Tue"
+	SysConst_SAssertError,	"%s (%s, line %d)"
+	SysConst_SAbstractError,	"Abstract Error"
+	SysConst_SModuleAccessViolation,	"Access violation at address %p in module '%s'. %s of address %p"
+	SysConst_SOSError,	"System Error.  Code: %d.\r\n%s"
+	SysConst_SUnkOSError,	"A call to an OS function failed"
+	SysConst_SShortMonthNameJan,	"Jan"
+	SysConst_SShortMonthNameFeb,	"Feb"
+	SysConst_SShortMonthNameMar,	"Mar"
+	SysConst_SShortMonthNameApr,	"Apr"
+	SysConst_SShortMonthNameMay,	"May"
+	SysConst_SShortMonthNameJun,	"Jun"
+	SysConst_SShortMonthNameJul,	"Jul"
+	SysConst_SShortMonthNameAug,	"Aug"
+	SysConst_SShortMonthNameSep,	"Sep"
+	SysConst_SShortMonthNameOct,	"Oct"
+	SysConst_SShortMonthNameNov,	"Nov"
+	SysConst_SVarArrayBounds,	"Variant or safe array index out of bounds"
+	SysConst_SVarArrayLocked,	"Variant or safe array is locked"
+	SysConst_SInvalidVarCast,	"Invalid variant type conversion"
+	SysConst_SInvalidVarOp,	"Invalid variant operation"
+	SysConst_SInvalidVarOpWithHResultWithPrefix,	"Invalid variant operation (%s%.8x)\n%s"
+	SysConst_SVarTypeCouldNotConvert,	"Could not convert variant of type (%s) into type (%s)"
+	SysConst_SVarTypeConvertOverflow,	"Overflow while converting variant of type (%s) into type (%s)"
+	SysConst_SVarOverflow,	"Variant overflow"
+	SysConst_SVarInvalid,	"Invalid argument"
+	SysConst_SVarBadType,	"Invalid variant type"
+	SysConst_SVarNotImplemented,	"Operation not supported"
+	SysConst_SVarUnexpected,	"Unexpected variant error"
+	SysConst_SExternalException,	"External exception %x"
+	SysConst_SAssertionFailed,	"Assertion failed"
+	SysConst_SIntfCastError,	"Interface not supported"
+	SysConst_SSafecallException,	"Exception in safecall method"
+	SysConst_SUnderflow,	"Floating point underflow"
+	SysConst_SInvalidPointer,	"Invalid pointer operation"
+	SysConst_SInvalidCast,	"Invalid class typecast"
+	SysConst_SAccessViolationArg3,	"Access violation at address %p. %s of address %p"
+	SysConst_SAccessViolationNoArg,	"Access violation"
+	SysConst_SStackOverflow,	"Stack overflow"
+	SysConst_SControlC,	"Control-C hit"
+	SysConst_SPrivilege,	"Privileged instruction"
+	SysConst_SException,	"Exception %s in module %s at %p.\r\n%s%s\r\n"
+	SysConst_SExceptTitle,	"Application Error"
+	SysConst_SInvalidFormat,	"Format '%s' invalid or incompatible with argument"
+	SysConst_SArgumentMissing,	"No argument for format '%s'"
+	SysConst_SDispatchError,	"Variant method calls not supported"
+	SysConst_SReadAccess,	"Read"
+	SysConst_SWriteAccess,	"Write"
+	SysConst_SVarArrayCreate,	"Error creating variant or safe array"
+	SysConst_SInvalidInteger,	"'%s' is not a valid integer value"
+	SysConst_SOutOfMemory,	"Out of memory"
+	SysConst_SInOutError,	"I/O error %d"
+	SysConst_SFileNotFound,	"File not found"
+	SysConst_SInvalidFilename,	"Invalid filename"
+	SysConst_STooManyOpenFiles,	"Too many open files"
+	SysConst_SAccessDenied,	"File access denied"
+	SysConst_SEndOfFile,	"Read beyond end of file"
+	SysConst_SDiskFull,	"Disk full"
+	SysConst_SInvalidInput,	"Invalid numeric input"
+	SysConst_SDivByZero,	"Division by zero"
+	SysConst_SRangeError,	"Range check error"
+	SysConst_SIntOverflow,	"Integer overflow"
+	SysConst_SInvalidOp,	"Invalid floating point operation"
+	SysConst_SZeroDivide,	"Floating point division by zero"
+	SysConst_SOverflow,	"Floating point overflow"
+END
+

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.res


+ 26 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/Simon.~dpr

@@ -0,0 +1,26 @@
+library Simon;
+
+{ Important note about DLL memory management: ShareMem must be the
+  first unit in your library's USES clause AND your project's (select
+  Project-View Source) USES clause if your DLL exports any procedures or
+  functions that pass strings as parameters or function results. This
+  applies to all strings passed to and from your DLL--even those that
+  are nested in records and classes. ShareMem is the interface unit to
+  the BORLNDMM.DLL shared memory manager, which must be deployed along
+  with your DLL. To avoid using BORLNDMM.DLL, pass string information
+  using PChar or ShortString parameters. }
+
+uses
+  SysUtils,
+  Classes,
+  MainSimon in 'MainSimon.pas' {frmMainSimon};
+
+{$R *.res}
+
+exports
+  LuaDebug_Initializer, SetLight, Create, Destroy, SetMediaPath,
+  GetUserSequence, GetPowerStatus, GetPlayStatus, SetScore, GetScore,
+  LockControls, UnlockControls, DisplayMessage, SetAppHandle, LuaSleep;
+
+begin
+end.

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.dcu


BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.ddp


+ 17 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.dfm

@@ -0,0 +1,17 @@
+object frmMain: TfrmMain
+  Left = 549
+  Top = 277
+  Width = 262
+  Height = 89
+  Caption = 'Simon'
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'MS Sans Serif'
+  Font.Style = []
+  OldCreateOrder = False
+  OnCreate = FormCreate
+  PixelsPerInch = 96
+  TextHeight = 13
+end

+ 91 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.pas

@@ -0,0 +1,91 @@
+unit Main;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, Lua, LuaUtils, LAuxLib, LuaLib, StdCtrls;
+
+var
+  L: Plua_State;
+
+type
+  TInitializer = function(L: PLua_State): Integer; cdecl;
+  PTInitializer = ^TInitializer;
+
+  TfrmMain = class(TForm)
+    procedure FormCreate(Sender: TObject);
+  private
+    { Private declarations }
+  public
+    { Public declarations }
+    function ExecuteInitializer(sInitializer: String; L: PLua_State): Integer;
+    procedure CallHookFunc(L: Plua_State; AR: Plua_Debug);
+  end;
+
+procedure HookCaller(L: Plua_State; AR: Plua_Debug); cdecl;
+procedure SetAppHandle(Handle: HWND); cdecl; external 'Simon.dll';
+
+var
+  frmMain: TfrmMain;
+
+implementation
+
+{$R *.dfm}
+
+function TfrmMain.ExecuteInitializer(sInitializer: String; L: PLua_State): Integer;
+var
+  Ptr: TFarProc;
+  pFunc: TInitializer;
+  iFuncReturn: Integer;
+  hModule: Cardinal;
+begin
+  try
+    hModule := LoadLibrary(PChar(sInitializer));
+    Ptr := GetProcAddress(hModule, 'LuaDebug_Initializer');
+    pFunc := TInitializer(Ptr);
+    iFuncReturn := pFunc(L);
+
+    Result := iFuncReturn;
+  except
+    Result := -1;
+    
+    if hModule <> NULL then
+      FreeLibrary(hModule);
+
+    Application.MessageBox(PChar('An error occured when attempting to call the initializer from "'+sInitializer+'".'), 'LuaEdit', MB_ICONERROR+MB_OK);
+  end;
+end;
+
+procedure TfrmMain.CallHookFunc(L: Plua_State; AR: Plua_Debug);
+begin
+  lua_getinfo(L, 'Snlu', AR);
+end;
+
+procedure HookCaller(L: Plua_State; AR: Plua_Debug); cdecl;
+begin
+  frmMain.CallHookFunc(L, AR);
+  Application.ProcessMessages;
+end;
+
+procedure TfrmMain.FormCreate(Sender: TObject);
+begin
+  // Initialize the Plua_State structure
+  L := lua_open();
+  lua_baselibopen(L);
+  luaopen_loadlib(L);
+  lua_tablibopen(L);
+  luaopen_io(L);
+  luaopen_string(L);
+  luaopen_math(L);
+  luaopen_debug(L);
+  lua_sethook(L, HookCaller, LUA_MASKCALL or LUA_MASKRET or LUA_MASKLINE, 0);
+
+  // Calling game's main entry function
+  ExecuteInitializer(ExtractFilePath(Application.ExeName)+'Simon.dll', L);
+  LuaLoadBufferFromFile(L, ExtractFilePath(Application.ExeName)+'Simon.lua', 'Main');
+  LuaPCall(L, 0, 0, 0);
+  Self.Free;
+end;
+
+end.

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.~ddp


+ 17 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.~dfm

@@ -0,0 +1,17 @@
+object frmMain: TfrmMain
+  Left = 549
+  Top = 277
+  Width = 262
+  Height = 89
+  Caption = 'Simon'
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'MS Sans Serif'
+  Font.Style = []
+  OldCreateOrder = False
+  OnCreate = FormCreate
+  PixelsPerInch = 96
+  TextHeight = 13
+end

+ 91 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/Main.~pas

@@ -0,0 +1,91 @@
+unit Main;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, Lua, LuaUtils, LAuxLib, LuaLib, StdCtrls;
+
+var
+  L: Plua_State;
+
+type
+  TInitializer = function(L: PLua_State): Integer; cdecl;
+  PTInitializer = ^TInitializer;
+
+  TfrmMain = class(TForm)
+    procedure FormCreate(Sender: TObject);
+  private
+    { Private declarations }
+  public
+    { Public declarations }
+    function ExecuteInitializer(sInitializer: String; L: PLua_State): Integer;
+    procedure CallHookFunc(L: Plua_State; AR: Plua_Debug);
+  end;
+
+procedure HookCaller(L: Plua_State; AR: Plua_Debug); cdecl;
+procedure SetAppHandle(Handle: HWND); cdecl; external 'Simon.dll';
+
+var
+  frmMain: TfrmMain;
+
+implementation
+
+{$R *.dfm}
+
+function TfrmMain.ExecuteInitializer(sInitializer: String; L: PLua_State): Integer;
+var
+  Ptr: TFarProc;
+  pFunc: TInitializer;
+  iFuncReturn: Integer;
+  hModule: Cardinal;
+begin
+  try
+    hModule := LoadLibrary(PChar(sInitializer));
+    Ptr := GetProcAddress(hModule, 'LuaDebug_Initializer');
+    pFunc := TInitializer(Ptr);
+    iFuncReturn := pFunc(L);
+
+    Result := iFuncReturn;
+  except
+    Result := -1;
+    
+    if hModule <> NULL then
+      FreeLibrary(hModule);
+
+    Application.MessageBox(PChar('An error occured when attempting to call the initializer from "'+sInitializer+'".'), 'LuaEdit', MB_ICONERROR+MB_OK);
+  end;
+end;
+
+procedure TfrmMain.CallHookFunc(L: Plua_State; AR: Plua_Debug);
+begin
+  lua_getinfo(L, 'Snlu', AR);
+end;
+
+procedure HookCaller(L: Plua_State; AR: Plua_Debug); cdecl;
+begin
+  frmMain.CallHookFunc(L, AR);
+  Application.ProcessMessages;
+end;
+
+procedure TfrmMain.FormCreate(Sender: TObject);
+begin
+  // Initialize the Plua_State structure
+  L := lua_open();
+  lua_baselibopen(L);
+  luaopen_loadlib(L);
+  lua_tablibopen(L);
+  luaopen_io(L);
+  luaopen_string(L);
+  luaopen_math(L);
+  luaopen_debug(L);
+  lua_sethook(L, HookCaller, LUA_MASKCALL or LUA_MASKRET or LUA_MASKLINE, 0);
+
+  // Calling game's main entry function
+  ExecuteInitializer(ExtractFilePath(Application.ExeName)+'Simon.dll', L);
+  LuaLoadBufferFromFile(L, ExtractFilePath(Application.ExeName)+'Simon.lua', 'Main');
+  LuaPCall(L, 0, 0, 0);
+  Self.Free;
+end;
+
+end.

+ 43 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.cfg

@@ -0,0 +1,43 @@
+-$A8
+-$B-
+-$C-
+-$D-
+-$E-
+-$F-
+-$G+
+-$H+
+-$I-
+-$J-
+-$K-
+-$L-
+-$M-
+-$N+
+-$O-
+-$P+
+-$Q-
+-$R-
+-$S-
+-$T-
+-$U-
+-$V+
+-$W-
+-$X+
+-$Y-
+-$Z1
+-cg
+-AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
+-H+
+-W+
+-M
+-$M16384,1048576
+-K$00400000
+-E"..\..\bin"
+-LE"c:\program files\borland\delphi7\Projects\Bpl"
+-LN"c:\program files\borland\delphi7\Projects\Bpl"
+-U"..\LuaCore"
+-O"..\LuaCore"
+-I"..\LuaCore"
+-R"..\LuaCore"
+-w-UNSAFE_TYPE
+-w-UNSAFE_CODE
+-w-UNSAFE_CAST

+ 16 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.dfm

@@ -0,0 +1,16 @@
+object Form1: TForm1
+  Left = 278
+  Top = 106
+  Width = 783
+  Height = 540
+  Caption = 'Form1'
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'MS Sans Serif'
+  Font.Style = []
+  OldCreateOrder = False
+  PixelsPerInch = 96
+  TextHeight = 13
+end

+ 152 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.dof

@@ -0,0 +1,152 @@
+[FileVersion]
+Version=7.0
+[Compiler]
+A=8
+B=0
+C=0
+D=0
+E=0
+F=0
+G=1
+H=1
+I=0
+J=0
+K=0
+L=0
+M=0
+N=1
+O=0
+P=1
+Q=0
+R=0
+S=0
+T=0
+U=0
+V=1
+W=0
+X=1
+Y=0
+Z=1
+ShowHints=1
+ShowWarnings=1
+UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
+NamespacePrefix=
+SymbolDeprecated=1
+SymbolLibrary=1
+SymbolPlatform=1
+UnitLibrary=1
+UnitPlatform=1
+UnitDeprecated=1
+HResultCompat=1
+HidingMember=1
+HiddenVirtual=1
+Garbage=1
+BoundsError=1
+ZeroNilCompat=1
+StringConstTruncated=1
+ForLoopVarVarPar=1
+TypedConstVarPar=1
+AsgToTypedConst=1
+CaseLabelRange=1
+ForVariable=1
+ConstructingAbstract=1
+ComparisonFalse=1
+ComparisonTrue=1
+ComparingSignedUnsigned=1
+CombiningSignedUnsigned=1
+UnsupportedConstruct=1
+FileOpen=1
+FileOpenUnitSrc=1
+BadGlobalSymbol=1
+DuplicateConstructorDestructor=1
+InvalidDirective=1
+PackageNoLink=1
+PackageThreadVar=1
+ImplicitImport=1
+HPPEMITIgnored=1
+NoRetVal=1
+UseBeforeDef=1
+ForLoopVarUndef=1
+UnitNameMismatch=1
+NoCFGFileFound=1
+MessageDirective=1
+ImplicitVariants=1
+UnicodeToLocale=1
+LocaleToUnicode=1
+ImagebaseMultiple=1
+SuspiciousTypecast=1
+PrivatePropAccessor=1
+UnsafeType=0
+UnsafeCode=0
+UnsafeCast=0
+[Linker]
+MapFile=0
+OutputObjs=0
+ConsoleApp=1
+DebugInfo=0
+RemoteSymbols=0
+MinStackSize=16384
+MaxStackSize=1048576
+ImageBase=4194304
+ExeDescription=
+[Directories]
+OutputDir=..\..\bin
+UnitOutputDir=
+PackageDLLOutputDir=
+PackageDCPOutputDir=
+SearchPath=..\LuaCore
+Packages=vcl;rtl;vclx;indy;inet;xmlrtl;vclie;inetdbbde;inetdbxpress;dbrtl;dsnap;dsnapcon;vcldb;soaprtl;VclSmp;dbexpress;dbxcds;inetdb;bdertl;vcldbx;webdsnap;websnap;adortl;ibxpress;teeui;teedb;tee;dss;visualclx;visualdbclx;vclactnband;vclshlctrls;IntrawebDB_50_70;Intraweb_50_70;Rave50CLX;Rave50VCL;dclOfficeXP;DJcl;JvStdCtrlsD7R;JvAppFrmD7R;JvCoreD7R;JvBandsD7R;JvDockingD7R;JvDotNetCtrlsD7R;JvEDID7R;qrpt;JvGlobusD7R;JvHMID7R;JvInterpreterD7R;JvJansD7R;JvManagedThreadsD7R;JvCmpD7R;JvMMD7R;JvNetD7R;JvPageCompsD7R;JvPluginD7R;JvPrintPreviewD7R;JvRuntimeDesignD7R;JvCtrlsD7R;JvSystemD7R;JvTimeFrameworkD7R;JvUIBD7R;JvValidatorsD7R;JvWizardD7R;JvXPCtrlsD7R;JvBDED7R;JvDBD7R;JvDlgsD7R;JvCryptD7R;JvCustomD7R;VirtualTreesD7;ExtLib_D6
+Conditionals=
+DebugSourceDirs=
+UsePackages=0
+[Parameters]
+RunParams=
+HostApplication=
+Launcher=
+UseLauncher=0
+DebugCWD=
+[Language]
+ActiveLang=
+ProjectLang=
+RootDir=
+[Version Info]
+IncludeVerInfo=0
+AutoIncBuild=0
+MajorVer=1
+MinorVer=0
+Release=0
+Build=0
+Debug=0
+PreRelease=0
+Special=0
+Private=0
+DLL=0
+Locale=1033
+CodePage=1252
+[Version Info Keys]
+CompanyName=
+FileDescription=
+FileVersion=1.0.0.0
+InternalName=
+LegalCopyright=
+LegalTrademarks=
+OriginalFilename=
+ProductName=
+ProductVersion=1.0.0.0
+Comments=
+[HistoryLists\hlUnitAliases]
+Count=1
+Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
+[HistoryLists\hlSearchPath]
+Count=6
+Item0=..\LuaCore
+Item1=C:\Prog\Delphi\MNet\LuaCore
+Item2=$(DELPHI)\Lib\Debug;C:\Prog\Delphi\COMPON~1\JEDI\jcl\lib\D7\debug;C:\Prog\Delphi\MNet\LuaCore
+Item3=$(DELPHI)\Lib\Debug;C:\Prog\Delphi\COMPON~1\JEDI\jcl\lib\D7\debug
+Item4=$(DELPHI)\Lib\Debug;C:\Prog\Delphi\Component\JEDI\jcl\lib\D7\debug;C:\Prog\Delphi\COMPON~1\JEDI\jcl\lib\D7\debug;C:\Prog\Delphi\MNet\LuaCore
+Item5=$(DELPHI)\Lib\Debug;C:\Prog\Delphi\Component\JEDI\jcl\lib\D7\debug;C:\Prog\Delphi\COMPON~1\JEDI\jcl\lib\D7\debug
+[HistoryLists\hlOutputDirectorry]
+Count=3
+Item0=..\..\bin
+Item1=..\Bin
+Item2=.\bin

+ 14 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.dpr

@@ -0,0 +1,14 @@
+program SimonExec;
+
+uses
+  Forms,
+  Main in 'Main.pas' {frmMain};
+
+{$R *.res}
+
+begin
+  Application.Initialize;
+  Application.Title := 'Simon';
+  Application.CreateForm(TfrmMain, frmMain);
+  Application.Run;
+end.

+ 24 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.pas

@@ -0,0 +1,24 @@
+unit SimonExec;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs;
+
+type
+  TForm1 = class(TForm)
+  private
+    { Private declarations }
+  public
+    { Public declarations }
+  end;
+
+var
+  Form1: TForm1;
+
+implementation
+
+{$R *.dfm}
+
+end.

BIN
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.res


+ 14 - 0
LuaEdit/Tutorials/BindDllToLuaEdit/src/SimonExec/SimonExec.~dpr

@@ -0,0 +1,14 @@
+program SimonExec;
+
+uses
+  Forms,
+  Main in 'Main.pas' {frmMain};
+
+{$R *.res}
+
+begin
+  Application.Initialize;
+  Application.Title := 'Simon';
+  Application.CreateForm(TfrmMain, frmMain);
+  Application.Run;
+end.