|
| LuaBSF: A LuaJava extension |
LuaBSF is an extension of BSF that implements an engine that allows BSF to call Lua. In order to do that, LuaBSF uses LuaJava to implement the comunication between Lua and Java.
Bean Scripting Framework (BSF) is a set of Java classes which provides scripting language support within Java applications, and access to Java objects and methods from scripting languages. BSF allows one to write JSPs in languages other than Java while providing access to the Java class library. In addition, BSF permits any Java application to be implemented in part (or dynamically extended) by a language that is embedded within it. This is achieved by providing an API that permits calling scripting language engines from within Java, as well as an object registry that exposes Java objects to these scripting language engines.
There are two ways to use LuaBSF.
BSFManager.registerScriptingEngine() method:registerScriptingEngine("lua", "org.keplerproject.luajava.luabsf.LuaEngine", new String[]{"lua"})
LuaBSF can be downloaded from here.
BSF offers a taglib to be used to develop Java Server Pages(jsp) using a script language. Here is an example of a jsp page using Lua:
example.jsp
<%@ taglib uri="/WEB-INF/bsf.tld" prefix="bsf" %>
<html>
<body>
<bsf:scriptlet language="lua">
for i=1,5 do
out:println("This is a scriptlet test in Lua.."..i.."<br>")
end
</bsf:scriptlet>
<bsf:expression language="lua">
"Now it's an expression"
</bsf:expression>
</body>
</html>
The output for this page should be:
This is a scriptlet test in Lua..1
This is a scriptlet test in Lua..2
This is a scriptlet test in Lua..3
This is a scriptlet test in Lua..4
This is a scriptlet test in Lua..5
Now it's an expression