[Help] Passing an array of strings.
#1

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

thanks,
N1trO
Reply
#2

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

pawn Код:
static String[24];
new  array = 5;
format(String,sizeof(String),"Array : %d",array);
Reply
#3

Quote:
Originally Posted by H1g0r
Посмотреть сообщение
Do not quite understand what you mean bad in this case would be;

pawn Код:
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 Код:
native GetMatrix(&arr[][],&size1 = sizeof(arr),&size2 = sizeof(arr[]));
Reply
#4

maybe using amx_SetString bla bla params[1][xxx] where xxx is size1. ?
Reply
#5

This page (and maybe topic) can be interesting (just scroll down):
https://sampforum.blast.hk/showthread.php?tid=253436&page=4

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

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
Reply
#7

anyone?
Reply
#8

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

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:

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

Код:
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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)