2

I'm writing my lua code with SciTE, i wrote a C function that could be invoked by lua like this:

int hello(lua_State* L){
printf("----->> Hi! %s\n", lua_tostring(L, 1));
return 0;
}

and my lua code is like this:

zcLua.hello('Kitty')
print'hello'

('zcLua' is the libname i registered). in lua console, the output is

----->> Hi! Kitty
hello

but in SciTE the output is reversed :

hello
----->> Hi! Kitty

how can i correct that? seems it's because code print'hello' is executed faster than invoking the c function

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • How does `printf` work? That's not a standard Lua function. – Nicol Bolas Oct 24 '12 at 04:19
  • no it's not a lua function. it's c/c++ code. i'm testing to bind lua to c – zhangxaochen Oct 24 '12 at 04:50
  • 1
    As I don't know SciTE, I can't tell it for sure. But I think the `print` function is refined in the editor, which places the output data in a _buffer_ that is only displayed at the end of script, or in a separate thread. – prapin Oct 24 '12 at 06:04
  • prapin explanation make sense. odd behaviour though. i would'n care too much about the "late" output from your C-binding. it seems to work and i guess you have all set up properly. The execution order will be preserved. you could print a value passed in through the stack (lua_State) to prove this. – lipp Oct 24 '12 at 07:16

1 Answers1

0

As I don't know SciTE, I can't tell it for sure. But I think the print function is refined in the editor, which places the output data in a buffer that is only displayed at the end of script, or in a separate thread.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265