Jump to content


Parsing %{command.data} in Lua

  • Please log in to reply
4 replies to this topic

#1 Trinovi



  • Members
  • Pip
  • 6 posts

Posted 01 October 2011 - 08:26 PM


This is probably a question answered elsewhere here, but I can't seem to find exactly what I'm looking for, which is either:

1.) A simple way to take space-separated command data strings and assign them to variables in a Lua script

or, barring that,

2.) An easy way to store my own %{command.data} parsing function in global space, so that any of my Lua scripts may call it, as opposed to my having to define such a function within each script.

Had Lua a split() or explode() or similar string manipulation function, I would just pass %{command.data} to that, but sadly it does not.

Either of these solutions would be great for me. (I would like to know how to do both, if both possibilities exist!)

If it isn't clear what I'm after, here's an example.

If entered into the command window, the command 'gbag food 3' would send to the world, 'get all food from bag 3'.


gbag(item, bagNumber) {
Atlantis:sendText(world, 'get ' .. item .. ' from bag ' .. bagNumber);

How do I turn %{command.data}, 'bag 3' into item='bag', bagNumber=3 ?

Thanks for any help anyone can provide.


#2 wombat


    Advanced Member

  • Members
  • PipPipPip
  • 321 posts

Posted 02 October 2011 - 03:59 PM

I don't use Lua, but I would assume you can put your own .lua library file in ~/Library/Atlantis/Scripts/ and call functions the same way you do the Atlantis functions.

#3 Trinovi



  • Members
  • Pip
  • 6 posts

Posted 05 October 2011 - 09:31 PM

Thanks, Wombat. I assume something like that is possible, too, but it doesn't appear that *.lua gets loaded when the application is run, otherwise I would expect functions like MyFunctions:foo(), defined in ~/Library/Atlantis/Scripts/MyFunctions.lua as...

function MyFunction:foo()
Atlantis:sendText(AtlantisState['world.name'], 'say foo');

...to be callable in my aliases in the same way as Atlantis:<functions> are callable. Unfortunately, this isn't the case. Here is the error string:

%% Error: [string "?"]:1: attempt to call method 'foo' (a nil value)

My alias is simply:


Any tips on how to load up my own libraries either in runtime or when launching the application? I'll dig around the other threads for an answer, but if anyone can help out, I'd be grateful.


#4 Trinovi



  • Members
  • Pip
  • 6 posts

Posted 05 October 2011 - 09:55 PM

Moving my lib into a directory under the lua path, and then requiring it in my alias, works, but it seems like an inelegant way to do this.

#5 fuzzyweapon



  • Members
  • PipPip
  • 10 posts
  • Gender:Female

Posted 20 January 2016 - 02:48 AM

I found out a solution that does not require you to move our lib.  Instead, add to your LUAPATH at runtime.*


Your .../Scripts folder should have a file in it.  I made mine functions.lua for the sake of this example:


functions = {}


function functions:test()
    return Atlantis:sendText()
And then in your events lua trigger, something like:
package.path = package.path .. ';/Users/redacted/Library/Atlantis/Scripts/?.lua;/Users/redacted/My Apps/clients/Atlantis.app/Contents/Scripts/?.lua'
require "Atlantis"
require "functions"
*The current code snippets are not fully working and omit the arguments to sendText and currently crash Atlantis, however, I can confirm that it does solve this problem.  On my approach to getting my code to this point, the lua interpreter could not see my file.  Then it could but couldn't resolve the Atlantis namespace call.  Then I added the location of that to the path.  Then this happened.
If I'm able to get a fully working simple example, I will post it up in a new thread for others.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users