Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Thu Jul 24, 2014 7:19 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri May 09, 2014 1:27 pm 
Prolific Poster

Joined: Sat Apr 14, 2012 5:12 pm
Posts: 20
So I followed an advice from http://forum.gpwiki.org/viewtopic.php?f=26&t=12321 and managed to implement the LuaJava to my project with this https://code.google.com/p/libgdx-users/wiki/LuaTutorial?ts=1316712533&updated=LuaTutorial guide. Now I need some tips how to use it:

1. In guide, there is a class LoadScript which wrapps the LuaState. Should I create new object of that class or LuaState class for every script file I want to run?
2. How do I handle errors? I mean what to do to avoid app crashes if lua script is messed up or contains syntax errors etc.

(I'll reply/update with new questions if they come to my mind)


Top
 Profile  
 
PostPosted: Mon Jun 09, 2014 6:35 pm 
Gamer Geek

Joined: Thu May 01, 2014 8:18 pm
Posts: 31
I have not used LuaJava, but am in the process of adapting Lua in my c++ code. Here's what I can tell*:
tariel36 wrote:
1. In guide, there is a class LoadScript which wrapps the LuaState. Should I create new object of that class or LuaState class for every script file I want to run?
No, there is no such need. One LuaState should be able (not to say must, but kind of, yeah) to handle multiple files; just think of every time you do lua_dofile (or whatever it's called in java) as adding new global variables (so functions aswell) to your "Lua universe" (that is, your luaState), and executing whatever direct commands are in the file you're running.
However:
Rather than having multiple LuaStates for multiple files, it might be good to have several LuaStates that use the same file. It all of course depends on the implementation, but in my project for example (mind the disclaimer), every mob has its own LuaState, in which it loads and executes the behavior scripts appropriate for that mob.

TL;DR: nothing forces you to create several LuaStates to run several Lua files, however, there may be other reasons for doing so.

As for your second question:
tariel36 wrote:
2. How do I handle errors? I mean what to do to avoid app crashes if lua script is messed up or contains syntax errors etc.
Well, you should always write your code so that it is ready for errors. I do not know the exact procedure or names in java, but if you for example use lua_getglobal to get at global variable on the stack, you should check that it is the type you expected, and not, for example, nil. In c++, the funcitons for that are called "lua_isstring", "lua_isfunction", etc. All functions that theoretically can go wrong, should have a mechanism for telling you they did. However, this is implementation-specific so you'll have to consult your documentation.

TL;DR: You check the values you get before using them. And other things.

*DISCLAIMER: Everything I'm saying, I'm saying from a c++ background. I have used general lua concepts to try to answer your questions, but it is fully possible (if improbable) that things are different over there in Ol'JavaLand. So if someone answers having any real experience with LuaJava, and his answers are in conflict with mine, he's probably right.

Good luck with what you're doing, and tell me if the answers were satisfying!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

Powered by phpBB® Forum Software © phpBB Group