This is a really well documented and implemented project. Lua has a lot of potential as a platform for internal DSLs. In my opinion, this potential is not tapped often enough.
I have two ideas for this project. I'm not convinced that they are things that you should implement; however, I'm posting them because I think they are interesting.
Idea 1:
An alternative way to implement something like this would be to use coroutines. Instead of representing a scene as a sequence of expressions, you would represent it using a function. As with the current implementation, you would still be able to associate extra data, such as background images, with the scene by adding values into a table.
Example 4 might look something like this:
Code: Select all
local END = LNVL.Scene()
function END.script()
Jeff “I hate you. I hate you so much.”
...
end
local NOT_GUILTY = NOT_GUILTY.Scene()
function NOT_GUILTY.script()
Eric “Not Guilty, your honor!”
...
end
local THE_TRUTH = LNVL.Scene()
function THE_TRUTH.script()
Eric “Ok, so we infringed on copyrighted material...”
…
LNVL:jumpTo( END() )
end
local START = LNVL.Scene()
START.background = “img/courtroom.png”
function START.script()
Jeff “Isn't this a copyright infringement again?”
Eric “Would you just shut up...”
Judge “I have reviewed the evidence. How do you plead?”
if LNVL.Menu(“Not Guilty”, “Obviously Guilty”) == “Not Guilty” then
LNVL:jumpTo( NOT_GUILTY() )
else
LNVL:jumpTo( THE_TRUTH() )
end
end
With this approach, I think it would be sensible to give the programmer two options for
scene transititions. One would be to call a function which sets up the scene and then executes its events.
Using this, you could organize your novel hierarchically as follows.
Code: Select all
function Start.script()
Beginning()
Middle()
End()
end
The other option would be to set up a transition which occurs in a non-hierarchical manner after the current scene has finished executing.
Code: Select all
local Start = LNVL.NewScene()
Start.nextScene = “Beginning”
function Start.script ()
...
end
There would be pros and cons to this approach.
Pros:
-Debugger Friendly
-Scenes can be composed in a hierarchical fashion. (Actually this is an iffy pro—a screenwriter would never do this, so why would someone writing a visual novel?)
-Programmer can take advantage of constructs such as local variable definitions, if statements, and parameterized function calls
Cons:
-Less ability to reflect on the runtime data that represents scenes
-Function definitions are ugly in lua
-Probably a lot of other things that I didn't think of
Idea 2:
Another idea that I have is an alternative notation for monologues. If one chose to use the coroutine approach, it would be debugger friendly. If not, the notation *might* be slightly preferable, but I think the current notation works fine.
The new notation would look like this:
Code: Select all
SomeDude
“Hello reader.”
“I am SomeDude.”
SomeDude's call metamethod would take one string argument. However, the call metamethod would return SomeDude, allowing the programmer to supply additional lines for a monologue.
Finally, responding to your original question, I imagine that you have already read the paper
Building Domain-Specific Languages over a Language Framework by the lua creators.
BTW. I can't run most of the examples because the image resources that they depend on do not seem to have been included.
Keep up the good work.