lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On this day of 06/12/07 04:24, Luc1an0 saw fit to scribe:
> I had already use shell code in my java program... So I think it's
> possible to do like that :
> //js code
> |String x = "var out = new java.lang.StringBuffer();\nfor (i=0; i<3;
> i++)\nout.append('hello, world! ('+i+')\\n');"; |
> //call engine...
> | javax.script.ScriptEngineManager manager = new
> javax.script.ScriptEngineManager();
> //and get interpreter
> javax.script.ScriptEngine jsengine = manager.getEngineByName("js"); 
>   try {
>   jsengine.eval(x);
>   String out = new String((StringBuffer)jsengine.get("out"));
>   System.out.println(out);
> }
> catch Exception { }
> So I want use the same sample, but with an lua interpreter.

Check out the sample code on:

That seems to be what you want, right? You can also evaluate strings
directly using e.g. loadstring. If you wanted to have the same interface
as the javax.script.ScriptEngine I suppose you could write a small
wrapper around it without too much difficulty.

I wrote a config class that loads its contents from file. The
constructor is pretty simple:

	public Config(File f) throws FileNotFoundException
		configState_ = LuaStateFactory.newLuaState();
		configState_.doFile( f.getAbsolutePath() );

then when I want to get a key, I can do things like pushString followed
by getTable to get the config table's value at that key.

- David