Jump to content

Function argument insanity. Losing my mind?


Corrosive

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]

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...