Jump to content

Recommended Posts

My experience has generally been with JavaScript, PHP, Perl and VB, and the last time I worked with Lua was when I wrote a mod for WoW many many years ago. It's entirely possible I'm missing something obvious.

 

Anyway, while trying to simultaneously figure out Lua and the DS API, I wrote a simple print_r function to use in the console while rooting around. The problem is, whenever I tried calling it, I got bad argument errors.  So I made the simplest function I could muster in global space to test:

 function GLOBAL:test(a_table, a_string, a_misc)      print("a_table: " .. type(a_table))      print(a_table)      print("a_string: " .. type(a_string))      print(a_string)      print("a_misc: " .. type(a_misc))      print(a_misc)  end
Hard to get more simple than that, right?

I tried entering this into the console:

 test_table = GetPlayer()  test_string = "Some string."  test_misc = {}  test(test_table, test_string, test_misc)
Here's what pops out every time:

 a_table: string  Some string.  a_string: table  table: 2E93C090  a_misc: nil
Obviously this isn't what I'm expecting.  The 1st and 2nd argument appear to be swapped, and the third argument is nil when it should be a table. If I do print(a_table/string/misc) or print(type(a_table/string/misc)) from the console I get exactly what I expect, though.

 

What gives? Have I been playing too much DS?  Am I starting to lose my mind as well?

[edit: formatting]

Edited by Corrosive
  • Developer

Try rewriting your function as:

 

function GLOBAL.test(a_table, a_string, a_misc)

 

The colon that you are currently using gobbles the first parameter as 'self', which is something you usually do when using OO in lua.

 

This stackoverflow post explains it better:

http://stackoverflow.com/questions/4911186/difference-between-and-in-lua

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...