SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 17/05/2011, 06:31 AM   #1
N1trO
Little Clucker
 
Join Date: Dec 2008
Posts: 15
Reputation: 0
Question [Help] Passing an array of strings.

hello,
is there any way to pass an array of strings? (as reference)

thanks,
N1trO
N1trO is offline   Reply With Quote
Old 17/05/2011, 11:44 AM   #2
H1g0r
Big Clucker
 
Join Date: Jan 2011
Posts: 118
Reputation: 2
Default Re: [Help] Passing an array of strings.

Do not quite understand what you mean bad in this case would be;

pawn Code:
static String[24];
new  array = 5;
format(String,sizeof(String),"Array : %d",array);
__________________
Code:
Mundo infestado de gente imbecil proporção assustadora nessa porra de Brasil (8)
H1g0r is offline   Reply With Quote
Old 17/05/2011, 12:54 PM   #3
N1trO
Little Clucker
 
Join Date: Dec 2008
Posts: 15
Reputation: 0
Default Re: [Help] Passing an array of strings.

Quote:
Originally Posted by H1g0r View Post
Do not quite understand what you mean bad in this case would be;

pawn Code:
static String[24];
new  array = 5;
format(String,sizeof(String),"Array : %d",array);
I want to pass an array from my plugin to the pawn script.
The function would look somthing like that:
pawn Code:
native GetMatrix(&arr[][],&size1 = sizeof(arr),&size2 = sizeof(arr[]));
N1trO is offline   Reply With Quote
Old 17/05/2011, 01:27 PM   #4
Gamer_Z
Guest
 
Posts: n/a
Default Re: [Help] Passing an array of strings.

maybe using amx_SetString bla bla params[1][xxx] where xxx is size1. ?
  Reply With Quote
Old 17/05/2011, 03:15 PM   #5
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 2,929
Reputation: 700
Default Re: [Help] Passing an array of strings.

This page (and maybe topic) can be interesting (just scroll down):
http://forum.sa-mp.com/showthread.php?t=253436&page=4

And you can ask questions in my topic if you want, because this section is not a help section.
__________________

Sup?
RyDeR` is offline   Reply With Quote
Old 17/05/2011, 06:36 PM   #6
N1trO
Little Clucker
 
Join Date: Dec 2008
Posts: 15
Reputation: 0
Default Re: [Help] Passing an array of strings.

well tanks for the help but I now this already...
I'm developing my plugin for a while, so i know all the basics...

The thing i wish to do is to get from the plugin an array that contains all the files in a specified directory(i used boost for that part) and return it as an array of string (string x[] or new string[][]).

I know how to pass a single string from the plugin to the script (using "amx_SetString") but I don't know how to pass a whole array of them.

thanks,
N1trO
N1trO is offline   Reply With Quote
Old 18/05/2011, 04:47 PM   #7
N1trO
Little Clucker
 
Join Date: Dec 2008
Posts: 15
Reputation: 0
Default Re: [Help] Passing an array of strings.

anyone?
N1trO is offline   Reply With Quote
Old 18/05/2011, 06:02 PM   #8
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 2,929
Reputation: 700
Default Re: [Help] Passing an array of strings.

I'm sorry, no clue about that. I will try some thing though and let you know if I know something more.
__________________

Sup?
RyDeR` is offline   Reply With Quote
Old 21/05/2011, 08:26 AM   #9
0x5A656578
Guest
 
Posts: n/a
Default Re: [Help] Passing an array of strings.

I believe this is possible but as ****** mentioned the one-at-a-time method may be better for your purpose as you don't know how many files there are in the specified directory in advance.

Anyway, there's a section in their Implementer's Guide document and here's what it states about the subject at page 61:

Quote:
Multi-dimensional arrays must be handled differently, though, as the memory
lay-out differs between C/C++ and pawn. In comparison with C/C++, two-
dimensional arrays in pawn are prefixed with a single-dimensional array that
holds memory offsets to the start of each “row” in the two-dimensional array.
This extra list allows each row to have a different column length. In C/C++, each
column in a two-dimensional array must have the same size.

If you are writing a wrapper function for an existing C function, as opposed to
writing/adapting a native function specifically to exploit pawn’s features, you will
not be concerned with variable column-length arrays —C/C++ does not support
them, so your native function will not allow them. All that needs to be done,
then, is to skip the prefixed “column offsets” list after getting the address from
amx_GetAddr.

For an example, I use the OpenGL function glMultMatrixf which multiplies a
given 4 × 4 matrix with the current matrix. The prototype of the function is:

Code:
void glMultMatrixf(const GLfloat *m);
The wrapper function just has to get the address of its array parameter and add
four cells to them.

Code:
static cell n_glMultMatrixf(AMX *amx, const cell *params)
{
  cell *cptr;
  assert(sizeof(cell) == sizeof(time_t));
  amx_GetAddr(amx, params[1], &cptr);
  glMultMatrixf( (GLfloat*)(cptr + 4) );
  return 0;
}

Last edited by 0x5A656578; 21/05/2011 at 09:19 AM.
  Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems on strings of an enumerator of a 2D array leong124 Help Archive 4 17/05/2011 07:17 AM
an array with strings. legodude Help Archive 7 17/01/2011 06:12 PM
Strings into array.. deather Help Archive 4 20/07/2010 05:22 PM
Array, Strings problem Paranoja Help Archive 2 11/08/2009 08:32 PM


All times are GMT. The time now is 07:08 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.