Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6607003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:27:22+00:00 2026-05-25T19:27:22+00:00

I intend to use LuaJava to run scripts in my Java/Android applications. When I

  • 0

I intend to use LuaJava to run scripts in my Java/Android applications.

  • When I run Lua script, is it executed in some another thread?
  • How do I manage execution of Lua code, how do I know that script finished execution?
    If I want my Java program to wait for Lua code to finish, what do I do then?

My first guess was to use some semaphores and invoke Java callbacks from Lua. How do I do it in a right way?

UPD WITH CODE

Java:

    LoadScript(final String filename) {
        this.luaState = LuaStateFactory.newLuaState();
        this.luaState.openLibs();
        this.luaState.LdoFile(filename);//launch Lua script to print lines
        printLines();// print Java lines
    }

    void printLines(){
        for(int i=0;i<100;i++)
            System.out.println("From java: "+i);
    }

Lua:

for i=0,100
  do
    print("From lua: ",i)
end

In console I see that Java printed its strings first, and then Lua did.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:27:23+00:00Added an answer on May 25, 2026 at 7:27 pm

    When I run Lua script, is it executed in some another thread?

    No.

    You will know that the script has “finished” execution when the next Java statement after the one that calls into the script is executed.


    That happens because they’re using different streams to write to std-out. They have different flushing behavior, so one will happen before the other. But the actual execution of the code is not threaded.

    If you want to test this, just have the Lua script return something and then have your Java code get the top thing from the stack. It will always be what the Lua script generated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I intend to use TripleDES in one of my project. I was doing some
i intend to use IceFaces with spring framework and i have some questions, before
What are the possibilities in Android, when I intend to use serialization/deserialization with data?
I'm writing a JavaScript that generates some data. I intend to use it as
I intend to use RADIX / MTRIE as my preferred data-structure for a routing
I have declared a DataTemplate in Window.Resources; I don't intend to use it inside
I intend to develop a small (Java) application for managing my finances. I believe
I intend to use Reinforcement learning in my project but I do not know
So..I intend to use a Model View Presenter(the passive mode, in which the UI
I intend to develop an application using .Net 4.0, and intend to use EF4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.