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

  • SEARCH
  • Home
  • 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 4343776
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:48:06+00:00 2026-05-21T11:48:06+00:00

I just got homework to create a lua menu which is as small as

  • 0

I just got homework to create a lua menu which is as small as possible, and as user friendly as possible.

Currently it’s 32 lines long and it’s being used like this:

menu_name = "Mahi's Lua Menu Template v1"
menu_items = {
    "Move menu to left",
    "Move menu to right",
    "Reset menu position",
    "Exit menu"
}
function use(item)
    if item==1 then menupos=menupos-1
    elseif item==2 then menupos=menupos+1
    elseif item==3 then menupos=3
    elseif item==4 then quit=true end
end

I’d like to make it so function use() would be replaced with

menu_actions = {
    "menupos=menupos-1",
    "menupos=menupos+1",
    "menupos=3",
    "quit=true"
}

But now there’s the problem, that I can’t use any of those actions when they’re strings. Is there any way to just “remove” the quotation marks?

I already did customize the use function to this:

function use()
    for i=1,#menu_actions do
        if i==selection then
            toaction(menu_actions[i])
        end
    end
end

Of course there’s no such command as “toaction”, but this is what I’m looking for, is it possible to make that, or do I just have to stick with my current use function?

Edit: I just realized that it could be done by writing the text’s from menu_actions table into a .lua file and then remove quotation marks, and then just run the lua file and remove it after menu is being shut down… But that’s slow, any better ideas?

Edit2: SOLVED

function toaction(s)   
  if _G[s]==nil then _G[s]=loadstring(s) end 
  _G[s]() 
end

Thanks, that works! 😀
But then again, I could just replace the whole toaction() with loadstring()…

function use()
    for i=1,#menu_actions do
        if i==selection then
            loadstring(menu_actions[i])()
        end
    end
end

But thanks, didn’t know there was function called loadstring >.<

  • 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-21T11:48:07+00:00Added an answer on May 21, 2026 at 11:48 am

    Try this:

    function toaction(s)
      if _G[s]==nil then _G[s]=loadstring(s) end
      _G[s]()
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this exercise, is not a homework , I just trying to solve:
Just got a request from my boss for an application I'm working on. Basically
Just got a question about generics, why doesn't this compile when using a generic
I just got Delphi 2009 and have previously read some articles about modifications that
I just got a dedicated server from a hosting company, and for some reason,
I just got through manually removing the bin\ and obj\ folders from around 30
I just got a shiny, brand-new Debian server handed to me by our Systems
I just got my azure invitation code...yay! Are there any official samples for windows
I just got done working through the Django tutorials for the second time, and
I just got this error message: ... from c:/ruby/lib/ruby/gems/1.8/gems/... ... 10 levels... from c:/ruby/lib/ruby/gems/1.8/gems/...

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.